HomeAutomation

Selenium Java Interview Questions And Answers – Part 14

Selenium Java Interview Questions And Answers – Part 14

Selenium Java Interview Questions and Answers Part-14

1) What are the different ways to customize TestNG report?

We can customize TestNG reports in 2 ways:
– Using ITestListener Interface
– Using IReporter Interface

2) What is required to generated the PDF reports?

To create pdf report we need a Java API called IText.

3) What are Selenium WebDriver Listeners?

The WebDriverEventListener interface can implement classes and methods like EventFiringWebDriver and WebDriverEventListener. It can also track events like “beforeNavigateTo” , “afterNavigateTo”, “BeforeClickOn”, “AfterClickOn” and more.

4) What are the different types of Listeners in TestNG?

Below are different types of listeners in TestNG:
– IAnnotationTransformer
– IConfigurable
– IConfigurationListener
– IExecutionListener
– IHookable
– IInvokedMethodListener
– IMethodInterceptor
– IReporter
– ISuiteListener
– ITestListener

5) What is the API that is required for implementing Database Testing using Selenium WebDriver?

JDBC api is required for Database testing.

6) When to use AutoIt?

AutoIt is a freeware BASIC-like scripting language designed for automating the Windows GUI and general purpose scripting. It should be used to automate window based popups and dialog boxes.

7) Why do we need Session Handling while using Selenium WebDriver?

During test execution, the Selenium WebDriver has to interact with the browser all the time to execute given commands. At the time of execution, it is also possible that, before current execution completes, someone else starts execution of another script, in the same machine and in the same type of browser. In such situation, we need a mechanism by which our two different executions should not overlap with each other.

8) What is the advantage of using GitHub for Selenium?

Github can be used for the following:
– Effective Source Code Management
– Collaboration among team members
– Versioning of Selenium code

9) What are the advantages and disadvantages of Selenium over other testing tools like QTP and TestComplete?
Advantages:
– Selenium is open source and free automation tool
– Selenium supports multiple languages and platforms
– Selenium can be easily integrated with CI/CD tools

Disadvantages:
– Selenium can only automate Web Applications
– Selenium doesn’t have reporting capabilities
– Selenium doesn’t have a object repository

10) What is exception test in Selenium?

In TestNG we use expectedException with @Test annotation and we need to specify the type of exceptions that are expected to be thrown when executing the test methods.

11) Why and how will you use an Excel sheet in your Selenium project?

Excel sheet can be used as a data source from which we can read test data. We can also use it for reporting.

12) How can you redirect browsing from a browser through some proxy?

Selenium provides a PROXY class to redirect browsing from a proxy.

String PROXY = "199.200.124.130:8080";

org.openqa.selenium.Proxy proxy = new.org.openqa.selenium.Proxy();
proxy.setHTTPProxy(Proxy)
.setFtpProxy(Proxy)
.setSslProxy(Proxy)

DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(cap);

 

13) How do you achieve synchronization in WebDriver?

Synchronization can be achieved by using the following wait commands in WebDriver:
– ImplicitWait
– ExplicitWait
– FluentWait

14) Write a code to wait for a particular element to be visible on a page.

WebElement element = driver.findElement(By.id("button"));
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(element));

 

15) Write a code to wait for an alert to appear.

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.alertIsPresent());

 

16) How to scroll down a page using JavaScript in Selenium?

JavaScriptExecutor js = (JavaScriptExecutor)driver;
js.executeScript("window.scrollBy(0,1000)");

 

17) How to scroll down to a particular element?

JavaScriptExecutor js = (JavaScriptExecutor)driver;
js.executeScript("arguments[0].scrollIntoView();", Element);

 

18) How to handle keyboard and mouse actions using Selenium?

Keboard and mouse actions can be handled by using Actions class in Selenium.

19) Which files can be used as data source for different frameworks?

Text, Excel, XML and JSON can be used as data source files.

20) How can you fetch an attribute from an element?

We can fetch an attribute using getAttribute() method in Selenium.

21) How to retrieve typed text from a text box?

String text = driver.findElement(By.id("textBox")).getText();

 

22) How to send alt or shift or control or enter or tab key in Selenium WebDriver?

We can use sendKeys() method to send any key.

driver.findElement(element).sendKeys(Keys.TAB);

 

23) How to set the size of browser window using Selenium?

Dimension d = new Dimension(300,1080);
driver.manage().window().setSize(d);

 

24) How to switch to a new window (new tab) which opens up after you click on a link?

String currentWindowHandle = driver.getWindowHandle();
ArrayList<String> windowHandles = new ArrayList<String>(driver.getWindowHandles());
for (String window:windowHandles){
if (window != currentWindowHandle){
driver.switchTo().window(window);
}
}

 

25) Can I call a single data provider method for multiple functions and classes?

Yes. We can use a single data provider method for multiple functions.

Next Steps:

> More interview questions and answers on Selenium Java, continue to the next post (Click on Next Post link below)

> Check complete Selenium Java interview questions and answers here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Bijan Patel

Connect to me on Linked In (Click here)

On a mission to contribute to the Software Testing Community in all possible ways.

 

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

For FREE Testing Tutorials & Videos

X
Open chat
Contact Us on Whatsapp