Top Selenium Testing Interview Questions and Answers

Last updated on Jan 18 2024
Shankar Shankar Trivedi

1. What is Selenium?

Answer: Selenium is an open-source automation testing framework used for automating web applications. It provides a playback tool for authoring functional tests without needing to learn a test scripting language.

2. Explain the different components of Selenium.

Answer: Selenium consists of Selenium IDE (Integrated Development Environment), Selenium WebDriver, Selenium Grid, and Selenium Standalone Server.

3. How do you launch a browser using Selenium WebDriver?

Answer: You can launch a browser using the following code in Java:

WebDriver driver = new ChromeDriver();

4. What is the difference between ‘findElement’ and ‘findElements’ in Selenium WebDriver?

Answer: findElement returns the first matching element on the web page, while findElements returns a list of all matching elements.

WebElement element = driver.findElement(By.id("exampleId"));

5. Explain the importance of XPath in Selenium.

Answer: XPath is crucial in Selenium for locating web elements on a webpage. It provides a powerful way to traverse the HTML structure.

WebElement element = driver.findElement(By.xpath("//input[@id='username']"));

6. How can you handle dynamic elements in Selenium?

Answer: Dynamic elements can be handled using Explicit Waits, where you wait for the element to be present or clickable before interacting with it.

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("dynamicElement")));

7. What is the Page Object Model (POM) in Selenium?

Answer: The Page Object Model is a design pattern that encourages using a separate class for each web page. It enhances code maintainability and readability.

LoginPage loginPage = new LoginPage(driver);
loginPage.login("username", "password");

8. How can you handle multiple windows in Selenium WebDriver?

Answer: Multiple windows can be handled using getWindowHandles() and switchTo().window(handle) methods.

Set<String> handles = driver.getWindowHandles();
for (String handle : handles) {
driver.switchTo().window(handle);
// Perform actions on each window
}

9. Explain the concept of Implicit Wait in Selenium.

Answer: Implicit Wait is used to make WebDriver wait for a certain amount of time before throwing a “No Such Element” exception.

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

10. How do you perform drag and drop in Selenium WebDriver?
Answer: Drag and drop actions can be performed using the Actions class.

WebElement sourceElement = driver.findElement(By.id("source")); WebElement targetElement = driver.findElement(By.id("target")); Actions actions = new Actions(driver); actions.dragAndDrop(sourceElement, targetElement).build().perform();

11. Explain the concept of Cross-Browser Testing in Selenium.
Answer: Cross-Browser Testing is testing web applications across different browsers. Selenium supports cross-browser testing by providing WebDriver for various browsers.

WebDriver driver = new FirefoxDriver(); // Test on Firefox

12. What is TestNG, and how is it useful in Selenium?
Answer: TestNG is a testing framework for Java. It provides annotations for test configuration, parallel test execution, and facilitates data-driven testing.

@Test public void testLogin() { // Test logic here }

13. How can you handle dropdowns in Selenium?
Answer: Dropdowns can be handled using the Select class in Selenium.

WebElement dropdown = driver.findElement(By.id("dropdown")); Select select = new Select(dropdown); select.selectByVisibleText("Option 1");

14. What is the purpose of the Selenium Grid?
Answer: Selenium Grid is used for parallel test execution across multiple machines and browsers, allowing efficient and faster testing.

// Set up a Selenium Grid hub and nodes for parallel execution

15. How do you capture screenshots in Selenium?
Answer: Screenshots can be captured using the TakesScreenshot interface.

File screenshotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshotFile, new File("screenshot.png"));

16. How do you handle frames in Selenium?
Answer: Frames can be handled using the switchTo().frame() method.

WebElement frameElement = driver.findElement(By.id("frame")); driver.switchTo().frame(frameElement); // Perform actions inside the frame

17. What is the difference between close() and quit() methods in Selenium WebDriver?
Answer: close() method closes the current browser window, while quit() method quits the entire browser session, closing all windows.

driver.close(); // Closes the current window driver.quit(); // Quits the entire browser session

18. How can you simulate keyboard key presses in Selenium WebDriver?
Answer: Keyboard key presses can be simulated using the sendKeys method of the Actions class.

Actions actions = new Actions(driver); actions.sendKeys(Keys.ENTER).build().perform();

19. Explain the use of the @FindBy annotation in Selenium.
Answer: @FindBy is used in Page Object Model to locate WebElements using annotations.

@FindBy(id = "username") private WebElement usernameInput;

20. How do you handle alerts in Selenium?
Answer: Alerts can be handled using the Alert interface in Selenium.

Alert alert = driver.switchTo().alert(); alert.accept(); // To accept the alert

21. What is the purpose of the getAttribute method in Selenium?
Answer: getAttribute is used to retrieve the value of a specified attribute of an element.

WebElement element = driver.findElement(By.id("exampleId")); String value = element.getAttribute("attributeName");
22. How do you perform scrolling in Selenium WebDriver?
Answer: Scrolling can be done using JavaScriptExecutor or Actions class.

// Using JavaScriptExecutor
((JavascriptExecutor)driver).executeScript("window.scrollBy(0, 500)");

// Using Actions class
Actions actions = new Actions(driver);
actions.sendKeys(Keys.PAGE_DOWN).build().perform();

23. What is the purpose of the isEnabled method in Selenium?
Answer: isEnabled is used to check if an element is enabled or not.

WebElement button = driver.findElement(By.id("submitBtn")); boolean isEnabled = button.isEnabled();

24. How can you perform parallel testing in Selenium using TestNG?
Answer: Parallel testing in TestNG can be achieved by setting the parallel attribute in the test or suite element in the XML file.

xml <suite name="ParallelSuite" parallel="tests"> <test name="TestA"> <!-- Test configuration --> </test> <test name="TestB"> <!-- Test configuration --> </test> </suite>

25. Explain the concept of Data-Driven Testing in Selenium.
Answer: Data-Driven Testing involves running the same test with multiple sets of data. TestNG’s @DataProvider annotation is commonly used for data-driven testing.

@Test(dataProvider = "loginData") public void testLogin(String username, String password) { // Test logic here }

26. What is the use of the isDisplayed method in Selenium?
Answer: isDisplayed is used to check if an element is currently visible on the page.

WebElement element = driver.findElement(By.id("exampleId")); boolean isDisplayed = element.isDisplayed();

27. How do you handle cookies in Selenium WebDriver?
Answer: Cookies can be handled using the addCookie, getCookieNamed, and deleteCookieNamed methods.

// Adding a cookie
Cookie newCookie = new Cookie("cookieName", "cookieValue");
driver.manage().addCookie(newCookie);

go

// Deleting a cookie
driver.manage().deleteCookieNamed("cookieName");

28. Explain the concept of Headless Browser Testing in Selenium.
Answer: Headless Browser Testing is executing browser tests without the graphical user interface. It can be achieved using browsers like Chrome or Firefox in headless mode.

ChromeOptions options = new ChromeOptions(); options.setHeadless(true); WebDriver driver = new ChromeDriver(options);

29. How can you perform synchronization in Selenium WebDriver?
Answer: Synchronization can be achieved using Implicit Waits, Explicit Waits, or Fluent Waits.

// Implicit Wait
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

// Explicit Wait
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“exampleId”)));

30. What are the advantages of using Selenium for automated testing?
Answer: Advantages include cross-browser compatibility testing, support for multiple programming languages, and the ability to integrate with various tools. Selenium also provides a large community and extensive documentation.

These questions cover a broad range of Selenium testing concepts and practices. Understanding them will help you excel in a Selenium testing interview.

What is the difference between Selenium 2.0 and Selenium 3.0? 

Selenium 2.0 is a tool that makes the development of automated tests for web applications easier. It represents the merger of the original Selenium project with the WebDriver project. Selenium RC got deprecated since the merge, however, was used for backward compatibility

Selenium 3.0 is the extended version of Selenium 2.0. It is inherently backward compatible and does not involve Selenium RC. The new version came along with several bug fixes and increased stability.

What are the Selenium suite components?

Selenium IDE

It is a Firefox/Chrome plug-in that was developed to speed up the creation of automation scripts. It records the user actions on the web browser and exports them as a reusable script.

Selenium Remote Control (RC)

RC is a server that allows users to write application tests in various programming languages. The commands from the test script are accepted by this server and are sent to the browser as Selenium core JavaScript commands. The browser then behaves accordingly.

Selenium WebDriver

WebDriver is a programming interface that helps create and run test cases. It makes provision to act on web elements. Unlike RC, WebDriver does not require an additional server and interacts natively with the browser applications.

Selenium Grid

The grid was designed to distribute commands to different machines simultaneously. It allows the parallel execution of tests on different browsers and different operating systems. It is exceptionally flexible and is integrated with other suite components for simultaneous execution.

What are the limitations of Selenium testing? 

  1. Unavailability of reliable tech support: Since Selenium is an open-source tool, it does not have dedicated tech support to resolve the user queries.
  2. Tests web applications only: Selenium needs to be integrated with third-party tools like Appium and TestNG to test desktop and mobile applications.
  3. Limited support for image testing.
  4. No built-in reporting and test management facility: Selenium has to be integrated with tools like TestNG, or JUnit among others to facilitate test reporting and management.
  5. May require the knowledge of programming languages: Selenium WebDriver expects the user to have some basic knowledge about programming.

What are the testing types supported by Selenium? 

Selenium supports Regression testing and Functional testing. 

Regression testing – It is a full or partial selection of already executed test cases that are re-executed to ensure existing functionalities work fine.

The steps involved are –

  1. Re-testing: All tests in the existing test suite are executed. It proves to be very expensive and time-consuming.
  2. Regression test selection: Tests are classified as feature tests, integration tests,  and the end to end tests. In this step, some of the tests are selected.
  3. Prioritization of test cases: The selected test cases are prioritized based on business impact and critical functionalities.

Functional testing – Functional Testing involves the verification of every function of the application with the required specification.

The following are the steps involved:

  1. Identify test input
  2. Compute test outcome
  3. Execute test
  4. Compare the test outcome with the actual outcome

What is the same-origin policy and how is it handled?

Same Origin policy is a feature adopted for security purposes. According to this policy, a web browser allows scripts from one webpage to access the contents of another webpage provided both the pages have the same origin. The origin refers to a combination of the URL scheme, hostname, and port number.

The same Origin Policy prevents a malicious script on one page to access sensitive data on another webpage.

Consider a JavaScript program used by google.com. This test application can access all Google domain pages like google.com/login, google.com/mail, etc. However, it cannot access pages from other domains like yahoo.com

Selenium RC was introduced to address this. The server acts as a client configured HTTP proxy and “tricks” the browser into believing that Selenium Core and the web application being tested come from the same origin.

What is Selenese? How is it classified?

Selenese is the set of Selenium commands which are used to test your web application. The tester can test the broken links, the existence of some object on the UI, Ajax functionality, alerts, window, list options, and a lot more using Selenese.

Action: Commands which interact directly with the application

Accessors: Allow the user to store certain values to a user-defined variable

Assertions: Verifies the current state of the application with an expected state

What are the types of waits supported by WebDriver?

Implicit wait – Implicit wait commands Selenium to wait for a certain amount of time before throwing a “No such element” exception.

driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);

Explicit wait – Explicit wait is used to tell the Web Driver to wait for certain conditions before throwing an “ElementNotVisibleException” exception.

WebDriverWait wait = new WebDriverWait(WebDriver Reference, TimeOut);

Fluent wait – It is used to tell the web driver to wait for a condition, as well as the frequency with which we want to check the condition before throwing an “ElementNotVisibleException” exception.

Wait wait = new FluentWait(WebDriver reference).withTimeout(timeout, SECONDS).pollingEvery(timeout, SECONDS).ignoring(Exception.class);

Mention the types of navigation commands 

driver.navigate().to(“https://www.ebay.in/“); – Navigates to the provided URL

driver.navigate().refresh(); – This method refreshes the current page

driver.navigate().forward(); – This method does the same operation as clicking on the Forward Button of any browser. It neither accepts nor returns anything.

driver.navigate().back(); – This method does the same operation as clicking on the Back Button of any browser. It neither accepts nor returns anything.

What is the major difference between driver.close() and driver.quit()?

driver.close()

This command closes the browser’s current window. If multiple windows are open, the current window of focus will be closed.

driver.quit()

When quit() is called on the driver instance and there are one or more browser windows open, it closes all the open browser windows.

How to type text in an input box using Selenium?

sendKeys() is the method used to type text in input boxes

Consider the following example –

WebElement email = driver.findElement(By.id(“email”)); – Finds the “email” text using the ID locator

email.sendKeys(“abcd.efgh@gmail.com”);  – Enters text into the URL field

WebElement password = driver.findElement(By.id(“Password”)); – Finds the “password” text using the ID locator

password.sendKeys(“abcdefgh123”); – Enters text into the password field

Mention the types of Web locators.

Locator is a command that tells Selenium IDE which GUI elements ( say Text Box, Buttons, Check Boxes, etc) it needs to operate on. Locators specify the area of action.

Locator by ID: It takes a string parameter which is a value of the ID attribute which returns the object to findElement() method.

driver.findElement(By.id(“user”));

Locator by the link: If your targeted element is a link text then you can use the by.linkText locator to locate that element.

driver.findElement(By.linkText(“Today’s deals”)).click();

Locator by Partial link: The target link can be located using a portion of text in a link text element.

driver.findElement(By.linkText(“Service”)).click();

Locator by Name: The first element with the name attribute value matching the location will be returned.

driver.findElement(By.name(“books”).click());

Locator by TagName: Locates all the elements with the matching tag name

driver.findElement(By.tagName(“button”).click());

Locator by classname: This finds elements based on the value of the CLASS attribute. If an element has many classes then this will match against each of them.

driver.findElement(By.className(“inputtext”));

Locator by XPath: It takes a parameter of String which is a XPATHEXPRESSION and it returns an object to findElement() method.

driver.findElement(By.xpath(“//span[contains(text(),’an account’)]”)).getText();

Locator by CSS Selector: Locates elements based on the driver’s underlying CSS selector engine.

  driver.findElement(By.cssSelector(“input#email”)).sendKeys(“myemail@email.com”);

How to click on a hyperlink in Selenium?

driver.findElement(By.linkText(“Today’s deals”)).click();

The command finds the element using link text and then clicks on that element, where after the user would be redirected to the corresponding page.

driver.findElement(By.partialLinkText(“Service”)).click();

The above command finds the element based on the substring of the link provided in the parenthesis and thus partialLinkText() finds the web element.

How to scroll down a page using JavaScript?

scrollBy() method is used to scroll down the webpage

General syntax:

executeScript(“window.scrollBy(x-pixels,y-pixels)”);

First, create a JavaScript object

JavascriptExecutor js = (JavascriptExecutor) driver;

Launch the desired application

driver.get(“https://www.amazon.com”);

Scroll down to the desired location

js.executeScript(“window.scrollBy(0,1000)”); 

The window is not scrolled vertically by 1000 pixels

How to assert the title of a webpage? 

Get the title of the webpage and store in a variable

String actualTitle = driver.getTitle();

Type in the expected title

String expectedTitle = “abcdefgh”;

Verify if both of them are equal

if(actualTitle.equalsIgnoreCase(expectedTitle))

System.out.println(“Title Matched”);

else

System.out.println(“Title didn’t match”);

Alternatively,

Assert.assertEquals(actualTitle, expectedTitle);

How to mouse hover over a web element? 

Actions class utility is used to hover over a web element in Selenium WebDriver

Instantiate Actions class.

Actions action = new Actions(driver);

In this scenario, we hover over search box of a website

actions.moveToElement(driver.findElement(By.id(“id of the searchbox”))).perform();

How to retrieve CSS properties of an element?

getCssValue() method is used to retrieve CSS properties of any web element

General Syntax:

driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”);

Example:

driver.findElement(By.id(“email“)).getCssValue(“font-size”);

What is POM (Page Object Model)?

Every webpage of the application has a corresponding page class that is responsible for locating the web elements and performing actions on them. Page Object Model is a design pattern that helps create object repositories for the web elements. POM improves code reusability and readability. Multiple test cases can be run on the object repository.

Can Captcha be automated?

No, Selenium cannot automate Captcha. Well, the whole concept of Captcha is to ensure that bots and automated programs don’t access sensitive information – which is why, Selenium cannot automate it. The automation test engineer has to manually type the captcha while other fields can be filled automatically.

How does Selenium handle Windows-based pop-ups?

Selenium was designed to handle web applications. Windows-based features are not natively supported by Selenium. However, third-party tools like AutoIT, Robot, etc can be integrated with Selenium to handle pop-ups and other Windows-based features.

How to take screenshots in WebDriver?

TakeScreenshot interface can be used to take screenshots in WebDriver.

getScreenshotAs() method can be used to save the screenshot

File scrFile = ((TakeScreenshot)driver).getScreenshotAs(outputType.FILE);

Is there a way to type in a textbox without using sendKeys()?

Yes! Text can be entered into a textbox using JavaScriptExecutor

JavascriptExecutor jse = (JavascriptExecutor) driver;

jse.executeScript(“document.getElementById(‘email’).value=“abc.efg@xyz.com”);

How to select a value from a dropdown in Selenium WebDriver?

Select class in WebDriver is used for selecting and deselecting options in a dropdown.

The objects of Select type can be initialized by passing the dropdown webElement as a parameter to its constructor.

WebElement testDrop = driver.findElement(By.id(“testingDropdown”));  

Select dropdown = new Select(testDrop);

WebDriver offers three ways to select from a dropdown:

selectByIndex: Selection based on index starting from 0

dropdown.selectByIndex(5);

selectByValue: Selection based on value

dropdown.selectByValue(“Books”);

selectByVisibleText: Selection of option that displays text matching the given argument

dropdown.selectByVisibleText(“The Alchemist”);

What does the switchTo() command do? 

switchTo() command is used to switch between windows, frames or pop-ups within the application. Every window instantiated by the WebDriver is given a unique alphanumeric value called “Window Handle”.

Get the window handle of the window you wish to switch to

String  handle= driver.getWindowHandle();

Switch to the desired window

driver.switchTo().window(handle);

Alternatively

for(String handle= driver.getWindowHandles())

{ driver.switchTo().window(handle); }

 How to login to any site if it is showing an Authentication Pop-Up for Username and Password?

To handle authentication pop-ups, verify its appearance and then handle them using an explicit wait command.

Use the explicit wait command

WebDriverWait wait = new WebDriverWait(driver, 10);

Alert class is used to verify the alert

Alert alert = wait.until(ExpectedConditions.alertIsPresent());

Once verified, provide the credentials

alert.authenticateUsing(new UserAndPassword(<username>, <password>));

What is the difference between single and double slash in Xpath?

Single slash is used to create Xpath with an absolute path i.e. the XPath would be created to start selection from the start node.

/html/body/div[2]/div[1]/div[1]/a

Double slash is used to create Xpath with relative path i.e. the XPath would be created to start selection from anywhere within the document

//div[class=”qa-logo”]/a

How do you find broken links in Selenium WebDriver?

Answer: Finding broken links is an essential aspect of web application testing, as broken links can negatively impact user experience. Selenium WebDriver can be used to identify and validate links on a webpage. The process involves identifying all links, sending HTTP requests to each link, and analyzing the responses to determine whether the links are functional or broken.

Example: In this example, we’ll create a Selenium WebDriver script in Java to find and validate broken links on a webpage. We will use the HttpURLConnection class to send HTTP requests and check the response codes.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;

public class BrokenLinksExample {
public static void main(String[] args) {
// Set up WebDriver and open the webpage
WebDriver driver = new ChromeDriver();
driver.get("https://example.com");

// Find all links on the webpage
List<WebElement> links = driver.findElements(By.tagName("a"));

// Iterate through each link and check for broken links
for (WebElement link : links) {
String url = link.getAttribute("href");

// Validate the URL only if it is not null or empty
if (url != null && !url.isEmpty()) {
try {
// Create a URL object
URL linkURL = new URL(url);

// Open a connection to the URL
HttpURLConnection httpURLConnection = (HttpURLConnection) linkURL.openConnection();

// Get the HTTP response code
int responseCode = httpURLConnection.getResponseCode();

// Check if the response code indicates a broken link
if (responseCode >= 400) {
System.out.println("Broken Link: " + url + " - Response Code: " + responseCode);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

// Close the browser
driver.quit();
}
}

In this example:

  1. We use driver.findElements(By.tagName("a")) to find all the anchor elements (links) on the webpage.
  2. For each link, we extract the href attribute, which contains the URL.
  3. We use HttpURLConnection to open a connection to the URL and retrieve the HTTP response code.
  4. If the response code is greater than or equal to 400, it indicates a broken link, and we print the details.

This script can be extended to handle other types of links (images, scripts, etc.) and provides a foundation for creating a more comprehensive link validation framework in your testing suite.

How can you handle dynamic elements in Selenium?

Answer: Dynamic elements on a webpage are those whose attributes or presence may change dynamically based on user interactions or page updates. Handling such elements is crucial in test automation to ensure stable and reliable scripts. One effective way to deal with dynamic elements is by using Explicit Waits in Selenium.

Example: Suppose you have a scenario where a webpage has a button that becomes clickable after a certain amount of time or when an asynchronous operation completes. Without proper synchronization, your script might try to interact with the button before it is ready, leading to failures.

In this example, we’ll use Explicit Wait to handle a dynamically changing button. Let’s assume the button has an ID attribute of “dynamicButton.”

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.chrome.ChromeDriver;

public class DynamicElementExample {
public static void main(String[] args) {
// Set up WebDriver and open the webpage
WebDriver driver = new ChromeDriver();
driver.get("https://example.com");

// Use Explicit Wait for the dynamic button to be clickable
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement dynamicButton = wait.until(ExpectedConditions.elementToBeClickable(By.id("dynamicButton")));

// Perform an action on the dynamic button, now that it's ready
dynamicButton.click();

// Close the browser
driver.quit();
}
}

In this example:

  1. We use WebDriverWait to specify the maximum amount of time to wait for a certain condition (in this case, the button to be clickable).
  2. The ExpectedConditions.elementToBeClickable method waits until the specified element is clickable.
  3. Once the dynamic button is ready (clickable), we proceed with the desired action, such as clicking on it.

This Explicit Wait approach ensures that the script waits for the element to be in the desired state before interacting with it, making the test more robust and adaptable to dynamic changes in the application.

What is Selenium and what is composed of?

Selenium is a suite of tools for automated web testing.  It is composed of

  • Selenium IDE (Integrated Development Environment) :  It is a tool for recording and playing back.  It is a firefox plugin
  • WebDriver and RC:  It provide the APIs for a variety of languages like Java, .NET, PHP, etc. With most of the browsers Webdriver and RC works.
  • Grid: With the help of Grid you can distribute tests on multiple machines so that test can be run parallel which helps in cutting down the time required for running in browser test suites

What is Selenium 2.0 ?

Web Testing tools Selenium RC and WebDriver are consolidated in single tool in Selenium 2.0

 

Mention what is Selenium 3.0?

Selenium 3.0 is the latest version of Selenium. It has released 2 beta versions of selenium 3.0 with few of the below changes:

Here are few new features added to Selenium 3.0

How will you find an element using Selenium?

In Selenium every object or control in a web page is referred as an elements, there are different ways to find an element in a web page they are

  • ID
  • Name
  • Tag
  • Attribute
  • CSS
  • Linktext
  • PartialLink Text
  • Xpath etc

List out the test types that are supported by Selenium?

For web-based application testing selenium can be used

The test types can be supported are

  1. a) Functional,
  2. b) Regression

For post release validation with continuous integration automation tool could be used

  1. a) Jenkins
  2. b) Hudson
  3. c) Quick Build

Explain what is assertion in Selenium and what are the types of assertion?

Assertion is used as a verification point. It verifies that the state of the application conforms to what is expected.  The types of assertion are “assert” , “verify” and “waitFor”.

Mention what is the use of X-path?

X-Path is used to find the WebElement in web pages. It is also useful in identifying the dynamic elements.

Explain the difference between single and double slash in X-path?

Single slash ‘/ ’

  • Single slash ( / ) start selection from the document node
  • It allows you to create ‘absolute’ path expressions

Double Slash ‘// ’

  • Double slash ( // ) start selection matching anywhere in the document
  • It enables to create ‘relative’ path expressions

List out the technical challenges with Selenium?

Technical challenges with Selenium are

  • Selenium supports only web-based applications
  • It does not support the Bitmap comparison
  • For any reporting related capabilities have to depend on third party tools
  • No vendor support for tool compared to commercial tools like HP UFT
  • As there is no object repository concept in Selenium, maintainability of objects becomes difficult

What is the difference between type keys and type commands?

TypeKeys() will trigger JavaScript event in most of the cases whereas .type() won’t. Type key populates the value attribute using JavaScript whereas .typekeys() emulates like actual user typing

What is the difference between verify and assert commands?

Assert:  Assert allows to check whether an element is on the page or not. The test will stop on the step failed, if the asserted element is not available. In other words, the test will terminated at the point where check fails.

Verify: Verify command will check whether the element is on the page, if it is not then the test will carry on executing.  In verification, all the commands are going to run guaranteed even if any of test fails.

What is JUnit Annotations and what are different types of annotations which are useful?

In JAVA a special form of syntactic meta-data can be added to Java source code, this is known as Annotations.  Variables, parameters, packages, methods and classes are annotated some of the Junit annotations which can be useful are

  • Test
  • Before
  • After
  • Ignore
  • BeforeClass
  • AfterClass
  • RunWith

While using click command can you use screen coordinate? 

To click on specific part of element, you would need to use clickAT command.  ClickAt command accepts element locator and x, y co-ordinates as arguments- clickAt (locator, cordString)

What are the advantages of Selenium?

  • It supports C#, PHP, Java, Perl, Phython
  • It supports different OS like Windows, Linux and Mac OS
  • It has got powerful methods to locate elements (Xpath, DOM , CSS)
  • It has highly developer community supported by Google

Why testers should opt for Selenium and not QTP?

Selenium is more popular than QTP as

  • Selenium is an open source whereas QTP is a commercial tool
  • Selenium is used specially for testing web-based applications while QTP can be used for testing client server application also
  • Selenium supports Firefox, IE, Opera, Safari on operating systems like Windows, Mac, Linux etc. however QTP is limited to Internet Explorer on Windows.
  • Selenium supports many programming languages like Ruby, Perl, Python whereas QTP supports only VB script

 What are the four parameter you have to pass in Selenium?

Four parameters that you have to pass in Selenium are

  • Host
  • Port Number
  • Browser
  • URL

What is the difference between setSpeed() and sleep() methods?

Both will delay the speed of execution.

Thread.sleep () :  It will stop the current (java) thread for the specified period of time.  Its done only once

  • It takes a single argument in integer format

Ex: thread.sleep(2000)- It will wait for 2 seconds

  • It waits only once at the command given at sleep

SetSpeed () :  For specific amount of time it will stop the execution for every selenium command.

  • It takes a single argument in integer format

Ex: selenium.setSpeed(“2000”)- It will wait for 2 seconds

  • Runs each command after set Speed delay by the number of milliseconds mentioned in set Speed

This command is useful for demonstration purpose or if you are using a slow web application

What is same origin policy? How you can avoid same origin policy?

The “Same Origin Policy” is introduced for security reason, and it ensures that content of your site will never be accessible by a script from another site.  As per the policy, any code loaded within the browser can only operate within that website’s domain.

To avoid “Same Origin Policy” proxy injection method is used, in proxy injection mode the Selenium Server acts as a client configured HTTP proxy , which sits between the browser and application under test and then masks the AUT under a fictional URL

What is heightened privileges browsers?

The purpose of heightened privileges is similar to Proxy Injection, allows websites to do something that are not commonly permitted.  The key difference is that the browsers are launced in a special mode called heightened privileges.  By using these browser mode, Selenium core can open the AUT directly and also read/write its content without passing the whole AUT through the Selenium RC server.

How you can use “submit” a form using Selenium ?

You can use “submit” method on element to submit form-

element.submit () ;

Alternatively you can use click method on the element which does form submission

What are the features of TestNG and list some of the functionality in TestNG which makes it more effective?

TestNG is a testing framework based on JUnit and NUnit to simplify a broad range of testing needs, from Unit Testing to Integration Testing. And the functionality which makes it efficient testing framework are

  • Support for annotations
  • Support for data-driven testing
  • Flexible test configuration
  • Ability to re-execute failed test cases

Mention what is the difference between Implicit wait and Explicit wait?

Implicit Wait: Sets a timeout for all successive Web Element searches. For the specified amount of time, it will try looking for element again and again before throwing a NoSuchElementException.  It waits for elements to show up.

Explicit Wait:  It is a one-timer, used for a particular search.

Which attribute you should consider throughout the script in frame for “if no frame Id as well as no frame name”?

You can use…..driver.findElements(By.xpath(“//iframe”))….

This will return list of frames.

You will need to switch to each and every frame and search for locator which we want.

Then break the loop

Explain what is the difference between find elements () and find element () ?

find element ():

It finds the first element within the current page using the given “locating mechanism”.  It returns a single WebElement

findElements () : Using the given “locating mechanism” find all the elements within the current page.  It returns a list of web elements.

Explain what are the JUnits annotation linked with Selenium?

The JUnits annotation linked with Selenium are

  • @Before public void method() – It will perform the method () before each test, this method can prepare the test
  • @Test public void method() – Annotations @Test identifies that this method is a test method environment
  • @After public void method()- To execute a method before this annotation is used, test method must start with test@Before

Explain what is Datadriven framework and Keyword driven?

Datadriven framework:  In this framework, the test data is separated and kept outside the Test Scripts, while Test Case logic resides in Test Scripts.  Test data is read from the external files ( Excel Files) and are loaded into the variables inside the Test Script.  Variables are used for both for input values and for verification values.

Keyworddriven framework: The keyword driven frameworks requires the development of data tables and keywords, independent of the test automation.  In a keyword driven test, the functionality of the application under test is documented in a table as well as step by step instructions for each test.

Explain how you can login into any site if it’s showing any authentication popup for password and username?

Pass the username and password with url

  • Syntax-http://username:password@url
  • ex- http://creyate:tom@www.gmail.com

Explain how to assert text of webpage using selenium 2.0 ?

WebElement el = driver.findElement(By.id(“ElementID”))

//get test from element and stored in text variable

String text = el.getText();

//assert text from expected

Assert.assertEquals(“Element Text”, text);

Explain what is the difference between Borland Silk and Selenium?

                          Silk Test Tool                         Selenium Test Tool
  • Borland Silk test is not a free testing tool
  • Selenium is completely free test automation tool
  • Silk test supports only Internet Explorer and Firefox
  • Selenium supports many browsers like Internet Explorer, Firefox, Safari, Opera and so on
  • Silk test uses test scripting language
  • Selenium suite has the flexibility to use many languages like Java, Ruby,Perl and so on
  • Silk test can be used for client server applications
  • Selenium can be used for only web application

What is Object Repository?

An object repository is an essential entity in any UI automations which allows a tester to store all object that will be used in the scripts in one or more centralized locations rather than scattered all over the test scripts.

Explain how Selenium Grid works?

Selenium Grid sent the tests to the hub. These tests are redirected to Selenium Webdriver, which launch the browser and run the test.  With entire test suite, it allows for running tests in parallel.

Can we use Selenium grid for performance testing?

Yes. But not as effectively as a dedicated Performance Testing tool like Loadrunner.

List the advantages of Webdriver over Selenium Server?

  • If you are using Selenium-WebDriver, you don’t need the Selenium Server as it is using totally different technology
  • Selenium Server provides Selenium RC functionality which is used for Selenium 1.0 backwards compatibility
  • Selenium Web driver makes direct calls to browser using each browsers native support for automation, while Selenium RC requires selenium server to inject Javascript into the browser

Mention what are the capabilities of Selenium WebDriver or Selenium 2.0 ?

WebDriver should be used when requiring improvement support for

  • Handling multiple frames, pop ups , multiple browser windows and alerts
  • Page navigation and drag & drop
  • Ajax based UI elements
  • Multi browser testing including improved functionality for browser not well supported by Selenium 1.0

While injecting capabilities in webdriver to perform tests on a browser which is not supported by a webdriver what is the limitation that one can come across?

Major limitation of injecting capabilities is that “findElement” command may not work as expected.

Explain how you can find broken images in a page using Selenium Web driver ?

To find the broken images in a page using Selenium web driver is

  • Get XPath and get all the links in the page using tag name
  • In the page click on each and every link
  • Look for 404/500 in the target page title

Explain how you can handle colors in web driver?

To handle colors in web driver you can use

Use getCssValue(arg0) function to get the colors by sending ‘color’ string as an argument

Using web driver how you can store a value which is text box?

You can use following command to store a value which is text box using web driver

driver.findElement(By.id(“your Textbox”)).sendKeys(“your keyword”);

Explain how you can switch between frames?

To switch between frames webdrivers [ driver.switchTo().frame() ] method takes one of the three possible arguments

  • A number:  It selects the number by its (zero-based) index
  • A name or ID: Select a frame by its name or ID
  • Previously found WebElement: Using its previously located WebElement select a frame

Mention 5 different exceptions you had in Selenium web driver?

The 5 different exceptions you had in Selenium web drivers are

  • WebDriverException
  • NoAlertPresentException
  • NoSuchWindowException
  • NoSuchElementException
  • TimeoutException

Explain using Webdriver how you can perform double click ?

You can perform double click by using

  • Syntax- Actions act = new Actions (driver);
  • act.doubleClick(webelement);

How will you use  Selenium to upload a file ?

You can use “type”command to type in a file input box of upload file. Then, you have to use “Robot” class in JAVA to make file upload work.

Which web driver implementation is fastest?

HTMLUnit Driver implementation is fastest, HTMLUnitDriver does not execute tests on browser but plain http request, which is far quick than launching a browser and executing tests

Explain how you can handle frames using Selenium 2.0 ?

To bring control on HTML frame you can use “SwitchTo” frame method-

driver.switchTo().frame(“frameName”);

To specify a frame you can use index number

driver.switchTo().frame(“parentFrame.4.frameName”);

This would bring control on frame named- “frameName” of the 4th sub frame names “parentFrame”

What is the difference between getWindowhandles() and getwindowhandle() ?

getwindowhandles(): It is used to get the address of all the open browser and its return type is Set<String>

getwindowhandle(): It is used to get the address of the current browser where the control is and return type is string

Explain how you can switch back from a frame?

To switch back from a frame use method defaultContent()

Syntax-driver.switchTo().defaultContent();

List out different types of locators?

Different types of locators are

  • By.id()
  • By.name()
  • By.tagName()
  • By.className()
  • By.linkText()
  • By.partialLinkText()
  • By.xpath
  • By.cssSelector()

 What is the command that is used in order to display the values of a variable into the output console or log?

  • In order to display a constant string, command can be used is echo <constant string>
  • If order to display the value of a variable you can use command like echo ${variable name>>

Above is using PHP. If you are using Java, replace echo with System.out.println

 Explain how you can use recovery scenario with Selenium?

Recovery scenarios depends upon the programming language you use.  If you are using Java then you can use exception handling to overcome same.  By using “Try Catch Block” within your Selenium WebDriver Java tests

Explain how to iterate through options in test script?

To iterate through options in test script you can loop features of the programming language, for example to type different test data in a text box you can use “for” loop in Java

// test data collection in an array

String[ ] testData = { “test1” , “test2” , “test3” } ;

// iterate through each test data

For  (string s: test data) { selenium.type ( “elementLocator”, testData) ; }

How can you prepare customized html report using TestNG in hybrid framework ?

There are three ways

  • Junit: With the help of ANT
  • TestNG: Using inbuilt default.html to get the HTML report. Also XST reports from ANT, Selenium, Testng combinations
  • Using our own customized reports using XSL jar for converting XML content to HTML

From your test script how you can create html test report?

To create html test report there are three ways

  • TestNG:  Using inbuilt default.html to get the HTML report. Also XLST reports from ANT, Selenium, TestNG combination
  • JUnit: With the help of ANT
  • Using our own customized reports using XSL jar for converting XML content to HTML

Explain how you can insert a break point in Selenium IDE ?

In Selenium IDE to insert a break point

  • Select “Toggle break point” by right click on the command in Selenium IDE
  • Press “B” on the keyboard and select the command in Selenium IDE
  • Multiple break points can be set in Selenium IDE

Explain in Selenium IDE how can you debug the tests?

  • Insert a break point from the location from where you want to execute test step by step
  • Run the test case
  • At the given break point execution will be paused
  • To continue with the next statement click on the blue button
  • Click on the “Run” button to continue executing all the commands at a time

What is Selenese and what are the types of Selenese ?

Selenese is a selenium set of command which are used for running the test

There are three types of Selenese

  • Actions: It is used for performing the operations and interactions with the target elements
  • Assertions: It is used as a check points
  • Accessors: It is used for storing the values in a variable

Explain what are the limitations of Selenium IDE?

The limitations of Selenium IDE

  • Exceptional handling is not present
  • Selenium IDE uses only HTML languages
  • External databases reading is not possible with IDE
  • Reading from the external files like .txt, .xls is not possible
  • Conditional or branching statements execution like if,else,  select statements is not possible

What are the two modes of views in Selenium IDE ?

Either Selenium IDE can be opened as a pop up window or in side bar

8In selenium IDE what are the element locators that can be used to locate elements on web page?

In selenium there are mainly 4 locators that are used

  • X-path locators
  • Css locators
  • Html id
  • Html name

In Selenium IDE how you can generate random numbers and dates for test data ?

In Selenium IDE you can generate random numbers by using Java Script

type

css=input#s

javascript{Math.random()}

And for

type

css=input#s

javascript{new Date()}

 How you can convert any Selenium IDE tests from Selenese to another language?

You can use the format option of Selenium IDE to convert tests into another programming language

Using Selenium IDE is it possible to get data from a particular html table cell ?

You can use the “storeTable” command

Example store text from cell 0,2 from an html table

storeTable

Css=#table 0.2

textFromCell

 Explain what can cause a Selenium IDE test to fail?

  • When a locator has changed and Selenium IDE cannot locate the element
  • When element Selenium IDE waiting to access did not appear on the web page and the operation timed out

Explain how you can debug the tests in Selenium IDE ?

  • Insert a break point from the location where you want to execute step by step
  • Run the test case
  • At the given break point execution will be paused
  • To continues with the next step click on the Blue button
  • To run commands at a time click on run button

From Selenium IDE how you can execute a single line?

From Selenium IDE single line command can be executed in two ways

  • Select “Execute this command” by right clicking on the command in Selenium IDE
  • Press “X” key on the keyboard after selecting the command in Selenium IDE

In which format does source view shows your script in Selenium IDE ?

In Selenium IDE source view shows your script in XML format

Explain how you can insert a start point in Selenium IDE?

In two ways selenium IDE can be set

  • Press “S” key on the keyboard and select the command in Selenium IDE
  • In Seleniun IDE right click on the command and the select  “Set / Clear Start Point”

What if you have written your own element locator and how would you test it?

To test the locator one can use “Find Button” of Selenium IDE, as you click on it, you would see on screen an element being highlighted provided your element locator is right or or else an error message will be displayed

 What is regular expressions? How you can use regular expressions in Selenium ?

A regular expression is a special text string used for describing a search pattern. In Selenium IDE regular expression can be used with the keyword- regexp: as a prefix to the value and patterns needs to be included for the expected values.

What are core extension ?

If you want to “extend” the defualt functionality provided by Selenium Function Library , you can create a Core Extension. They are also called “User Extension”. You can even download ready-made Core Extension created by other Selenium enthusiats.

How will you handle working with multiple windows in Selenium ?

We can use the command selectWindow to switch between windows. This command uses the title of Windows to identify which window to switch to.

How will you verify the specific position of an web element

You can use verifyElementPositionLeft & verifyElementPositionTop. It does a pixel comparison of the position of the element from the Left and Top of page respectively

How can you retrive the message in an alert box ?

You can use the storeAlert command which will fetch the message of the alert pop up and store it in a variable.

What is selenium RC (Remote Control)?

Selenium IDE have limitations in terms of browser support and language support. By using Selenium RC limitation can be diminished.

  • On different platforms and  different web browser for automating web application  selenium RC is used with languages like Java, C#, Perl, Python
  • Selenium RC is a java based and using any language it can interact with the web application
  • Using server you can bypass the restriction and run your automation script running against any web application

Why Selenium RC is used?

Selenium IDE does not directly support many functions like condition statements, Iteration, logging and reporting of test results, unexpected error handling and so on as IDE supports only HTML language.  To handle such issues Selenium RC is used  it supports the language like Perl, Ruby, Python, PHP using these languages we can write the program to achieve the IDE issues.

 Explain what is the main difference between web-driver and RC ?

The main difference between Selenium RC and Webdriver is that, selenium RC injects javascript function into browsers when the page is loaded. On the other hand, Selenium Webdriver drives the browser using browsers built in support

What are the advantages of RC?

Advantages of RC are

  • Can read or write data from/ to .xls, .txt, etc
  • It can handle dynamic objects and Ajax based UI elements
  • Loops and conditions can be used for better performance and flexibility
  • Support many Programming languages and Operating Systems
  • For any JAVA script enabled browser Selenium RC can be used

Explain what is framework and what are the frameworks available in RC?

A collection of libraries and classes is known as Framework and they are helpful when testers has to automate test cases. NUnit, JUnit, TestNG, Bromine, RSpec, unittest are some of the frameworks available in RC .

. How can we handle pop-ups in RC ?

To handle pop-ups in RC , using selectWindow method, pop-up window will be selected and windowFocus method will let the control from current window to pop-up windows and perform actions according to script

What are the technical limitations while using Selenium RC?

Apart from “same origin policy” restriction from js, Selenium is also restricted from exercising anything that is outside browser.

Can we use Selenium RC to drive tests on two different browsers on one operating system without Selenium Grid?

Yes, it is possible when you are not using JAVA testing framework.  Instead of using Java testing framework if you are using java client driver of selenium then TestNG allows you to do this.  By using “parallel=test” attribute you can set tests to be executed in parallel and can define two different tests, each using different browser.

Why to use TestNG with Selenium RC ?

If you want full automation against different server and client platforms, You need a way to invoke the tests from a command line process, reports that tells you what happened and flexibility in how you create your test suites. TestNG gives that flexibility.

Explain how you can capture server side log Selenium Server?

To capture server side log in Selenium Server, you can use command

  • java –jar .jar –log selenium.log

Other than the default port 4444 how you can run Selenium Server?

You can run Selenium server on java-jar selenium-server.jar-port other than its default port

How Selenium grid hub keeps in touch with RC slave machine?

At predefined time selenium grid hub keeps polling all RC slaves to make sure it is available for testing.  The deciding parameter is called “remoteControlPollingIntervalSeconds” and is defined in “grid_configuration.yml”file

Using Selenium how can you handle network latency?

To handle network latency you can use driver.manage.pageloadingtime for network latency

To enter values onto text boxes what is the command that can be used?

To enter values onto text boxes we can use command sendkeys()

How do you identify an object using selenium?

To identify an object using Selenium you can use

isElementPresent(String locator)

isElementPresent takes a locator as the argument and if found returns a Boolean

In Selenium what are Breakpoints and Startpoints?

  • Breakpoints: When you implement a breakpoint in your code, the execution will stop right there. This helps you to verify that your code is working as expected.
  • StartpointsStartpoint indicates the point from where the execution should begin. Startpoint can be used when you want to run the testscript from the middle of the code or a breakpoint.

Mention why to choose Python over Java in Selenium?

Few points that favor Python over Java to use with Selenium is,

  • Java programs tend to run slower compared to Python programs.
  • Java uses traditional braces to start and ends blocks, while Python uses indentation.
  • Java employs static typing, while Python is dynamically typed.
  • Python is simpler and more compact compared to Java.

Mention what are the challenges in Handling Ajax Call in Selenium Webdriver?

The challenges faced in Handling Ajax Call in Selenium Webdriver are

  • Using “pause” command for handling Ajax call is not completely reliable. Long pause time makes the test unacceptably slow and increases the testing time. Instead, “waitforcondition” will be more helpful in testing Ajax applications.
  • It is difficult to assess the risk associated with particular Ajax applications
  • Given full freedom to developers to modify Ajax application makes the testing process challenging
  • Creating automated test request may be difficult for testing tools as such AJAX application often use different encoding or serialization technique to submit POST data.

Mention what is IntelliJ?

Intellij is an IDE that helps you to write better and faster code for Selenium. Intellij can be used in the option to Java bean and Eclipse.

Mention in what ways you can customize TestNG report?

You can customize TestNG report in two ways,

  • Using ITestListener Interface
  • Using IReporter Interface

To generate pdf reports mention what Java API is required?

To generate pdf reports, you need Java API IText.

Mention what is Listeners in Selenium WebDriver?

In Selenium WebDriver, Listeners “listen” to the event defined in the selenium script and behave accordingly. It allows customizing TestNG reports or logs. There are two main listeners i.e. WebDriver Listeners and TestNG Listeners.

Mention what are the types of Listeners in TestNG?

The types of Listeners in TestNG are,

  • IAnnotationTransformer
  • IAnnotationTransformer2
  • IConfigurable
  • IConfigurationListener
  • IExecutionListener
  • IHookable
  • IInvokedMethodListener
  • IInvokedMethodListener2
  • IMethodInterceptor
  • IReporter
  • ISuiteListener
  • ITestListener

Mention what is desired capability? How is it useful in terms of Selenium?

The desired capability is a series of key/value pairs that stores the browser properties like browser name, browser version, the path of the browser driver in the system, etc. to determine the behavior of the browser at run time.

For Selenium,

  • It can be used to configure the driver instance of Selenium WebDriver.
  • When you want to run the test cases on a different browser with different operating systems and versions.

For Database Testing in Selenium Webdriver what API is required?

For Database Testing in Selenium Webdriver, you need JDBC (Java Database Connectivity) API. It allows you to execute SQL statements.

Mention when to use AutoIT?

Selenium is designed to automate web-based applications on different browsers. But to handle window GUI and non-HTML popups in the application you need AutoIT. know more about

Mention why do you need Session Handling while working with Selenium?

While working with Selenium, you need Session Handling. This is because, 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. So to avoid such situation you need Session Handling.

Mention what are the advantages of Using Git Hub For Selenium?

The advantages of Using Git Hub for Selenium are

  • Multiple people when they work on the same project they can update project details and inform other team members simultaneously.
  • Jenkins can help you to build the project from the remote repository regularly. This helps you to keep track of failed builds.

What are the advantages and disadvantages of Selenium over other testing tools like QTP and TestComplete?

The differences are listed below.

Selenium vs HP QTP vs TestComplete

Features Selenium HP QTP TestComplete
License Open Source Required Required
Cost Free High High
Customer support Yes; Open-source community Yes Yes
Release Cycles/ Development Sprints Smaller release cycles with immediate feedback Smaller release cycles Agility only
Coding skills Very High Low High
Environment support Windows, Linux, Mac Only Windows Windows only (7, Vista, Server 2008 or later OS)
Language support Language support VB Script VB Script, JS Script, Delphi Script, C++ & C#

What are the significant changes in upgrades in various Selenium versions?

Selenium v1 included only three suite of tools: Selenium IDE, Selenium RC and Selenium Grid. Note that there was no WebDriver in Selenium v1. Selenium WebDriver was introduced in Selenium v2. With the onset of WebDriver, Selenium RC got deprecated and is not in use since. Older versions of RC is available in the market though, but support for RC is not available. Currently, Selenium v3 is in use, and it comprises of IDE, WebDriver and Grid. Selenium 4 is actually the latest version.

IDE is used for recording and playback of tests, WebDriver is used for testing dynamic web applications via a programming interface and Grid is used for deploying tests in remote host machines.

Explain the different exceptions in Selenium WebDriver.

Exceptions in Selenium are similar to exceptions in other programming languages. The most common exceptions in Selenium are:

  • TimeoutException: This exception is thrown when a command performing an operation does not complete in the stipulated time
  • NoSuchElementException: This exception is thrown when an element with given attributes is not found on the web page
  • ElementNotVisibleException: This exception is thrown when the element is present in DOM (Document Object Model), but not visible on the web page
  • StaleElementException: This exception is thrown when the element is either deleted or no longer attached to the DOM

What is exception test in Selenium?

An exception test is an exception that you expect will be thrown inside a test class. If you have written a test case in such way that it should throw an exception, then you can use the @Test annotation and specify which exception you will be expecting by mentioning it in the parameters. Take a look at the example below: @Test(expectedException = NoSuchElementException.class)

Do note the syntax, where the exception is suffixed with .class

How to upload a file in Selenium WebDriver? 

You can achieve this by using sendkeys() or Robot class method. Locate the text box and set the file path using sendkeys() and click on submit button

Locate the browse button

WebElement browse =driver.findElement(By.id(“uploadfile”));

Pass the path of the file to be uploaded using sendKeys method

browse.sendKeys(“D:\\SeleniumInterview\\UploadFile.txt”);

How to set browser window size in Selenium?

The window size can be maximized, set or resized

To maximize the window

driver.manage().window().maximize();

To set the window size

Dimension d = new Dimension(400,600);

driver.manage().window().setSize(d);

Alternatively,

The window size can be reset using JavaScriptExecutor

((JavascriptExecutor)driver).executeScript(“window.resizeTo(1024, 768)”);

When do we use findElement() and findElements()?

findElement() is used to access any single element on the web page. It returns the object of the first matching element of the specified locator.

General syntax:

WebElement element = driver.findElement(By.id(example));

findElements() is used to find all the elements in the current web page matching the specified locator value. All the matching elements would be fetched and stored in the list of Web elements.

General syntax:

List <WebElement> elementList = driver.findElements(By.id(example));

What is a pause on an exception in Selenium IDE? 

The user can use this feature to handle exceptions by clicking the pause icon on the top right corner of the IDE. When the script finds an exception it pauses at that particular statement and enters a debug mode. The entire test case does not fail and hence the user can rectify the error immediately. 

Why and how will you use an Excel Sheet in your project?

The reason we use Excel sheets is because it can be used as data source for tests. An excel sheet can also be used to store the data set while performing DataDriven Testing. These are the two main reasons for using Excel sheets.

When you use the excel sheet as data source, you can store the following:

  • Application URL for all environments: You can specify the URL of the environment in which you want to do the testing like: development environment or testing environment or QA environment or staging environment or production/ pre-production environment.
  • User name and password credentials of different environments: You can store the access credentials of the different applications/ environments in the excel sheet. You can store them in encoded format and whenever you want to use them, you can decode them instead of leaving it plain and unprotected.
  • Test cases to be executed: You can list down the entire set of test cases in a column and in the next column, you can specify either Yes or No which indicates if you want that particular test case to be executed or ignored.

When you use the excel sheet for DataDriven Test, you can store the data for different iterations to be performed in the tests. For example while testing a web page, the different sets of input data that needs to be passed to the test box can be stored in the excel sheet.

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

Selenium provides a PROXY class to redirect browsing from a proxy. Look at the example below:

1

2

3

4

5

6

7

8

9

String PROXY = “199.201.125.147: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);

What is POM (Page Object Model)? What are its advantages?

Page Object Model is a design pattern for creating an Object Repository for web UI elements. Each web page in the application is required to have it’s own corresponding page class. The page class is thus responsible for finding the WebElements in that page and then perform operations on those WebElements.

The advantages of using POM are:

  • Allows us to separate operations and flows in the UI from Verification – improves code readability
  • Since the Object Repository is independent of Test Cases, multiple tests can use the same Object Repository
  • Reusability of code

What is Page Factory?

Page Factory gives an optimized way to implement Page Object Model. When we say it is optimized, it refers to the fact that the memory utilization is very good and also the implementation is done in an object-oriented manner.

Page Factory is used to initialize the elements of the Page Object or instantiate the Page Objects itself. Annotations for elements can also be created (and recommended) as the describing properties may not always be descriptive enough to differentiate one object from the other.

The concept of separating the Page Object Repository and Test Methods is followed here also. Instead of having to use ‘FindElements’, we use annotations like: @FindBy to find WebElement, and initElements method to initialize web elements from the Page Factory class.

@FindBy can accept tagName, partialLinkText, name, linkText, id, css, className & xpath as attributes.

What are the different types of WAIT statements in Selenium WebDriver? Or the question can be framed like this: How do you achieve synchronization in WebDriver?

There are basically two types of wait statements: Implicit Wait and Explicit Wait.

Implicit wait instructs the WebDriver to wait for some time by polling the DOM. Once you have declared implicit wait, it will be available for the entire life of the WebDriver instance. By default, the value will be 0. If you set a longer default, then the behavior will poll the DOM on a periodic basis depending on the browser/ driver implementation.

Explicit wait instructs the execution to wait for some time until some condition is achieved. Some of those conditions to be attained are:

  • elementToBeClickable
  • elementToBeSelected
  • presenceOfElementLocated

Write a code to wait for a particular element to be visible on a page. Write a code to wait for an alert to appear.

We can write a code such that we specify the XPath of the web element that needs to be visible on the page and then ask the WebDriver to wait for a specified time. Look at the sample piece of code below:

1

2

WebDriverWait wait=new WebDriverWait(driver, 20);

Element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( “<xpath”)));

Similarly, we can write another piece of code asking the WebDriver to wait until an error appears like this:

1

2

WebDriverWait wait=new WebDriverWait(driver, 20);

Element = wait.until(ExpectedConditions.alertIsPresent());

What is the use of JavaScriptExecutor?

JavaScriptExecutor is an interface which provides a mechanism to execute Javascript through the Selenium WebDriver. It provides “executescript” and “executeAsyncScript” methods, to run JavaScript in the context of the currently selected frame or window. An example of that is:

1

2

JavascriptExecutor js = (JavascriptExecutor) driver;

js.executeScript(Script,Arguments);

How to scroll down a page using JavaScript in Selenium?

We can scroll down a page by using window.scrollBy() function. Example:

1 ((JavascriptExecutor) driver).executeScript(“window.scrollBy(0,500)”);

How to scroll down to a particular element?

To scroll down to a particular element on a web page, we can use the function scrollIntoView(). Example:

1 ((JavascriptExecutor) driver).executeScript(“arguments[0].scrollIntoView();”, element);

How to handle keyboard and mouse actions using Selenium?

We can handle special keyboard and mouse events by using Advanced User Interactions API. The Advanced User Interactions API contains the Actions and the Action Classes that are needed for executing these events. Most commonly used keyboard and mouse events provided by the Actions class are in the table below:

Selenium functions and their explanation

 

What are different types of frameworks?

The different types of frameworks are:

  • Data Driven Framework: –
    When the entire test data is generated from some external files like Excel, CSV, XML or some database table, then it is called Data Driven framework.
  • Keyword Driven Framework:-
    When only the instructions and operations are written in a different file like an Excel worksheet, it is called Keyword Driven framework.
  • Hybrid Framework:-
    A combination of both the Data Driven framework and the Keyword Driven framework is called Hybrid framework.

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

Some of the file types of the dataset can be: excel, xml, text, csv, etc.

How can you fetch an attribute from an element? How to retrieve typed text from a textbox?

We can fetch the attribute of an element by using the getAttribute() method. Sample code:

1

2

WebElement eLogin = driver.findElement(By.name(“Login”);

String LoginClassName = eLogin.getAttribute(“classname”);

Here, I am finding the web page’s login button named ‘Login’. Once that element is found, getAttribute() can be used to retrieve any attribute value of that element and it can be stored it in string format. In my example, I have retrieved ‘classname’ attribute and stored it in LoginClassName.

Similarly, to retrieve some text from any textbox, we can use getText() method. In the below piece of code I have retrieved the text typed in the ‘Login’ element.

1

2

WebElement eLogin = driver.findElement(By.name(“Login”);

String LoginText = Login.getText ();

In the below Selenium WebDriver tutorial, there is a detailed demonstration of locating elements on the web page using different element locator techniques and the basic methods/ functions that can be applied on those elements.

What is Selenese?

Selenese is the set of selenium commands which are used to test your web application.

You can even make use of:

  • Actions: Used for performing operations
  • Assertions: Used as checkpoints
  • Accessors: Used for storing a value in a particular variable

What is the difference between Page Object Model (POM) and Page Factory?

 

Can Selenium handle window pop-ups?

Selenium does not support handling pop-ups. Alert is used to display a warning message. It is a pop-up window that comes up on the screen.

A few methods using which this can be achieved:

  • Void dismiss(): This method is called when the ‘Cancel’ button is clicked in the alert box.
  • Void accept(): This method is called when you click on the ‘OK’ button of the alert.
  • String getText(): This method is called to capture the alert message.
  • Void sendKeys(String stringToSed): This is called when you want to send some data to alert box.

How to click on a hyper link using linkText?

  1. driver.findElement(By.linkText(“Google”)).click();

The above command search the element using a link text, then click on that element and thus the user will be re-directed to the corresponding page.

The following command can access the link mentioned earlier.

  1. driver.findElement(By.partialLinkText(“Goo”)).click();

The above-given command searches the element based on the substring of the link provided in the parenthesis. And after that partialLinkText() finds the web element with the specified substring and then clicks on it.

What is a Robot class?

This Robot class provides control over the mouse and keyboard devices.

The methods include:

  • KeyPress(): This method is called when you want to press any key.
  • KeyRelease(): This method is used to release the pressed key on the keyboard.
  • MouseMove(): This method is called when you want to move the mouse pointer in the X and Y co-ordinates.
  • MousePress(): This is used to press the left button of the mouse.
  • MouseMove(): This method helps in releasing the pressed button of the mouse.

How to handle multiple windows in Selenium?

A window handle is a unique identifier that holds the address of all the windows. This is basically a pointer to a window, which returns the string value.

  • get.windowhandle(): helps in getting the window handle of the current window.
  • get.windowhandles(): helps in getting the handles of all the windows opened.
  • set: helps to set the window handles which is in the form of a string.
  • switch to: helps in switching between the windows.
  • action: helps to perform certain actions on the windows.

What are Listeners in Selenium?

It is defined as an interface that modifies the behavior of the system. Listeners allow customization of reports and logs.

Listeners mainly comprise of two types, namely

  1. WebDriver listeners
  2. TestNG listeners

What are Assert and Verify commands?

  • Assert: An assertion is used to compare the actual result of an application with the expected result.
  • Verify: There won’t be any halt in the test execution even though the verify condition is true or false.

Can you navigate back and forth the webpage in Selenium?

Yes. You can navigate in the browser. A few methods using which you can achieve it are:

  • driver.navigate.forward
  • driver.manage.back
  • driver.manage.navigate
  • driver.navigate.to(“url”)

From here on, we’ll be looking at the most important advanced level interview questions for Selenium testers.

How to send ALT/SHIFT/CONTROL key in Selenium WebDriver?

When we generally use ALT/SHIFT/CONTROL keys, we hold onto those keys and click other buttons to achieve the special functionality. So it is not enough just to specify keys.ALT or keys.SHIFT or keys.CONTROL functions.

For the purpose of holding onto these keys while subsequent keys are pressed, we need to define two more methods: keyDown(modifier_key) and keyUp(modifier_key)

Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)
Purpose: Performs a modifier key press and does not release the modifier key. Subsequent interactions may assume it’s kept pressed.

Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)
Purpose: Performs a key release.
Hence with a combination of these two methods, we can capture the special function of a particular key.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

public static void main(String[] args)

{

String baseUrl = “https://www.facebook.com”;

WebDriver driver = new FirefoxDriver();

 

driver.get(“baseUrl”);

WebElement txtUserName = driver.findElement(By.id(“Email”);

 

Actions builder = new Actions(driver);

Action seriesOfActions = builder

.moveToElement(txtUerName)

.click()

.keyDown(txtUserName, Keys.SHIFT)

.sendKeys(txtUserName, “hello”)

.keyUp(txtUserName, Keys.SHIFT)

.doubleClick(txtUserName);

.contextClick();

.build();

seriesOfActions.perform();

}

How to take screenshots in Selenium WebDriver?

You can take a screenshot by using the TakeScreenshot function. By using getScreenshotAs() method you can save that screenshot. Example:

1 File scrFile = ((TakeScreenshot)driver).getScreenshotAs(outputType.FILE);

How to set the size of browser window using Selenium?

To maximize the size of browser window, you can use the following piece of code:
driver.manage().window().maximize(); – To maximize the window

To resize the current window to a particular dimension, you can use the setSize() method. Check out the below piece of code:

1

2

3

System.out.println(driver.manage().window().getSize());

Dimension d = new Dimension(420,600);

driver.manage().window().setSize(d);

To set the window to a particular size, use window.resizeTo() method. Check the below piece of code:

1 ((JavascriptExecutor)driver).executeScript(“window.resizeTo(1024, 768);”);

To witness a demonstration on setting custom sizes for the browser window and finding various elements on the web page, see the video below.

How to handle a dropdown in Selenium WebDriver? How to select a value from dropdown?

Questions on dropdown and selecting a value from that dropdown are very common Selenium interview questions because of the technicality involved in writing the code.

The most important detail you should know is that to work with a dropdown in Selenium, we must always make use of this html tag: ‘select’. Without using ‘select’, we cannot handle dropdowns. Look at the snippet below in which I have written a code for a creating a dropdown with three options.

1

2

3

4

5

<select id=”mySelect”>

<option value=”option1″>Cars</option>

<option value=”option2″>Bikes</option>

<option value=”option3″>Trains</option>

</select>

In this code we use ‘select’ tag to define a dropdown element and the id of the dropdown element is ‘myselect’. We have 3 options in the dropdown: Cars, Bikes and Trains. Each of these options, have a ‘value’ attribute also assigned to them. First option from dropdown has value assigned as ‘option1’, second option has value = ‘option2’ and similarly third option has value assigned as ‘option3’.

If you are clear with the concept so far, then you can proceed to the next aspect of choosing a value from the dropdown. This is a 2 step process:

  1. Identify the ‘select’ html element (Because dropdowns must have the ‘select’ tag)
  2. Select an option from that dropdown element

To identify the ‘select’ html element from the web page, we need to use findElement() method. Look at the below piece of code:

1

2

WebElement mySelectElement = driver.findElement(By.id(“mySelect”));

Select dropdown = new Select(mySelectElement);

Now to select an option from that dropdown, we can do it in either of the three ways:

  1. dropdown.selectByVisibleText(“Bikes”); → Selecting an option by the text that is visible
  2. dropdown.selectByIndex(“1”); → Selecting, by choosing the Index number of that option
  3. dropdown.selectByValue(“option2”); → Selecting, by choosing the value of that option

Note that from the above example, in all the three cases, “Bikes” will be chosen from the dropdown. In the first case, we are choosing by visible text on the web page. When it comes to selection by index, 1 represents “Bikes” because indexing values start from 0 and then get incremented to 1 and 2. Finally in case of selection by value attribute, ‘option2’ refers to “Bikes”. So, these are the different ways to choose a value from a dropdown.

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

If you click on a link in a web page, then for changing the WebDriver’s focus/ reference to the new window we need to use the switchTo() command. Look at the below example to switch to a new window:
driver.switchTo().window();

Here, ‘windowName’ is the name of the window you want to switch your reference to.

In case you do not know the name of the window, then you can use the driver.getWindowHandle() command to get the name of all the windows that were initiated by the WebDriver. Note that it will not return the window names of browser windows which are not initiated by your WebDriver.

Once you have the name of the window, then you can use an enhanced for loop to switch to that window. Look at the piece of code below.

1

2

3

4

5

String handle= driver.getWindowHandle();

for (String handle : driver.getWindowHandles())

{

driver.switchTo().window(handle);

}

How do you upload a file using Selenium WebDriver?

To upload a file we can simply use the command element.send_keys(file path). But there is a prerequisite before we upload the file. We have to use the html tag: ‘input’ and attribute type should be ‘file’. Take a look at the below example where we are identifying the web element first and then uploading the file.

1

2

3

<input type=”file” name=”uploaded_file” size=”50″ class=”pole_plik”>

element = driver.find_element_by_id(”uploaded_file”)

element.send_keys(“C:myfile.txt”)

Can we enter text without using sendKeys()?

Yes. We can enter/ send text without using sendKeys() method. We can do it using JavaScriptExecutor.

How do we do it?
Using DOM method of, identification of an element, we can go to that particular document and then get the element by its ID (here login) and then send the text by value. Look at the sample code below:

1

2

JavascriptExecutor jse = (JavascriptExecutor) driver;

jse.executeScript(“document.getElementById(‘Login’).value=Test text without sendkeys”);

Explain how you will login into any site if it is showing any authentication popup for username and password?

Since there will be popup for logging in, we need to use the explicit command and verify if the alert is actually present. Only if the alert is present, we need to pass the username and password credentials. The sample code for using the explicit wait command and verifying the alert is below:

1

2

3

WebDriverWait wait = new WebDriverWait(driver, 10);

Alert alert = wait.until(ExpectedConditions.alertIsPresent());

alert.authenticateUsing(new UserAndPassword(**username**, **password**));

Explain how can you find broken links in a page using Selenium WebDriver?

This is a tricky question which the interviewer will present to you. He can provide a situation where in there are 20 links in a web page, and we have to verify which of those 20 links are working and how many are not working (broken).

Since you need to verify the working of every link, the workaround is that, you need to send HTTP requests to all of the links on the web page and analyze the response. Whenever you use driver.get() method to navigate to a URL, it will respond with a status of 200 – OK. 200 – OK denotes that the link is working and it has been obtained. If any other status is obtained, then it is an indication that the link is broken.

But how will you do that?
First, we have to use the anchor tags <a> to determine the different hyperlinks on the web page. For each <a> tag, we can use the attribute ‘href’ value to obtain the hyperlinks and then analyze the response received for each hyperlink when used in driver.get() method.

Which technique should you consider using throughout the script “if there is neither frame id nor frame name”?

If neither frame name nor frame id is available, then we can use frame by index.

Let’s say, that there are 3 frames in a web page and if none of them have frame name and frame id, then we can still select those frames by using frame (zero-based) index attribute. Each frame will have an index number. The first frame would be at index “0”, the second at index “1” and the third at index “2”. Once the frame has been selected, all subsequent calls on the WebDriver interface will be made to that frame.

1 driver.switchTo().frame(int arg0);

From here on, you’ll read all the TestNG and Selenium Webdriver interview questions for experienced professionals.

What is the significance of testng.xml?

I’m pretty sure you all know the importance of TestNG. Since Selenium does not support report generation and test case management, we use TestNG framework with Selenium. TestNG is much more advanced than JUnit, and it makes implementing annotations easy. That is the reason TestNG framewrok is used with Selenium WebDriver.

But have you wondered where to define the test suites and grouping of test classes in TestNG?

It is by taking instructions from the testng.xml file. We cannot define a test suite in testing source code, instead it is represented in an XML file, because suite is the feature of execution. The test suite, that I am talking about is basically a collection of test cases.

So for executing the test cases in a suite, i.e a group of test cases, you have to create a testng.xml file which contains the name of all the classes and methods that you want to execute as a part of that execution flow.

Other advantages of using testng.xml file are:

  • It allows execution of multiple test cases from multiple classes
  • It allows parallel execution
  • It allows execution of test cases in groups, where a single test can belong to multiple groups

What is parameterization in TestNG? How to pass parameters using testng.xml?

Parameterization is the technique of defining values in testng.xml file and sending them as parameters to the test class. This technique is especially useful when we need to pass multiple login credentials of various test environments. Take a look at the code below, in which “myName” is annotated as a parameter.

1

2

3

4

5

6

7

public class ParameterizedTest1{

@Test

@Parameters(“myName”)

public void parameterTest(String myName) {

System.out.println(“Parameterized value is : ” + myName);

}

}

To pass parameters using testng.xml file, we need to use ‘parameters’ tag. Look at the below code for example:

1

2

3

4

5

6

7

8

9

10

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE suite SYSTEM “<a href=”http://testng.org/testng-1.0.dtd”>http://testng.org/testng-1.0.dtd</a>” >

<suite name=”CustomSuite”>

<test name=”CustomTest”>

<parameter name=”myName” value=”John”/>

<classes>

<class name=”ParameterizedTest1″ />

</classes>

</test>

</suite>

Explain DataProviders in TestNG using an example. Can I call a single data provider method for multiple functions and classes?

DataProvider is a TestNG feature, which enables us to write DataDriven tests. When we say, it supports DataDriven testing, then it becomes obvious that the same test method can run multiple times with different data-sets. DataProvider is in fact another way of passing parameters to the test method.

@DataProvider marks a method as supplying data for a test method. The annotated method must return an Object[] where each Object[] can be assigned to parameter list of the test method.

To use the DataProvider feature in your tests, you have to declare a method annotated by @DataProvider and then use the said method in the test method using the ‘dataProvider‘ attribute in the Test annotation.

As far as the second part of the question is concerned, Yes, the same DataProvider can be used in multiple functions and classes by declaring DataProvider in separate class and then reusing it in multiple classes.

How to skip a method or a code block in TestNG?

If you want to skip a particular test method, then you can set the ‘enabled’ parameter in test annotation to false.
@Test(enabled = false)

By default, the value of ‘enabled’ parameter will be true. Hence it is not necessary to define the annotation as true while defining it.

What is soft assertion in Selenium? How can you mark a test case as failed by using soft assertion?

Soft Assertions are customized error handlers provided by TestNG. Soft Assertions do not throw exceptions when assertion fails, and they simply continue to the next test step. They are commonly used when we want to perform multiple assertions.

To mark a test as failed with soft assertions, call assertAll() method at the end of the test.

Explain what is Group Test in TestNG?

In TestNG, methods can be categorized into groups. When a particular group is being executed, all the methods in that group will be executed. We can execute a group by parameterizing it’s name in group attribute of @Test annotation. Example: @Test(groups={“xxx”})

1

2

3

4

5

6

7

8

9

10

11

12

13

14

@Test(groups={“Car”})

public void drive(){

system.out.println(“Driving the vehicle”);

}

 

@Test(groups={“Car”})

public void changeGear() {

system.out.println(“Change Gears”);

}

 

@Test(groups={“Car”})

public void accelerate(){

system.out.println(“Accelerating”);

}

How does TestNG allow you to state dependencies? Explain it with an example.

Dependency is a feature in TestNG that allows a test method to depend on a single or a group of test methods. Method dependency only works if the “depend-on-method” is part of the same class or any of the inherited base classes (i.e. while extending a class).

Syntax: @Test(dependsOnMethods = { “initEnvironmentTest” })

1

2

3

4

5

6

7

8

9

10

11

12

13

14

@Test(groups={“Car”})

public void drive(){

system.out.println(“Driving the vehicle”);

}

 

@Test(dependsOnMethods={“drive”},groups={cars})

public void changeGear() {

system.out.println(“Change Gears”);

}

 

@Test(dependsOnMethods={“changeGear”},groups={“Car”})

public void accelerate(){

system.out.println(“Accelerating”);

}

Explain what does @Test(invocationCount=?) and @Test(threadPoolSize=?) indicate.

@Test(invocationCount=?) is a parameter that indicates the number of times this method should be invoked.
@Test(threadPoolSize=?) is used for executing suites in parallel. Each suite can be run in a separate thread.

To specify how many times @Test method should be invoked from different threads, you can use the attribute threadPoolSize along with invocationCount. Example:

1

2

3

@Test(threadPoolSize = 3, invocationCount = 10)

public void testServer() {

}

 

How to build the object repository?

An object repository is a common storage location for all objects. In Selenium WebDriver context, objects would typically be the locators used to uniquely identify web elements.

How do you achieve synchronization in WebDriver?

It is a mechanism which involves more than one components to work parallel with each other.

Synchronization can be classified into two categories:

  • Unconditional: In this we just specify timeout value only. We will make the tool to wait until certain amount of time and then proceed further.
  • Conditional: It specifies a condition along with timeout value, so that tool waits to check for the condition and then come out if nothing happens.

What are different types of TestNG Listeners in Selenium?

  • IAnnotationTransformer
  • IAnnotationTransformer2
  • IConfigurable
  • IConfigurationListener
  • IExecutionListener
  • IHookable
  • IInvokedMethodListener
  • IInvokedMethodListener2
  • IMethodInterceptor
  • IReporter
  • ISuiteListener
  • ITestListener

How can you prepare a customised HTML report in TestNG using Hybrid framework?

  • Junit with the help of an Ant.
  • TestNG using inbuild default file.
  • Also use XSL file.

How can you achieve Database Testing using Selenium?

Selenium does not support Database Testing, still, it can be partially done using JDBC and ODBC.

Please explain the various Selenium components.

Answer: Although labeled as an automation testing tool, Selenium isn’t a standalone tool. Instead, it is a package of several tools, and thus a testing suite. The Selenium suite has the following components:

  • Selenium IDE – Distributed as a Firefox plugin, Selenium IDE serves as a record and playback tool.
  • Selenium Grid – Allows distributing test execution across multiple platforms and environments concurrently.
  • Selenium RC – A server that allows users to create test scripts in a desirable programming language. Selenium RC also permits executing test scripts across a diverse range of web browsers.
  • Selenium WebDriver – Communicated directly with the web browser in addition to using its native compatibility to automate.

Could you state the limitations of Selenium?

Answer:

  • Although Selenium has an active community support, no vendor support is available
  • No built-in report generation. Third-party tools like JUnit and TestNG need to be used
  • Not able to offer testing for barcode and captcha readers
  • Requires good programming language knowledge
  • Supports testing of only web-based applications. Hence, doesn’t provide support for testing mobile applications

What are the different types of locators in Selenium?

Answer: A locator is a kind of address that offers a unique way of identifying a web element on the webpage. Selenium has a range of locators to identify different elements of a webpage, namely:

  • ClassName
  • CSS Selector
  • DOM
  • ID
  • LinkText
  • Name
  • PartialLinkText
  • TagName
  • XPath

Can you explain the difference between assert and verify commands in Selenium?

Answer: Both assert and verify commands are responsible for checking whether the given condition is true or false. However, the main distinction between the two lies what each of them does after the condition checking is complete.

If the condition comes out to be false in the case of a verify command, then the execution stops and no further tests will be executed. However, if the condition is true then the program control will continue executing the next test step.

Verify command, on the other hand, does not care about the result of the condition checking. Whether it is true or false, the program execution continues and all the test steps will be completed.

What do you understand by XPath in Selenium? Can you tell the difference between “/” and “//” in XPath?

Answer: XPath is a type of locator in Selenium that is used to locate a web element based on its XML path. XML denotes Extensible Markup Language, which is used for storing, organizing, and transporting arbitrary data. Much like HTML tags, XML stores data in a key-value pair.

Since HTML and XML both are markup languages, XPath can be used for locating HTML elements on a webpage. The underlying principle of XPath is traversing between several elements across the entire webpage and allowing them to find an element with the reference of some other element.

The single slash i.e. ‘/’ is used to create XPath with the absolute path, while the double slash i.e. ‘//’ is used for creating XPath with the relative path.

In the absolute path, the created XPath will start selection from the document node or the start node. However, in the relative path, the created XPath can start selection from anywhere within the entire web document.

How will you launch the browser using WebDriver?

Answer: The syntax used for launching Google Chrome, Mozilla Firefox, and Internet Explorer using WebDriver is respectively,

  • WebDriver driver = new FirefoxDriver();
  • WebDriver driver = new ChromeDriver();
  • WebDriver driver = new InternetExplorerDriver();

Please explain how to find if an element is displayed on the screen.

Answer: The WebDriver component of the Selenium suite facilitates checking the visibility of web elements, which can be buttons, checkboxes, drop boxes, labels, radio buttons, et cetera. WebDriver allows doing so with the following three methods:

  • isDisplayed()
    boolean buttonPresence = driver.findElement(By.id(“some id”)).isDisplayed();
  • isEnabled()
    boolean searchIconEnabled = driver.findElement(By.id(“some id”)).isEnabled();
  • isSelected()
    boolean buttonSelected = driver.findElement(By.id(“some id”)).isSelected();

What do you mean by Same Origin Policy? How to handle it?

Answer: An Origin is a sequential combination of host, scheme, and port of the URL. The issue of the same-origin policy restricts accessing the DOM of a document from an origin that is different from the one that a user is trying to access the document.

The Selenium Core isn’t allowed to access the elements from an origin that is different from where it was launched. Selenium Remote Control was introduced in order to handle the problem of Same Origin Policy.

Do you know how to get a text of a web element using Selenium?

Answer: In order to retrieve the inner text of a specified web element, Selenium offers the get command. It returns a string value and doesn’t require any parameters. Get command is one of the most widely used commands for verifying errors, labels, messages, etc. displayed on webpages. The general syntax for the get command is:

String Text = driver.findElement(By.id(“Text”)).getText();

Please enumerate the various types of Drivers and Waits available in WebDriver.

Answer: WebDriver provides support for the following drivers:

  • AndroidDriver
  • ChromeDriver
  • FirefoxDriver
  • HtmlUnitDriver
  • InternetExplorerDriver
  • IPhoneDriver
  • OperaDriver
  • SafariDriver

There are two types of waits available in WebDriver, explained as follows:

  • Implicit Wait – Used for providing a default waiting time between each successive test step or command across the entire test script. Hence, the next test step or command will only execute when the set default waiting time, say 30 seconds, have passed since the execution completion of the previous test step or command. Can be applied to a particular instance or several instances.
  • Explicit Wait – Used for halting the execution until the occurrence of a particular condition or till the elapsing of the maximum time. Applied for a particular instance only.

What do you understand by Object Repository? How do you create one in Selenium?

Answer: The term Object Repository refers to the collection of web elements that belong to AUT (Application Under Test) and their locator values. A corresponding locator value can be populated from the Object Repository whenever an element is required within the script.

Instead of hardcoding locators within the scripts, they are stored in a centralized location using Object Repository. Typically, the objects are stored in an excel sheet in Selenium which acts as the Object Repository.

Please explain how to click on a hyperlink using its text.

Answer: The following command finds a specified element using the linkText() method and then clicks on that element to redirect the user to the corresponding webpage:

driver.findElement(By.linkText(“Google”)).click();

Another command that can be used for the same purpose is:

driver.findElement(By.partialLinkText(“Goo”)).click();

In this command, we use the partialLinkText() method. The aforementioned command finds the element based on the substring, Goo in this case, of the link provided.

What is the most important difference between driver.close() and driver.quit() commands in Selenium?

Answer: The close() method closes the currently accessed window by the WebDriver. Neither does the command requires any parameter nor does it returns any value.

Unlike the close() method, the quit() method is used for closing down all the windows opened by the program. Like close() command, the quit() method doesn’t require any parameter nor does have any return value type.

How will you find more than one web element in the list using Selenium?

Answer: Selenium offers WebElement List for finding more than a single web element in the list. Its use is demonstrated by the following code snippet:

List elementList =

driver.findElements(By.xpath(“//div[@id=‘example’]//ul//li”));

Int listSize = elementList.size();

for (int i=0; i<listSize; i++)

{

serviceProviderLinks.get(i).click();

driver.navigate().back();

}

Can you explain the differences between Selenium and QTP?

Answer:

  • Availability – Selenium is an open-source and free-to-use testing tool. QTP, on the other hand, is a licensed and commercial testing tool.
  • Browser Compatibility – While QTP provides support for only Chrome, Firefox, and Internet Explorer, Selenium can be used with the aforementioned plus Opera, Safari, and several others.
  • Object Repository – QTP automatically creates and maintains an Object Repository. However, this is not the case with Selenium as one needs to create an Object Repository while working with the automation testing tool.
  • Programming Language Support – The only programming language supported by QTP is VB but Selenium provides support for a multitude of programming languages, including C#, Java, Perl, Python, and Ruby.
  • Testing Support – Whereas Selenium offers testing of only web applications, QTP provides testing support for both web-based and Windows-based applications.
  • Vendor Support – No vendor support is available with Selenium while the same is available for QTP.

How will you handle web-based pop-ups in Selenium?

Answer: WebDriver allows handling web-based pop-ups via the Alert interface. The general syntax is:

Alert alert = driver.switchTo().alert();

alert.accept();

A total of 4 methods are available for handling the web-based pop-ups, namely:

  • String getText() – Returns text displayed on the alert box
  • void accept() – Clicks on the ‘Ok’ button as soon as the pop-up appears
  • void dismiss() – Clicks on the ‘Cancel’ button as soon as the pop-up appears
  • void sendKeys(String stringToSend) – Inputs a specified string pattern in the alert box

Can you explain the various types of navigation commands supported by Selenium?

Answer: Selenium supports a total of 4 navigation commands, listed as follows:

  • navigate().back() – Takes the user back to the previous webpage as per the web browser history. Requires no parameters
  • navigate().forward() – Navigates the user to the next webpage in the web browser history. Requires no parameters
  • navigate().refresh() – Reload all the web elements by refreshing the current webpage. Requires no parameters
  • navigate().to() – Lets the user launch a new web browser window and navigate to the specified URL given as a parameter

When should we use findElement() and findElements()?

Answer: findElement() – Used for finding the first element in the current webpage matching to the specified locator value. Irrespective of the number of positive matches, only the first element will be fetched. Its general syntax is:

WebElement element = driver.findElements(By.xpath(“//div[@id=’some id’]//ul//li”));

findElements() – Used for finding all elements matching the specified locator value in the current webpage. All matching elements will be fetched and stored in the list of WebElements. The general syntax for the method is:

List elementList = driver.findElements(By.xpath(“//div[@id=’some id’]//ul//li”));

What is JUnit? Explain the various JUnit annotations.

Answer: JUnit is a Java-based testing framework from Apache that complements Selenium. Various JUnit Annotations are enumerated as follows:

  • @After – Lets the system know that this method will be executed every time a test method achieves completion
  • @AfterClass – Lets the system know that this method must be executed once after any of the test methods
  • @Before – Lets the system know that this method will be executed just before every time a test method starts execution
  • @BeforeClass – Lets the system know that this method must be executed once before any of the test methods start execution
  • @Ignore – Lest the system know that this method shall be ignored i.e. it shall not be executed
  • @Test – Lets the system know that this method is a test method. It is possible to have several test methods in a single test script

Please explain the various types of Test Automation Frameworks.

Answer:

  • Behavior-Driven Development Framework – Allows automating functional validations in an easy-to-read and understandable format for different professionals, including analysts, developers, and testers.
  • Data-Driven Testing Framework – Helps in segregating the test script logic and the test data. Allows storing test data in some external database in the form of key-value pairs. These keys are used for accessing as well as populating the data within the test scripts.
  • Keyword-Driven Testing Framework – It is an extension to the data-driven testing framework in a way that in addition to separating test data from the test scripts, a keyword-driven testing framework stores a part of the test script code in an external data file.
  • Library Architecture Testing Framework – Works on the principle of determining the right steps and then grouping them together into functions under a library. These functions are called in the test scripts whenever required.
  • Module-Based Testing Framework – Divides each application under testing into a number of logical and isolated modules. A distinct test script is created for each module.
  • Hybrid Testing Framework – Offers features belonging to different types of testing frameworks. The idea is to reap in all the benefits of various approaches with a single testing tool.

What is Selenium? Define its composition?

Answer: Selenium is a suite of various tools that are used explicitly for automated web testing purposes. Its compositions have Selenium IDE (Integrated Development Environment), WebDriver and RC, and Grid.

How are Selenium 2.0 and Selenium 3.0 different from Selenium?

Answer: Selenium 2.0 has consolidated Selenium RC and WebDriver to make a single tool, while Selenium 3.0 is the latest version, which has Beta 1 and Beta 2 updates.

Identify the various test types that are supported by Selenium?

Answer: The various test types that are supported by Selenium include the following:

  1. Functional.
  2. Regression.
  3. CruiseCont.
  4. Hudson.
  5. Jenkins.
  6. Quick Build.

What is the role of Assertion in Selenium?

Answer: The role of Assertion in Selenium is to act as a verification point. It helps in verifying the state of the application that conforms to expectations.

What are the various types of Assertion in Selenium?

Answer: There are three types of Assertion in Selenium, which include the following:

  1. Assert.
  2. Verify.
  3. WaitFor.

What are the technical challenges with Selenium?

Answer: There are several technical challenges with Selenium which includes:

  1. It only supports web-based applications.
  2. Bitmap comparison is not supported.
  3. Third-party tools are sought for reporting purposes.
  4. Vendor support is minimal as compared to other commercial tools such as HP UFT.
  5. It is challenging to maintain objects in Selenium.

Differentiate between Type Keys and Type Commands in Selenium?

Answer: Types Keys collects the different value attributes using the JavaScript while the Type Commands imitates like an actual user typing.

Differentiate between Assert and Verify commands?

Answer: Assert commands helps in checking if the element is on the page or not. The test will fail in case of missing the required element and will get terminated. Verify commands helps in checking the element is on the page or not but will not terminate but will continue ahead on executing all the commands.

What are the distinct features of Selenium?

Answer: The distinct features of Selenium include the following:

  1. It supports C#, Python, Perl, JAVA, and PHP.
  2. It can run on various operating systems, including Mac OS, Linux, and Windows.
  3. It can easily locate elements using Xpath, CSS, and DOM.
  4. Its developer community is supported by Google.

What makes Selenium better than QTP?

Answer: The following features of Selenium makes it better than QTP:

Selenium QTP
It is an open-source It is a commercial tool
It is used for testing various web-based applications. It is used for web-based applications and testing client-server applications.
It supports Safari, Opera, and Firefox on Linux, Mac, and Windows. It supports only the Internet Explorer on Windows.
It supports different programming languages such as Python, Perl, and Ruby. It supports only VB Script.

Define the parameters in Selenium?

Answer: There are four parameters in Selenium which includes:

  1. Host.
  2. URL.
  3. Port Number.
  4. Browser.

What is the role of set Speed() and Sleep() methods in Selenium?

Answer: The role of set Speed() and Sleep() in Selenium is to delay the speed of execution.

Define heightened privileges browsers?

Answer: Heightened privileges browsers acts as proxy injections that allow different websites to do things that are normally not permitted. These browsers allow Selenium core to pen the AUT directly and thereby read and write its content without passing the whole AUT through the Selenium RC server.

What is a Borland Silk Test Tool?

Answer: A Borland Silk Test Tool is used for the client-server application using a test scripting language.

What is a Selenium Test Tool?

Answer: A Selenium Test Tool is used for web applications and has the flexibility to many languages, including JAVA, Perl, Ruby, and various others.

What are the major differences between Borland Silk Test Tool and Selenium Test Tool?

Answer: The major differences between Borland Silk Test Tool and Selenium Test Tool can be displayed as follows:

Borland Silk Test Tool Selenium Test Tool
It is not a free testing tool. It is a free testing tool.
It has to be applied manually. It is an automation tool.
It supports only Internet Explorer and Firefox. It supports all kinds of browsers, including Internet Explorer, Firefox, Safari, Opera, and various others.
It is specifically used for testing script language. It can be applied for testing programs in various languages.
It can be applied to a client-server application. It can be applied only to web applications.

How is Webdriver beneficial over Selenium Server?

Answer: Webdriver does not require the Selenium Server because it uses a completely different technology. It provides Selenium RC functionality, which provides backward compatibility to Selenium 1.0. Also, it makes a direct call to the various browsers for making automation. At the same time, in the case of Selenium RC, it requires the Selenium Server to input the Javascript into the browser.

What is the other name of Selenium WebDriver?

Answer: The other popular name of Selenium WebDriver is Selenium 2.0

What are the distinct features 0f Selenium WebDriver from Selenium 1.0?

Answer: The distinct features of Selenium WebDriver from Selenium 1.0 includes:

  1. It helps in handling multiple frames, browsers, windows, alerts, and pop-ups.
  2. It helps in-page navigation.
  3. It offers a drag and drop facility on the page.
  4. It applies the Ajax-based User Interface (UI) elements.
  5. It offers multiple browser testing facilities which helps in improving functionality for browsers which were earlier not supported by Selenium 1.0

Can we handle colors in Web Driver?

Answer: Yes, we can handle colors in Web Driver using the getCssValue(arg0) function. It will help in getting the color by sending the ‘color’ string as an argument.

Can we store a value, which is a text box?

Answer: Yes, we can store a value, which is a text box using Web Driver. We can apply driver.findElement(By.id(“your Textbox”)).sendKeys(“your keyword”);

Can we Switch between frames?

Answer: Yes, we can Switch between frames using the WebDrivers, which can take any arguments.

What are the three arguments that can be taken into consideration for Switching?

Answer: The three arguments that can be taken into consideration for Switching includes:

  1. A number: This will select the number by its zero-based index.
  2. A name or ID: This will select a frame by its name or ID.
  3. Previously found WebElement: This will help in using the previously located WebElement to select a frame.

What are the exceptions to Selenium WebDriver?

Answer: There are five different exceptions to Selenium WebDriver which includes:

  1. TimeoutException.
  2. WebDriverException.
  3. NoAlertPresentException.
  4. NoSuchElementException.
  5. NoSuchWindowException.

Which is the best WebDriver implementation?

Answer: The best WebDriver implementation of the HTML unit is the fastest because it does not execute the tests on the browsers but applies plain HTTP request, which is quick and helps in launching the browser and executing the tests.

What is test automation or automation testing?

Automation testing uses automation tools to write and execute test cases, no manual involvement is necessary for executing an automated test suite. Testers prefer automation tools to write test scripts and test cases and then group into test suites.

Automation testing enables the use of specialized tools to automate the execution of manually designed test cases without any human intervention. Automation testing tools can access the test data, controls the execution of tests and compares the actual result against the expected result. Consequently, generating detailed test reports of the system under test.

 

What are the advantages of automation testing?

Some basic Advantages of automation testing are as follows.

  • Automation testing supports both functional and performance test on an application.
  • It supports the execution of repeated test cases.
  • It facilitates parallel execution.
  • It aids in testing a large test matrix.
  • It improves accuracy because there are no chances of human errors.
  • It saves time and money.

Name some of the commonly used Automation Testing tools that are used for Functional Automation.

Lists of top 10 used automation testing tools for Functional Automation are as follows.

  • Teleric Test Studio, Developed by Teleric.
  • TestingWhiz
  • HPE Unified Functional Testing (HP – UFT formerly QTP)
  • Tosca Testsuite
  • Watir
  • Quick Test Professional, provided by HP.
  • Rational Robot, provided by IBM.
  • Coded UI, provided by Microsoft.
  • Selenium, open source.
  • Auto It, Open Source.

Name some of the commonly used Automation Testing tools that are used for Non-Functional Automation.

Lists of some commonly used Automation Testing tools for Non-Functional Automation are as follows.

  • Load Runner, provided by Hp.
  • JMeter, provided by Apache.
  • Burp Suite, provided by PortSwigger.
  • Acunetix, provided by Acunetix.

What is Selenium?

Selenium is a portable framework for software testing. Selenium tool facilitates with a playback tool for authoring functional tests without the need to learn a test scripting language.

Selenium is one of the most widely used open source Web UI (User Interface) automation testing suite. Jason Huggins developed Selenium in 2004 as an internal tool at Thought Works. Selenium supports automation across different browsers, platforms, and programming languages.

What are the different components of Selenium?

Selenium is not just a single tool but a suite of software’s, each having a different approach to support automation testing. It comprises of four major components which include:

  1. Selenium Integrated Development Environment (IDE)
  2. Selenium Remote Control (Now Deprecated)
  3. WebDriver
  4. Selenium Grid

List out the names of programming languages, browsers and operating systems that are supported by Selenium.

Selenium supports various operating systems, browsers and programming languages. Following is the list:

  • Programming Languages: C#, Java, Python, PHP, Ruby, Perl, JavaScript.
  • Operating Systems: Android, iOS, Windows, Linux, Mac, Solaris.
  • Browsers: Google Chrome, Mozilla Firefox, Internet Explorer, Edge, Opera, Safari, etc.

What are the significant changes/upgrades in various Selenium versions?

Selenium v1.0:

  • Version 1.0 was the initial release of Selenium.
  • It included three tools: Selenium IDE, Selenium RC, and Selenium Grid.

Selenium v2.0:

  • Selenium WebDriver was introduced replacing Selenium RC in version “2.0”.
  • With the onset of WebDriver, RC got deprecated and moved to the legacy package.

Selenium v3:

  • The latest release Selenium 3 has new added features and functionalities.
  • It includes Selenium IDE, Selenium WebDriver, and Selenium Grid.

List some of the test types that are supported by Selenium.

Different types of testing’s that we can achieve through Selenium are.

  • Functional Testing
  • Regression Testing
  • Sanity Testing
  • Smoke Testing
  • Responsive Testing
  • Cross Browser Testing
  • UI testing (black box)
  • Integration Testing

What is Selenium IDE?

Selenium IDE is implemented as Firefox extension which provides record and playback functionality on test scripts. It allows testers to export recorded scripts in many languages like HTML, Java, Ruby, RSpec, Python, C#, JUnit and TestNG.

Selenium IDE has limited scope, and the generated test scripts are not very robust, and portable.

What do you mean by Selenese?

Selenium commands, also known as “Selenese” are the set of commands used in Selenium that run your tests. For example, command – open (URL); launches the desired URL in the specified browser and it accept both relative and absolute URLs.

A sequence of Selenium commands (Selenese) together is known as a test script.

What are the different ways of locating a web element in Selenium?

In Selenium, web elements are identified and located with the help of Locators. Locators specify a target location which uniquely defines the web element in the context of a web application. Thus, to identify web elements accurately and precisely we have different types of locators in Selenium:

  • ID
  • ClassName
  • Name
  • TagName
  • LinkText
  • PartialLinkText
  • Xpath
  • CSS Selector
  • DOM

How many types of WebDriver API’s are available in Selenium?

The list of WebDriver API’s which are used to automate browser include:

  • AndroidDriver
  • ChromeDriver
  • EventFiringWebDriver
  • FirefoxDriver
  • HtmlUnitDriver
  • InternetExplorerDriver
  • iPhoneDriver
  • iPhoneSimulatorDriver
  • RemoteWebDriver

List out some of the Automation tools which could be integrated with Selenium to achieve continuous testing.

Selenium can be used to automate functional tests and can be integrated with automation test tools such as Maven, Jenkins, &Docker to achieve continuous testing. It can also be integrated with tools such as TestNG, &JUnit for managing test cases and generating reports.

What do you mean by the assertion in Selenium?

The assertion is used as a verification point. It verifies that the state of the application conforms to what is expected. The types of assertion are “assert”, “verify” and “waitFor”.

Explain the difference between assert and verify commands?

Assert: Assert command checks if the given condition is true or false. If the condition is true, the program control will execute the next phase of testing, and if the condition is false, execution will stop, and nothing will be executed.

Verify: Verify command also checks if the given condition is true or false. It doesn’t halt program execution, i.e., any failure during verification would not stop the execution, and all the test phases would be executed.

What do you mean by XPath?

XPath is also defined as XML Path. It is a language used to query XML documents. It is an important approach to locate elements in Selenium. XPath consists of a path expression along with some conditions. Here, we can easily write XPath script/query to locate any element in the webpage. It is developed to allow the navigation of XML documents. The key factors that it considered while navigating are selecting individual elements, attributes, or some other part of an XML document for specific processing. It also produces reliable locators. Some other points about XPath are as follows.

  • XPath is a language used for locating nodes in XML documents.
  • XPath can be used as a substitute when you don’t have a suitable id or name attribute for the element you want to locate.
  • XPath provides locating strategies like:
    • XPath Absolute
    • XPath Attributes

Explain XPath Absolute and XPath attributes.

XPath Absolute:

  • XPath Absolute enables users to mention the complete XPath location from the root HTML tag to the specific elements.
  • Syntax: //html/body/tag1[index]/tag2[index]/…/tagN[index]
  • Example: //html/body/div[2]/div/div[2]/div/div/div/fieldset/form/div[1]/input[1]

XPath Attributes:

  • XPath Attributes is always recommended when you don’t have a suitable id or name attribute for the element you want to locate.
  • Syntax: //htmltag[@attribute1=’value1′ and @attribute2=’value2′]
  • Example: //input[@id=’passwd’ and @placeholder=’password’]

What is the difference between “/” and “//” in XPath?

Single Slash “/”: Single slash is used to create XPath with absolute path.

Double Slash “//”: Double slash is used to create XPath with the relative path.

What are the different types of annotations which are used in Selenium?

JUnit annotations which can be used are:

  • Test
  • Before
  • After
  • Ignore
  • BeforeClass
  • AfterClass
  • RunWith

What are the WebDriver supported Mobile Testing Drivers?

WebDriver supported “mobile testing drivers” are:

  • AndroidDriver
  • IphoneDriver
  • OperaMobileDriver

What are the popular programming languages supported by Selenium WebDriver to write Test Cases?

Selenium WebDriver supports the below languages to write Test Cases.

  • JAVA
  • PHP
  • Python
  • C#
  • Ruby
  • Perl

What is the difference between type keys and type commands?

TypeKeys() will trigger JavaScript event in most of the cases whereas .type() won’t.

What is the difference between “type” and “typeAndWait” command?

“type” command is used to type keyboard key values into the text box of software web application. It can also be used for selecting values of combo box whereas “typeAndWait” command is used when your typing is completed and software web page start reloading. This command will wait for software application page to reload. If there is no page reload event on typing, you have to use a simple “type” command.

What is the difference between findElement() and findElements()?

findElement(): It is used to find the first element within the current page using the given “locating mechanism”. It returns a single WebElement.

findElements(): It uses the given “locating mechanism” to find all the elements within the current page. It returns a list of web elements.

What is the wait? How many types of waits in selenium?

Selenium Webdriver introduces the concept of waits for the AJAX-based application. There are two types of waits:

  1. Implicit Wait
  2. Explicit Wait

What is the main disadvantage of implicit wait?

The main disadvantage of implicit wait is that it slows down test performance.

Another disadvantage of implicit wait is:

Suppose, you set the waiting limit to be 10 seconds, and the elements appear in the DOM in 11 seconds, your tests will be failed because you told it to wait a maximum of 10 seconds.

What is Selenium Grid?

Selenium Grid facilitates you to distribute your tests on multiple machines and all of them at the same time. So, you can execute tests on Internet Explorer on Windows and Safari on Mac machine using the same text script. It reduces the time of test execution and provides quick feedback.

How can we launch different browsers in Selenium WebDriver?

We have to create an instance of a driver of that particular browser.

  1. WebDriver driver =newFirefoxDriver();

Here, “WebDriver” is an interface, and we are creating a reference variable “driver” of type WebDriver, instantiated using “FireFoxDriver” class.

Write a code snippet to launch Firefox browser in WebDriver.

  1. public class FirefoxBrowserLaunchDemo {
  2. public static void main(String[] args) {
  3. //Creating a driver object referencing WebDriver interface
  4. WebDriver driver;
  5. //Setting webdriver.gecko.driver property
  6. System.setProperty(“webdriver.gecko.driver”, pathToGeckoDriver + “\\geckodriver.exe”);
  7. //Instantiating driver object and launching browser
  8. driver = newFirefoxDriver();
  9. //Using get() method to open a webpage
  10. driver.get(“http://javatpoint.com”);
  11. //Closing the browser
  12. driver.quit();
  13.     }
  14. }

Write a code snippet to launch Chrome browser in WebDriver.

  1. public class ChromeBrowserLaunchDemo {
  2. public static void main(String[] args) {
  3. //Creating a driver object referencing WebDriver interface
  4. WebDriver driver;
  5. //Setting the webdriver.chrome.driver property to its executable’s location
  6. System.setProperty(“webdriver.chrome.driver”, “/lib/chromeDriver/chromedriver.exe”);
  7. //Instantiating driver object
  8. driver = newChromeDriver();
  9. //Using get() method to open a webpage
  10. driver.get(“http://javatpoint.com”);
  11. //Closing the browser
  12. driver.quit();
  13.     }
  14. }

Write a code snippet to launch Internet Explorer browser in WebDriver.

  1. public class IEBrowserLaunchDemo {
  2. public static void main(String[] args) {
  3. //Creating a driver object referencing WebDriver interface
  4. WebDriver driver;
  5. //Setting the webdriver.ie.driver property to its executable’s location
  6. System.setProperty(“webdriver.ie.driver”, “/lib/IEDriverServer/IEDriverServer.exe”);
  7. //Instantiating driver object
  8. driver = newInternetExplorerDriver();
  9. //Using get() method to open a webpage
  10. driver.get(“http://javatpoint.com”);
  11. //Closing the browser
  12. driver.quit();
  13.     }
  14. }

Write a code snippet to perform right-click an element in WebDriver.

We will use Action class to generate user event like right-click an element in WebDriver.

  1. Actions action = newActions(driver);
  2. WebElement element = driver.findElement(By.id(“elementId”));
  3. action.contextClick(element).perform();

Write a code snippet to perform mouse hover in WebDriver.

  1. Actions action = newActions(driver);
  2. WebElement element = driver.findElement(By.id(“elementId”));
  3. action.moveToElement(element).perform();

How do you perform drag and drop operation in WebDriver?

Code snippet to perform drag and drop operation:

  1. //WebElement on which drag and drop operation needs to be performed
  2. WebElementfromWebElement = driver.findElement(By Locator of fromWebElement);
  3. //WebElement to which the above object is dropped
  4. WebElementtoWebElement = driver.findElement(By Locator of toWebElement);
  5. //Creating object of Actions class to build composite actions
  6. Actions builder = newActions(driver);
  7. //Building a drag and drop action
  8. Action dragAndDrop = builder.clickAndHold(fromWebElement)
  9.              .moveToElement(toWebElement)
  10.              .release(toWebElement)
  11.          .build();
  12. //Performing the drag and drop action
  13. dragAndDrop.perform();

What are the different methods to refresh a web page in WebDriver?

There are multiple ways of refreshing a page in Webdriver.

  1. Using driver.navigate command –
  1. driver.navigate().refresh();
  1. Using driver.getCurrentUrl() with driver.get() command –
  1. driver.get(driver.getCurrentUrl());
  1. Using driver.getCurrentUrl() with driver.navigate() command –
  1. driver.navigate().to(driver.getCurrentUrl());
  1. Pressing an F5 key on any textbox using the sendKeys command –
  1. driver.findElement(By textboxLocator).sendKeys(Keys.F5);
  1. Passing ascii value of the F5 key, i.e., “\uE035” using the sendKeys command –
  1. driver.findElement(By textboxLocator).sendKeys(“\uE035”);

Write a code snippet to navigate back and forward in browser history?

Navigate back in browser history:

  1. driver.navigate().back();

Navigate forward in browser history:

  1. driver.navigate().forward();

How to invoke an application in WebDriver?

  1. driver.get(“url”); or
  2. driver.navigate().to(“url”);

What are the benefits of Automation Testing?

Benefits of Automation testing are as follows.

  • It allows execution of repeated test cases
  • It enables parallel execution
  • Automation Testing encourages unattended execution
  • It improves accuracy. Thus, it reduces human-generated errors
  • It saves time and money.

How can we get a text of a web element?

Get command is used to get the inner text of the specified web element. The get command doesn’t require any parameter, but it returns a string type value. It is also one of the widely used commands for verification of messages, labels, and errors,etc.,from web pages.

Syntax

  1. String Text = driver.findElement(By.id(“Text”)).getText();

How to select value in a dropdown?

We use the WebDriver’s Select class to select the value in the dropdown.

Syntax:

selectByValue:

  1. Select selectByValue = new Select(driver.findElement(By.id(“SelectID_One”)));
  2. selectByValue.selectByValue(“greenvalue”);

selectByVisibleText:

  1. Select selectByVisibleText = new Select (driver.findElement(By.id(“SelectID_Two”)));
  2. selectByVisibleText.selectByVisibleText(“Lime”);
  1. Select selectByIndex = new Select(driver.findElement(By.id(“SelectID_Three”)));
  2. selectByIndex.selectByIndex(2);

What are the different types of navigation commands?

The navigation commands are as follows.

navigate().back()

The above command needs no parameters and takes back the user to the previous webpage.

Example

  1. driver.navigate().back();

navigate().forward()

The above command allows the user to navigate to the next web page with reference to the browser’s history.

Example

  1. driver.navigate().forward();

navigate().refresh()

The navigate().refresh() command allows the user to refresh the current web page by reloading all the web elements.

Example

  1. driver.navigate().refresh();

navigate().to()

The navigate().to() command allows the user to launch a new web browser window and navigate to the specified URL.

Example

  1. driver.navigate().to(“https://google.com”);

How to deal with frame in WebDriver?

An inline frame abbreviates as an iframe. It is used to insert another document within the current document. These document can be HTML document or simply web page and nested web page.

Select iframe by id

  1. driver.switchTo().frame(“ID of the frame”);

Locating iframe using tagName

  1. driver.switchTo().frame(driver.findElements(By.tagName(“iframe”).get(0));

Locating iframe using index

frame(index)

  1. driver.switchTo().frame(0);

frame(Name of Frame)

  1. driver.switchTo().frame(“name of the frame”);

frame(WebElement element)

Select Parent Window

  1. driver.switchTo().defaultContent();

Is there an HtmlUnitDriver for .NET?

To use HtmlUnit first use the RemoteWebDriver and pass it in the desired capabilities.

  1. IWebDriver driver
  2. = new RemoteWebDriver(DesiredCapabilities.HtmlUnit())

For the Firefox implementation to run, use

  1. IWebDriver driver
  2. = new RemoteWebDriver(DesiredCapabilities.HtmlUnitWithJavaScript())

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

Selenium facilitates with a PROXY class to redirect browsing from a proxy. Look at the example below.

Example

  1. String PROXY = “199.201.125.147:8080”;
  2. org.openqa.selenium.Proxy proxy = new.org.openqa.selenium.Proxy();
  3. proxy.setHTTPProxy(Proxy)
  4.  .setFtpProxy(Proxy)
  5.  .setSslProxy(Proxy)
  6. DesiredCapabilities cap = new DesiredCapabilities();
  7. cap.setCapability(CapabilityType.PROXY, proxy);
  8. WebDriver driver = new FirefoxDriver(cap);

What is POM (Page Object Model)? What are its advantages?

Page Object Model is a design pattern for creating an Object directory for web UI elements. Each web page is required to have its page class. The page class is responsible for finding the WebElements in web pages and then perform operations on WebElements.

The benefits of using POM are as follows.

  • It facilitates with separate operations and flows in the UI from Verification – improves code readability
  • Multiple tests can use the same Object Repository because the Object Repository is independent of Test Cases.
  • Reusability of code

How to capture screenshot in WebDriver?

Below is the program to capture screenshot in WebDriver.

  1. import org.junit.After;
  2. import org.junit.Before;
  3. import org.junit.Test;
  4. import java.io.File;
  5. import java.io.IOException;
  6. import org.apache.commons.io.FileUtils;
  7. import org.openqa.selenium.OutputType;
  8. import org.openqa.selenium.TakesScreenshot;
  9. import org.openqa.selenium.WebDriver;
  10. import org.openqa.selenium.firefox.FirefoxDriver;
  11. public class TakeScreenshot {
  12. WebDriver drv;
  13. @Before
  14. public void setUp() throws Exception {
  15. driver = new FirefoxDriver();
  16. drv.get(“https://google.com”);
  17. }
  18. @After
  19. public void tearDown() throws Exception {
  20. drv.quit();
  21. }
  22. @Test
  23. public void test() throws IOException {
  24. //capture the screenshot
  25. File scrFile = ((TakeScreenshot)drv).getScreenshotAs(OutputType.FILE);
  26. // paste the screenshot in the desired location
  27. FileUtils.copyFile(scrFile, new File(“C:\\Screenshot\\Scr.jpg”))
  28. }
  29. }

How to type text in a textbox using Selenium?

The sendKeys(“String to be entered”) is used to enter the string in a textbox.

Syntax

  1. WebElement username = drv.findElement(By.id(“Email”));
  2. // entering username
  3. username.sendKeys(“sth”);

How can you find if an element is displayed on the screen?

WebDriver allows user to check the visibility of the web elements. These web elements can be buttons, radio buttons, drop, checkboxes, boxes, labels etc. which are used with the following methods.

  • isDisplayed()
  • isSelected()
  • isEnabled()

Syntax:

  1. isDisplayed():
  2. boolean buttonPresence = driver.findElement(By.id(“gbqfba”)).isDisplayed();
  3. isSelected():
  4. boolean buttonSelected = driver.findElement(By.id(“gbqfba”)).isSelected();
  5. isEnabled():
  6. boolean searchIconEnabled = driver.findElement(By.id(“gbqfb”)).isEnabled();

What is Selenium? Why is it used?

Selenium is a cross-platform and portable automation testing framework created by Jason Huggins in 2004.

It has seen several upgrades since then, WebDriver 2.0 in 2011, and 3.0 in 2016. Check the below Selenium timeline.

We can use Selenium to write automation scripts for testing web applications. It helps in reducing manual testing efforts, improves productivity and quality.

Cross-platform means a Selenium script written on one OS say Windows can run on other supported systems such as Linux or Mac OS without making any changes.

Portable means the same script created for a desktop-based device can run on different supported devices such as tablets, mobiles, etc.

What is Selenium RC, and how does it talk to a browser?

Selenium RC a.k.a. Remote Control came out in early 2004.

It exposed a set of client APIs which use to send commands to a server to perform actions on the browser.

What is Selenium 2.0, and why is it superior to RC?

Selenium 2.0 a.k.a. WebDriver is a set of native APIs which directly send commands to the browser instead of delegating to a server.

Its release came out in 2011. It provided the native WebDriver API interface replacing the old client-server API model.

What is Selenium 3.0, and why is it superior to 2.0?

It was a major WebDriver upgrade which landed up in 2016.

It is superior to 2.0 because it implemented the W3C specifications for Webdriver APIs to make them a global standard.

Until 3.0, it was the Selenium community that was supplying Web drivers for specific browsers. But now, they provide their respective drivers that support the standard Web driver API interface.

What is the latest Selenium Webdriver architecture?

Below block diagram explains the latest architecture Selenium Webdriver supports.

What are the different components of the Selenium framework?

Selenium is an automation development kit that comprises the following components.

  • Selenium IDE:

A Firefox extension to record and play the user actions performed on a web page.

  • Selenium RC:

A Selenium Remote Control which exposes APIs for scripting tests in different languages and also runs them in browsers.

  • Selenium Webdriver:

These are native APIs that directly interact with the browser. They give more control and faster than the RC APIs.

  • Selenium Grid:

It provides concurrency. With its help, we can split testing and run a set of cases on one machine and some on another.

What are the benefits does WebDriver has over Selenium RC?

Selenium RC had a complex architecture, whereas WebDriver removed those complications. The below points discuss why WebDriver is better than the RC.

  • Selenium RC is slow because it has an additional JavaScript layer known as the core. On the contrary, WebDriver is fast as it natively interacts with the browser by utilizing its built-in engine.
  • Selenium core can’t ignore the disabled elements, whereas WebDriver handles the page elements more realistically.
  • Selenium RC has a mature set of APIs but suffers from redundancies and complicated commands. On the other hand, WebDriver APIs have a cleaner interface and do not have any such problems.
  • Selenium RC doesn’t provide support for the HtmlUnit browser, whereas the WebDriver has a headless HtmlUnit driver.
  • Selenium RC includes a test result generator to produce HTML reports. Web Driver doesn’t have any built-in reporting ability.

What are the benefits of Selenium automation?

There are many benefits of using Selenium for automated testing.

  • Open source: Since it is an OSS, so we don’t have to bear any licensing cost for using it.
  • Cross-browser: It works on all standard browsers such as Chrome, FF, IE, and Safari. We can run same the test script in all browsers.
  • Multi-language: We can choose a familiar programming language from Java, Python, C#, Ruby to use with Selenium.
  • Cross-platform: It provides test compatibility across Windows, Linux, and Mac OSX. We can run same the test script on all platforms.
  • Concurrency: With Selenium Grid, we can execute thousands of tests in parallel.
  • CLI support: We can create a test suite with hundreds of tests and launch it with a single command.
  • CI support: Jenkins is the best CI tool. It provides a Selenium plugin to configure tests for nightly execution.
  • Free help: We can get quick technical support from its large community.
  • Tester friendly: A non-programmer can also automate using Selenium. It is not too complicated to be used only by a programmer.
  • Ongoing project: Active development and bug fixes on the latest project.

What are some downsides to Selenium automation?

Selenium is a perfect clinical tool to impersonate user actions in a browser. However, it also has a few limitations given below.

  • Doesn’t support automation of Windows applications
  • Can’t perform mobile automation on its own
  • Lacks a good built-in reporting
  • Not 100% perfect for handling dynamic web elements
  • Poses challenges while processing popups or frames
  • Not that efficient in coping with the page load
  • Can’t automate a captcha

What programming languages does Selenium allow to use?

Selenium Webdriver supports the following programming languages.

  • Python
  • Java
  • C-Sharp
  • JavaScript
  • Ruby
  • PHP
  • Perl

What are the OS/platforms does Selenium support?

Following is the list of OS/platforms which Selenium supports.

  • Windows Desktop
  • Windows Mobile
  • Linux
  • Mac OS X
  • IOS
  • Android

What types of cases can you automate with Selenium?

We can use Selenium for automating the following types of cases.

  • Functional cases
  • Regression test cases
  • Acceptance tests
  • Sanity test cases
  • Smoke testing
  • End-to-end test cases
  • Cross-browser tests
  • Integration tests
  • Responsiveness cases

Can you use Selenium for testing Rest API or Web services?

Selenium provides Native APIs for interacting with the browser using actions and events. The Rest API and the web services don’t have any UI and hence can’t be automated using Selenium.

What are the different types of Web Driver APIs supported in Selenium?

Following are the web drivers supported in Selenium.

| WebDriver Name | WebDriver API | Supported Browser |

  1. Gecko Driver (a.k.a. Marinetto) | FirefoxDriver() | Firefox
  2. Microsoft WebDriver (a.k.a. Edge) | InternetExplorerDriver() | IE
  3. Google Chrome Driver | ChromeDriver() | Chrome
  4. HTML Unit Driver | WebClient() | {Chrome, FF, IE}
  5. OperaChromium Driver | ChromeDriver() | Opera
  6. Safari Driver | SafariDriver() | Safari
  7. Android Driver, AndroidDriver() | Android browser
  8. ios Driver | IOSDriver() | ios browser
  9. EventFiringWebDriver | EventFiringWebDriver() | ALL

Which of the WebDriver APIs is the fastest, and why?

It is none other than the HTMLUnitDriver, which is faster than all of its counterparts.

The technical reason is that the HTMLUnitDriver doesn’t execute in the browser. It employs a simple HTTP request-response mechanism for test case execution.

This method is far quicker than starting a browser to carry out test execution.

How can you use Selenium RC API along with Selenium 2.0/3.0?

We can still invoke Selenium 1.0 API (RC) from the Selenium 2.0 code. But there might be a few Selenium 1.0 methods missing.

However, we first need to create a Selenium instance from WebDriver and call Selenium functions.

The old methods might slow down the execution due to the API transitioning happening in the background.

What do you know about Selenium IDE?

Selenium IDE is a trendy Firefox browser extension. It presents a graphical interface to record, play, and save user actions. Test automation beginners can find it convenient for web automation testing. After capturing a workflow, we can also export the steps in various formats.

Shinya Kasatani was the developer who created the Selenium IDE. The idea crossed his mind while he was investigating the JavaScript code inside the Selenium core. He then did a proof of concept and developed it into a full-fledged IDE.

What do you know about Selenese?

Selenium IDE has a built-in linguistic system known as Selenese. It is a collection of Selenium commands to perform actions on a web page.

For example, it can detect broken links on a page, check the presence of a web element, Ajax, JavaScript alerts, and a lot more. There are mainly three types of command in Selenese.

  • Actions: It can alter the state of an application. For example, you are clicking on a link, selecting a value from the drop-down, etc.
  • Accessors: These commands monitor the state of an application and cache it into some variable. For example, storeTextPresent, storeElementPresent etc.
  • Assertions: These commands allow adding a checkpoint or a verification point. They confirm the current state of a UI element.

What do you know about Selenium Grid?

Selenium Grid is a tool which can distribute tests across multiple browsers or different machines. It enables parallel execution of the test cases. Using this, we can configure to run thousands of test cases concurrently on separate devices or browsers.

What do you use Selenium Grid?

Selenium Grid allows the test cases to run on multiple platforms and browsers simultaneously, and hence, supports distributed testing.

This ability to parallelize the testing is what makes us use the Selenium Grid.

What are the pros/benefits of using Selenium Grid?

There are a no. of benefits of using the Selenium Grid.

  • Support concurrent test execution and hence saves us a lot of our time.
  • It presents us with the ability to execute test cases in different browsers.
  • After creating multi-machine nodes, we can use it to distribute tests and execute them.

What does a hub do in Selenium Grid?

A hub is analogous to a server that drives the parallel test execution on different machines.

What does a node do in Selenium Grid?

The machine we register to a hub represents a node. The registration allows the grid to fetch node configuration and execute tests. There could be multiple nodes that we can bind to a Selenium Grid.

What is the command to bind a node to Selenium Grid?

Please make sure to download the Selenium-server jar before running the below command.

java –jar <selenium-server-standalone-x.xx.x.jar> –role node –hub http://<node IP>:4444/grid/register

Which of Java, C-Sharp, or Ruby can we use with Selenium Grid?

  • Java: Yes, we can. Moreover, we can do parallel testing using TestNG to utilize the Selenium grid features.
  • C-Sharp: Yes, we can. We need to use “Gallio” to run our tests concurrently in the grid.
  • Ruby: Yes, we can. We’ll use the “DeepTest” to distribute our tests across the grid.

What are Selenium Grid Extras? What additional features does it add to Selenium Grid?

Selenium Grid Extras is a set of management scripts to manage nodes more efficiently.

Below is a summary of the features provided by extras.

  • More control over the individual nodes
    • Kill a browser running tests by name
    • Stop a process or program by its PID
    • Shift the mouse to a specific coordinate
    • Retrieve physical memory (RAM) and persistent storage (Disk) usage statistics
  • Auto upgrade to newer versions of WebDriver
  • Reset/re-start test nodes after a specified no. of iterations
  • Centrally manage the configuration of all nodes
  • Capture screenshots during error conditions

What is the difference between MaxSessions vs. MaxInstances properties of Selenium Grid?

Sometimes we get confused while differentiating between the MaxSessions vs. MaxInstances. Let’s understand the difference with clarity.

  1. MaxInstances: It is the no. of browser instances (of the same versions) that can run on the remote machine. Check the below commands.

-browser browserName=firefox,version=59,maxInstances=3,platform=WINDOWS

-browser browserName=InternetExplorer,version=11,maxInstances=3,platform=WINDOWS

It means we can run three instances of both Firefox and IE at the same time. So, a total of six different browsers (FF & IE) could run in parallel.

  1. MaxSession: It dictates how many browsers (independent of the type & version) can run concurrently on the remote machine. It supersedes the “MaxInstances” setting.
    In the previous example: If the value of “maxSession” is one, then no more than a single browser would run. While its value is two, then any of these combinations (2FF, 2IE, 1FF+1IE) can run at a time.

What are the locators Selenium supports?

Following is the list of supported locators by Selenium.

  • ID: Unique for every web element
  • Name: Same as ID although it is not unique
  • CSS Selector: Works on element tags and attributes
  • XPath: Searches elements in the DOM, Reliable but slow
  • Class name: Uses the class name attribute
  • TagName: Uses HTML tags to locate web elements
  • LinkText: Uses anchor text to locate web elements
  • Partial Link Text: Uses partial link text to find web elements

Which of the id, name, XPath, or CSS selector should you use?

If the page has unique names or identifiers available, then we should use them.

If they are not available, then go for a CSS selector as it is faster than the XPath.

When none of the preferred locators is present, then you may try the XPath.

What is XPath? How does it work?

XPath is the most-used locator strategies Selenium uses to find web elements.

  • It works by navigating through the DOM elements and attributes to locate the target object. For example – a text box or a button or checkboxes.
  • Although it guarantees to give you the element you are looking after. But it is slower than as compared to other locators like ID, name, or CSS selectors.

What does a single slash “/” mean in XPath?

A single (forward) slash “/” represents the absolute path.

In this case, the XPath engine navigates the DOM right from the first node.

What does a double slash “//” mean in XPath?

A double (forward) Slash “//” represents the relative path.

In this case, the XPath engine searches for the matching element anywhere in the DOM.

What is an absolute XPath, explain with example?

An absolute XPath will always search from the root node until it reaches the target. Such an XPath expression includes the single forward-slash (/) as the prefix.

/html/body/div[1]/div[5]/form/table/tbody/tr[3]/td/input

What is a relative XPath, explain with example?

A relative XPath doesn’t have a specific point to start. It can begin navigation from any node inside the DOM and continues. Such an XPath expression includes the double forward-slash (//), as given below.

//input[@id=’username’]

How do you locate an element by partially comparing its attributes in XPath?

XPath supports the contains() method. It allows partially matching of attribute’s value.

It helps when the attributes use dynamic values while having some fixed part.

See the below example-

xPath usage => //*[contains(@category, ‘tablet’)]

The above expression would match all values of the category attribute having the word ‘tablet’ in them.

How do you locate elements based on the text in XPath?

We can call the text() method. The below expression will get elements that have text nodes that equal ‘Python.’

xPath usage = //*[text()=’Python’]

How do you access the parent of a node with XPath?

We can use the double dot (“..”) to point to the parent of any node using the XPath.

For example – The locator //span[@id=”current”]/.. will return the parent of the span element matching id value as ‘current’.

How do you get to the nth sub-element using the XPath?

We can modify the XPath expression to get to the nth element in the following ways:

  1. Use XPath as an array by appending the square brackets with an index.

# Example

tr[2]

The above XPath expression will return the second row of a table.

  1. By calling position() in the XPath expression

# Example

tr[position()=4]

The above XPath will give the fourth row.

How do you use “class” as a CSS selector?

We can use the below syntax to access elements using the class CSS selector.

.<class>

e.g. .color

It can help to select all elements related to the specified class.

How do you use “ID” as a CSS selector?

We can use the below syntax to access elements using ID as the CSS selector.

#<ID>

e.g. #name

How to specify attribute value while using the CSS selector?

Here is the syntax to provide the attribute value with the CSS selector.

[attribute=value]

e.g. [type=submit]

How to access the nth element using the CSS selector?

Here is the syntax to access the nth attribute using the CSS selector.

<type>:nth-child(n)

e.g. tr:nth-child(4)

What is the primary difference between the XPath and CSS selectors?

With the XPath, we can traverse both forward and backward, whereas CSS selector only moves forward.

What are the steps to create a simple Web Driver script?

Below are the minimal steps to create a WebDriver script.

  • Launch the Firefox or Chrome browser by creating the WebDriver object.
  • Open website www.google.co.in using the get() method.
  • Wait for the web page to load.
  • Display a message on the console that the webpage gets loaded successfully.
  • Close the browser.

Source Code:

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class SimpleWebDriverScript {

public static void main(String[] args) {

WebDriver driver = new FirefoxDriver();

String URL = “https://www.google.co.in”;

driver.get(URL);

driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);

System.out.println(“Webpage gets loaded successfully!!”);

driver.close();

}

}

What does FirefoxDriver mean, a Class or an Interface?

FirefoxDriver is a Java class, and it implements the WebDriver interface.

What does the Webdriver driver = new FirefoxDriver(); mean?

Webdriver driver = new FirefoxDriver();

The above line of code represents the following:

  • The driver is a variable of type ‘Webdriver’ interface.
  • We are instantiating an object of the FirefoxDriver class and storing it into the driver variable.

How can I read test data from excels?

Test data can efficiently be read from excel using JXL or POI API.

What is the difference between POI and jxl jar?

# JXL jar POI jar
1 JXL supports “.xls” format i.e. binary based format. JXL doesn’t support Excel 2007 and “.xlsx” format i.e. XML based format POI jar supports all of these formats
2 JXL API was last updated in the year 2009 POI is regularly updated and released
3 The JXL documentation is not as comprehensive as that of POI POI has a well prepared and highly comprehensive documentation
4 JXL API doesn’t support rich text formatting POI API supports rich text formatting
5 JXL API is faster than POI API POI API is slower than JXL API

What is the difference between Selenium and QTP?

Feature Selenium Quick Test Professional (QTP)
Browser Compatibility Selenium supports almost all the popular browsers like Firefox, Chrome, Safari, Internet Explorer, Opera etc QTP supports Internet Explorer, Firefox and Chrome. QTP only supports Windows Operating System
Distribution Selenium is distributed as an open source tool and is freely available QTP is distributed as a licensed tool and is commercialized
Application under Test Selenium supports testing of only web based applications QTP supports testing of both the web based application and windows based application
Object Repository Object Repository needs to be created as a separate entity QTP automatically creates and maintains Object Repository
Language Support Selenium supports multiple programming languages like Java, C#, Ruby, Python, Perl etc QTP supports only VB Script
Vendor Support As Selenium is a free tool, user would not get the vendor’s support in troubleshooting issues Users can easily get the vendor’s support in case of any issue

Can WebDriver test Mobile applications?

WebDriver cannot test Mobile applications. WebDriver is a web-based testing tool, therefore applications on the mobile browsers can be tested.

Can captcha be automated?

No, captcha and barcode reader cannot be automated.

What is Object Repository? How can we create an Object Repository in Selenium?

Object Repository is a term used to refer to the collection of web elements belonging to Application Under Test (AUT) along with their locator values. Thus, whenever the element is required within the script, the locator value can be populated from the Object Repository. Object Repository is used to store locators in a centralized location instead of hardcoding them within the scripts.

In Selenium, objects can be stored in an excel sheet which can be populated inside the script whenever required.

Why do we create a reference variable of type Webdriver, not the actual browser type?

It is because we could use the same Webdriver variable to hold the object of any browser, such as the ChromeDriver, IEDriver, or SafariDriver, etc.

# We follow this approach as it can work with any browser instance.

WebDriver driver = new FirefoxDriver();

# This approach is right too but will work only the Firefox.

FirefoxDriver driver = new FirefoxDriver();

How do you pass credentials to an authentication popup in Selenium?

We combine the username and password strings using the colon separator and stuff them between the “http://” and the site URL. See the below example.

http://userid:passcode@somesite.com

e.g. http://userid:passcode@somesite.com

What are the different exceptions available in Selenium?

Like many programming languages, Selenium also provides exception handling. The standard exceptions in Selenium are as follows.

  • TimeoutException: This occurs if a command doesn’t finish within the specified duration.
  • NoSuchElementException: This occurs if the web element with the specified attributes is not present on the page.
  • ElementNotVisibleException: This occurs if the element is not visible but still there inside the DOM.
  • StaleElementException: This occurs in the absence of an element that either got deleted or detached from the DOM.

What do you know about an exception test in Selenium?

An exception test is a special exception that occurs in a test class.

Suppose, we have created a test case that can throw an exception.

In this case, the @Test annotation can help us specify the exception that could occur.

Check out from the below example.

@Test(actualException = ElementNotVisibleException.class)

 

What is Web Driver Explicit wait?

Explicit Wait: It is an exclusive timeout method that works by adding code to delay the execution until a specific condition arises. It is more customizable in terms that we can set it up to wait for any suitable situation. Usually, we use a few of the pre-built Expected Conditions to wait for elements to become clickable, visible, invisible, etc.

WebDriver driver = new ChromeDriver();

driver.get(“http://target_page_url”);

WebElement dynamicElement = (new WebDriverWait(driver, 15))

.until(ExpectedConditions.presenceOfElementLocated(By.id(“dynamicElement”)));

What is the command to enter text in the HTML text box using Selenium?

We can do so by using the sendKeys() method.

WebDriver webdriver = new FirefoxDriver();

webdriver.get(“https://www.google.com”);

webdriver.findElement(By.xpath(“<<xpath expr>>”)).sendKeys(“Selenium Interview Questions”);

How to enter text in the HTML text box without invoking the sendKeys()?

There is a Selenium JavascriptExecutor class that provides methods to perform actions on the HTML elements.

// Set up the JS object

JavascriptExecutor jscript = (JavascriptExecutor)webdriver;

// Issue command to enter the text

jscript.executeScript(“document.getElementById(‘textbox’).value = ‘Some Text’;”);

What is the method to read the JavaScript variable using Selenium WebDriver?

Again, we can utilize the JavascriptExecutor class to read the value of a JS variable. See the below code.

// Set up the JavaScript object

JavascriptExecutor jscript = (JavascriptExecutor) webdriver;

// Read the site title

String strTitle = (String)jscript.executeScript(“return document.title”);

System.out.println(“Webpage Title: ” + strTitle);

How is an Assert different from Verify?

  • Assert: It allows us to verify the result of an expression or an operation. If the “assert” fails, then it will abort the test execution and continues with the next case.
  • Verify: It also operates the same as the assert does. However, if the “verify” fails, then it won’t abort the test instead continues with the next step.

What difference do you make between Soft vs. Hard Assert in Selenium?

  • Soft Assert: It aggregates the errors that occurred during the test execution. If such an assert fails, the control jumps to the next step.
  • Hard Assert: It immediately responds with an AssertException and breaks the current test. After that, the next case in the sequence gets executed.

What are the different waits available in WebDriver?

In Selenium Webdriver, the following three types of wait mechanisms are available.

  • Implicit Wait
  • Explicit Wait
  • Fluent Wait

.What is Web Driver Implicit wait?

Implicit Wait: It is a wait timeout which applies to a Webdriver instance.  It implies that all actions of this instance will timeout only after waiting for a duration specified by the implicit wait.

WebDriver driver = new ChromeDriver();

driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

What is the command to reset the HTML text box in Selenium Webdriver?

Selenium provides the clear() function to reset the value inside the text element.

WebDriver webdriver = new FirefoxDriver();

webdriver.get(“https://www.google.com”);

webdriver.findElement(By.xpath(“<<xpath expr>>”)).sendKeys(“Selenium Interview Questions”);

webdriver.findElement(By.xpath(“<<xpath expr>>”)).clear();

What is the command to get the value of a text box in Selenium Webdriver?

Selenium provides the getText() function to read the value inside the text element.

package webdriverdemo;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.Test;

public class demoClass {

@Test

public void readText() {

System.setProperty(“webdriver.chrome.driver”, “<<chromedriver.exe>>”);

WebDriver webdriver = new ChromeDriver();

webdriver.get(“https://www.google.com”);

String strText = webdriver.findElement(By.xpath(“<<xpath expr>>”)).getText();

System.out.println(“Text element contains: ” + strText);

}

};

What is the command to get the attribute value in Selenium Webdriver?

Selenium provides the getAttribute(value) function to read the value inside the text element.

String strValue = webdriver.findElement(By.name(“<<attrname>>”)).getAttribute(“value”);

System.out.println(“Attribute value is: ” + strValue);

What is the command to click on a hyperlink in Selenium Webdriver?

Selenium provides the click() function to click on a HTML link.

webdriver.findElement(By.linkText(“Selenium Interview Questions”)).click();

What is the command to submit the HTML form in Selenium Webdriver?

Selenium provides the submit() function to finalize a HTML form.

webdriver.findElement(By.id(“<<htmlform>>”)).submit();

However, we can also achieve the same effect by calling the click() method.

What is the command to press enter inside the HTML text box using Selenium Webdriver?

Selenium provides Enum Key macros to simulate the enter action.

webdriver.findElement(By.xpath(“<<xpath>>”)).sendKeys(Keys.ENTER);

What is the Selenium command to delay test execution for 10 seconds?

In Java, we can use the following method to halt the execution for a specified no. of milliseconds.

java.lang.Thread.sleep(long milliseconds)

To halt for 10 seconds, we can issue the following command:

Thread.sleep(10000)

Is it mandatory to prefix the URL with HTTP or HTTPS while calling the web driver’s get() method?

Yes, if the URL doesn’t contain the HTTP prefix, then the program will throw an exception.

Hence, it is mandatory to pass the HTTP or HTTPS protocol while calling the web driver’s get() method.

What is the other method which gives the same effect as we get from the web driver’s get()?

Selenium provides the “navigate.to(link)” method. It does the same thing as we achieve from the get() call.

What is the principal difference between “GET” and “NAVIGATE” methods?

Get method makes a page to load or extracts its source or parse the full text. On the contrary, the navigate method tracks the history and can perform operations like refresh, back, and forward.

For example – We like to move forward, execute some functionality and then move back to the home page.

We can achieve this by calling the Selenium’s navigate() API.

  • The driver.get() method waits until the page finish loading.
  • The driver.navigate() will only redirect and return immediately.

How can I move back and forth in a browser using Selenium?

Selenium provides the following methods for moving back and forth in a browser.

1) navigate().forward() – to move to the next web page as per the browser’s history
2) navigate().back() – to move back to the previous page as per the browser’s history
3) navigate().refresh() – to reload the current page
4) navigate().to(“URL”) – to start a new browser window and opening up the specified link

What is the Selenium command to fetch the current page URL?

To retrieve the current page URL, we can call the getCurrentURL() function.

webdriver.getCurrentUrl();

What is the Selenium command to set the browser maximized?

We can maximize the browser window by calling Selenium’s maximize() method.

It sets the current window in the maximized state.

webdriver.manage().window().maximize();

What is the Selenium command to delete session cookies?

To delete session cookies, we can invoke the deleteAllCookies() method.

webdriver.manage().deleteAllCookies();

State the difference between Web driver’s getWindowHandle() and getWindowHandles() methods?

webdriver.getWindowHandle() – It gets the handle of the active web page.

webdriver.getWindowHandles() – It gets the list of handles for all the pages opened at a time.

State the difference between Web driver’s close() and quit() methods?

These two methods perform the same task, i.e., the closing of the browser. However, there is a slight difference.

webdriver.close(): It closes the active WebDriver instance.

webdriver.quit(): It closes all the WebDriver instances opened at a time.

State the difference between Web driver’s findElement() and findElements() methods?

Both these methods traverse the DOM looking for the target web element. However, there are some basic differences between them.

  1. The findElement() method returns the first WebElement matching the locator, whereas the findElements() fetches all passing the locator criteria.

// Syntax of findElement()-

WebElement item = webdriver.findElement(By.id(“<<ID value>>”));

// Syntax of findElements()-

List <WebElement> items = webdriver.findElements(By.id(“<<ID value>>”));

  1. Another difference is if no element is matched, then the findElement() raises NoSuchElementException whereas findElements() returns an empty list.

How do you check if an object is present on multiple pages?

We can use the isElementPresent() command to verify the object on all pages.

assertTrue(selenium.isElementPresent(locator));

How do you check for the presence of a web element after the successful page load?

We can verify the presence of a web element with the following code.

While using the below function, do supply some timeout value (in seconds) to check the element in a regular interval.

public void checkIfElementPresent(String element, int timeout) throws Exception {

for (int sec = 0;; sec++) {

if (sec >= timeout)

fail(“Timeout! Couldn’t locate element.” + element);

try {

if (selenium.isElementPresent(element))

break;

} catch (Exception ex) {

}

Thread.sleep(1000);

}

}

How to handle Web-based alerts/pop-ups in Selenium?

WebDriver exposes the following APIs to handle such popups.

  • Dismiss(): It handles the alert by simulating the Cancel button.
  • Accept(): It handles the alert window by simulating the Okay button.
  • GetText(): You may call it to find out the text shown by the alert.
  • SendKeys(): This method simulates keystrokes in the alert window.

How to handle Windows-based alerts/pop-ups in Selenium?

Handling a window-based pop-up is not straight-forward. Selenium only supports web applications and doesn’t provide a way to automate Windows-based applications. However, the following approaches can help.

  1. Use the Robot class (Java-based) utility to simulate the keyboard and mouse actions. That’s how you can handle the window based pop.
  2. The KeyPress and KeyRelease methods simulate the user pressing and releasing a specific key on the keyboard.

How to handle multiple popup windows in Selenium?

Selenium provides the getWindowHandles() method, which returns the handles for all open popups.

We can store them into a <String> variable and convert it into an array.

After that, we can traverse the array and navigate to a specific window by using the below code.

driver.switchTo().window(ArrayIndex);

Alternatively, we can use the Java Iterator class to iterate through the list of handles. Find below is the code to handle multiple windows using Selenium.

String hMyWindow = driver.getWindowHandle();

WebDriver popup = null;

Iterator<String> hWindows = driver.getWindowHandles();

while(hWindows.hasNext()) {

String hWindow = hWindows.next();

popup = driver.switchTo().window(hWindow);

if (popup.getTitle().equals(“HandlingMultipleWindows”) {

break;

}

}

How can you access a Database from Selenium?

Selenium doesn’t have a direct API to access a database. Hence, we can look for its support in the programming language we choose to work with Selenium.

For illustration purposes, we used Java with Selenium.

Java provides the Connection class to initiate a connection with the database. It has a getConnection() method that we need to call. For this, we’ll make a Connection Object. It’ll manage the connection to the database.

Please note: An application could have one or more connections opened to a database or different databases.

Here is a short overview of the steps to be performed.

  • Firstly, we establish a connection with the database.
  • After that, we call the DriverManager.getConnection() method.
  • This method accepts a string pointing to the database URL.
  • The DriverManager class then attempts to find a driver to access the database URL.
  • After it finds a suitable driver, the call to the getConnection() method succeeds.

Syntax:

String url = “jdbc: odbc: makeConnection”;

 

Connection con = DriverManager.getConnection(url, “userID”, “password”);

How to handle AJAX controls using Selenium?

Let’s understand the handling of AJAX with an example.

Consider the Google search text box, which is an Ajax control. Whenever we write some text into the box, it shows up a list of auto-suggested values.

To automate this type of element, we need to grab the above list in a string as soon as the box receives input. After that, we can split and take the values one by one.

How to work with AJAX controls in WebDriver?

AJAX is an acronym for Asynchronous JavaScript and XML. It is independent of the opening and closing tags required for creating valid XML.

Sometimes, the WebDriver itself manages to work with the Ajax controls and actions. However, if it doesn’t succeed, then try out the below code.

//Waiting for Ajax Control

 

WebElement AjaxCtrl = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By. &lt;locatorType&gt;(“&lt;locator Value&gt;”)));

What is a Page Object in Selenium WebDriver?

First of all, both these terms belong to the Page Object Model (POM), a design pattern in Selenium. Let’s now see how are they different from each other.

Page Object is a class in POM corresponding to a web page. It captures the functionality as functions and objects as members.

public class LogInPage

{

private WebElement user;

private WebElement pass;

 

public LogInPage() {

}

 

public void findObjects() {

user = browser.findElement(By.id(“userName”));

pass = browser.findElement(By.id(“password”));

}

 

public void processLogIn() {

user.sendKeys(“john”);

pass.sendKeys(“password”);

}

}

What is a Page Factory in Selenium WebDriver?

Page Factory is a method to set up the web elements within the page object.

public class LogInPage

{

@FindBy(id=”userName”)

private WebElement user;

 

@FindBy(id=”password”)

private WebElement pass;

 

public LogInPage() {

PageFactory.initElements(browser, this); // Setup the members as browser.findElement()

}

 

public void processLogIn() {

user.sendKeys(“john”);

pass.sendKeys(“password”);

}

}

What are User Extensions, and how do you create them?

User extensions are a set of functions written in JavaScript. They are present in a separate known as the extension file. Selenium IDE or Selenium RC access it to activate the extensions.

Selenium’s core has a JavaScript codebase. So, we can also use it to create the extension.

The extension has a specific format, as given below.

// sample

Selenium.prototype.doFunctionName = function(){

 

}

The function name begins with a “do” prefix. It signals Selenium to interpret this function as a command.

It means we can call the above function inside any of our steps.

What is the right way to capture a screenshot in Selenium?

Sometimes, an image than a trace log can help us identify the right reason for an error. The code in the below example will capture the image and store it in a file.

Import org.apache.commons.io.FileUtils;

WebDriver ins = new ChromeDriver();

ins.get(“http://www.google.com/”);

 

File screen = ((TakesScreenshot)ins).getScreenshotAs(OutputType.FILE);

// Now you can do whatever you need to do with it, for example copy somewhere

 

FileUtils.copyFile(screen, new File(“c:\tmp\myscreen.png”));

How to simulate Mouse over action on a submenu option under a header menu?

Using the Actions object, you can first move the menu title, and then proceed to the popup menu item and click it. Don’t at all miss to invoke the “actions.Perform()” at the end. Check out the below Java code:

Actions acts = new Actions(driver);

WebElement menuHoverLink = driver.findElement(By.linkText(“Menu heading”));

acts.moveToElement(menuHoverLink);

WebElement subLink = driver.findElement(By.cssSelector(“#headerMenu .subLink”));

acts.moveToElement(subLink);

acts.click();

acts.perform();

How to resolve the SSL certificate issue (secured connection error) in Firefox with WebDriver?

There can be many reasons for the secured connection error. It could be because of the following:

  • While a site is getting developed, it may not have the right SSL certificate.
  • The site may be using a self-signed certificate.
  • The SSL may not have configured appropriately at the server end.

However, you still want to test the site’s standard functionality using Selenium. Then, the idea is to switch off the SSL setting and ignore the SSL error.

Check out the below code to disable the SSL in Selenium.

FirefoxProfile ssl = new FirefoxProfile();

 

ssl.setAcceptUntrustedCertificates(true);

 

ssl.setAssumeUntrustedCertificateIssuer(false);

 

WebDriver ins = new FirefoxDriver(ssl);How to resolve the SSL certificate issue in IE?

In the internet explorer, it is somewhat trivial to ignore the SSL error. Please add the below line of code and safely skip the SSL issue.

// Copy the below code after opening the browser.

 

driver.navigate().to(“javascript:document.getElementById(‘overridelink’).click()”);

How to handle a proxy using Selenium in Java?

Selenium implements a PROXY class to configure the proxy. See below example:

String setPROXY = “10.0.0.10:8080”;

 

org.openqa.selenium.Proxy allowProxy = new.org.openqa.selenium.Proxy();

allowProxy.setHTTPProxy(setPROXY)

.setFtpProxy(setPROXY)

.setSslProxy(setPROXY);

DesiredCapabilities allowCap = new DesiredCapabilities();

allowCap.setCapability(CapabilityType.PROXY, allowProxy);

WebDriver driver = new FirefoxDriver(allowCap);

How to handle a proxy using Selenium in Python?

from selenium import webdriver

 

PROXY = “10.0.0.10:8080” # IP:PORT or HOST:PORT

 

chrome_opt = webdriver.ChromeOptions()

chrome_opt.add_argument(‘–proxy-server=%s’ % PROXY)

 

chrome = webdriver.Chrome(options=chrome_opt)

chrome.get(“<< target URL >>”)

What are TestNG annotations frequently used with Selenium?

TestNG annotations prioritize the calling of a test method over others. Here are the ones to use with Selenium:

  • @BeforeSuite – to run before all tests.
  • @AfterSuite – to run only once after all tests.
  • @BeforeClass – to run only once before the first test method.
  • @AfterClass – to run only once after all the test methods of the current class finish execution.
  • @BeforeTest – to run before any test method inside the “Test” tag.
  • @AfterTest – to run after any test method inside the “Test” tag.

What do you know about TestNG @Parameters?

In TestNG, the “@Parameters” is a keyword that allows the arguments to pass to “@Test” methods.

What is Data Provider in TestNG?

The data provider is a TestNG annotation. It allows you to pass parameters like a property file or a database to a test method.

What is meant by grouping in TestNG?

It is an innovative TestNG feature that didn’t exist in the JUnit. You can assign methods with proper context and refine groupings of test methods.

You can not only link methods to groups but also tell groups to include other groups.

How to associate a single test to multiple groups in TestNG?

TestNG framework allows multiple tests to run by using the test group feature.

We can associate a single test to multiple groups, as shown in the below example.

@Test(groups = {“regression-testing”, “smoke-testing”})

Is TestNG capable of running multiple suites?

Yes, we can run multiple testNG suites in the following manner:

<suite name=”SuperSuite”>

<suite-files>

<suite-file path=”subSuite1.xml” />

<suite-file path=”subSuite2.xml” />

</suite-files>

</suite>

We can also run various suites in parallel by using an Ant task.

What is a Framework? What are the different types of frameworks available?

A framework is a charter of rules and best practices to solve a problem systematically. There are various types of automation frameworks.

Some of the most common ones are as follows:

  • Data-Driven Testing Framework
  • Keyword Driven Testing Framework
  • Hybrid Testing Framework
  • Behavioural Driven Framework

What are the Open-source frameworks (OSF) does Selenium support?

Selenium can integrate with the following Open Source frameworks.

  • JUnit
  • TestNG
  • Maven
  • FitNesse
  • Xebium

What is the principal difference between a Data-driven framework & a Keyword Driven framework?

Data-driven framework (DDF)

  • In a Data-driven framework, the test case logic is the part of test scripts.
  • It advises keeping the input data separate.
  • Usually, the test cases receive the data from the external files (XLS or CSV) and store them into variables. Later during execution, the variables serve as input as well as verification points.

Keyword-driven framework (KDF)

  • In KDF, there happens to be a table of keywords. Every keyword either maps to an action or an object.
  • The actions reflect the product functionality, and the objects represent its resources such as web elements, command or the DB URL, etc.
  • They remain detached from the test automation suite. Hence, the creation of the tests can continue with or without the AUT (application under test).
  • The keyword-driven tests cover the full functionality of the application under test.

What is the difference between hybrid and data-driven framework?

A hybrid framework is a combination of both data-driven and keyword-driven Selenium frameworks.

A data-driven framework works on the concept of separating data from the tests. It solely depends on the test input data.

What are the two most common practices for automation testing?

The two most frequently used practices for automation are as follows:

  • Test-Driven Development (TDD) introduced in 2003
  • Behavior Driven Development (BDD) got first heard in 2009

What is Test-Driven Development (TDD) framework?

TDD a.k.a. test-driven design is a software development paradigm that proposes to conduct unit testing frequently on the source code. It recommends to write tests, monitor, and refactor the code on failure.

The concept of TDD came to light while a few XP (Extreme Programming) developers conceived it.

It intends to prepare tests to check if the code breaks or not. After each test case failure, the developer should fix and re-run the test to verify the same. This process should repeat until all units function as per the design.

What is Behavior Driven Development (BDD) framework?

BDD follows most of the principles of TDD but replaces its unit-centric approach with a domain-centric design.

It intends to bring in inputs not only from the Dev or QA but an array of stakeholders such as Product Owners, Technical Support, Managers, and Customers.

The goal is to identify and automate appropriate tests that reflect the behavior sought by the principal stakeholders.

What are the main traits of a Software test automation framework?

A test automation framework should have the following features.

  • Flexible in the programming language selection
  • Support of keywords and actions
  • Provision of data sources for input
  • Allow test case creation and modification
  • Define test case priority
  • Manual or automated execution
  • Maintain test results history
  • Generate test metrics such as test vs. code coverage
  • Report creation
  • CI tool integration such as Jenkins
  • Cross-browser and cross-platform support

What type of test framework did you create using Selenium?

While replying to such questions, stay focused, and keep your answer short and crisp. You can start by telling about the different components in your framework and then explain them one by one.

Here is an illustration for your help.

  • I worked on a framework built on top of the Page Factory framework.
  • I’ve created a page class for every web page in my application. It keeps the objects and the handler functions.
  • Every page class has a followup test class where I create tests for related use cases.
  • I used separate packages to host the pages and their test classes. It’s a best practice to do that way.
  • The framework also had a lib package for utility and some standard wrapper functions over Selenium APIs.
  • Java is ca ore programming language used for this project. It was primarily because the team had previous Java experience. Also, we could utilize the TestNG annotations and report features.
  • Most test cases are data-driven. They require input from the external data source. So, I used Java property/POI class to read from the CSV/XLS files.
  • We used the TestNG group feature for labeling test cases as P1, P2, and P3.
  • The Log4J library provided the necessary support for tracing in our project.
  • Instead of using the TestNG reporting, we preferred the Extent report. It has more graphical options and gives an in-depth analysis of the results.
  • We built the framework with the help of Maven. Also, Jenkins provided support for automated build and execution.
  • Bitbucket allowed us to manage our source code using git repositories.

.What are challenges have you faced with Selenium? And how did you overcome them?

Here are some of the problems that testers usually face while doing automation with Selenium.

  • Wrong implementation: I used the page object model but had it implemented incorrectly. My classes were focussing on the web elements rather than they should have resembled the user actions.
  • Duplicate code: The project had many category pages. Each category had a different search function instead of handling them at a central place.
  • Ineffective use of wait: I used implicit wait with a fixed timeout. But some pages were timing out due to higher load time. I had to adopt the Fluent wait (with a variable timeout) to overcome this problem.
  • Improper error handling: It was getting hard to debug the cause of a failed test. At some places, the {try-catch} blocks were missing, and hence, cases were skipping w/o giving a proper reason. Therefore, I had to refactor the code by adding asserts and exception handling.
  • Inconsistent XPath: Most of the locators were using the XPath method. And the developers kept them changed while fixing new defects. I called up a discussion with them and agreed to have a fixed XPath or an ID for the web elements.
  • Performance & Localization: We were using the flat files (CSV) initially to feed data to test cases. However, it had us failed in testing localization as well as beaten us on the performance. Ee migrated all of our test data to MySQL and fixed both issues.
  • Monolithic tests: Earlier tests weren’t using the labeling. Honestly, there wasn’t a way to do it. Hence, we integrated our test suite with TestNG and got away with this limitation. Now, we have many test groups like features-based (F1, F2, F3…), priority-based (P1, P2, P3).

What benefits does TestNG have over the JUnit framework?

TestNG vs. JUnit – The Benefits

  1. In JUnit, we start by declaring the @BeforeClass and @AfterClass. However, there isn’t such a constraint in TestNG.
  2. TestNG allows adding setUp/tearDown routines, which JUnit doesn’t.
    -@BeforeSuite & AfterSuite, @BeforeTest & AfterTest, @BeforeGroup & AfterGroup
  3. TestNG doesn’t enforce a class to extend.
  4. Method names aren’t mandatory in TestNG, which are in JUnit.
  5. We can make a case depend on another in TestNG, whereas in JUnit, it’s not possible.
  6. TestNG allows grouping of tests, whereas JUnit doesn’t. Executing a group will run all tests under it. For example, if we have a no. of cases distributed in two groups, namely the Sanity and Regression. If the requirement is to run the “Sanity” tests, then we can configure TestNG to execute the tests under the “Sanity” group. TestNG will execute all cases associated with the “Sanity” group.
  7. The parallelization of test cases is another crucial feature of TestNG.

Which is the super interface of Selenium Web Driver?

Th SearchContext acts as the super interface for the Web Driver.

It is the external interface which has only two methods: findElement() and findElements()

What are the benefits of Automation Testing?

Benefits of Automation testing are:

  1. Supports execution of repeated test cases
  2. Aids in testing a large test matrix
  3. Enables parallel execution
  4. Encourages unattended execution
  5. Improves accuracy thereby reducing human-generated errors
  6. Saves time and money

Why should Selenium be selected as a test tool?

Selenium

  1. is a free and open source
  2. have a large user base and helping communities
  3. have cross Browser compatibility (Firefox, Chrome, Internet Explorer, Safari etc.)
  4. have great platform compatibility (Windows, Mac OS, Linux etc.)
  5. supports multiple programming languages (Java, C#, Ruby, Python, Pearl etc.)
  6. has fresh and regular repository developments
  7. supports distributed testing

What is Selenium? What are the different Selenium components?

Selenium is one of the most popular automated testing suites. Selenium is designed in a way to support and encourage automation testing of functional aspects of web-based applications and a wide range of browsers and platforms. Due to its existence in the open source community, it has become one of the most accepted tools amongst the testing professionals.

Selenium is not just a single tool or a utility, rather a package of several testing tools and for the same reason, it is referred to as a Suite. Each of these tools is designed to cater different testing and test environment requirements.

The suite package constitutes the following sets of tools:

  • Selenium Integrated Development Environment (IDE) – Selenium IDE is a record and playback tool. It is distributed as a Firefox Plugin.
  • Selenium Remote Control (RC) – Selenium RC is a server that allows a user to create test scripts in the desired programming language. It also allows executing test scripts within the large spectrum of browsers.
  • Selenium WebDriver – WebDriver is a different tool altogether that has various advantages over Selenium RC. WebDriver directly communicates with the web browser and uses its native compatibility to automate.
  • Selenium Grid – Selenium Grid is used to distribute your test execution on multiple platforms and environments concurrently.

What are the testing types that can be supported by Selenium?

Selenium supports the following types of testing:

  1. Functional Testing
  2. Regression Testing

What are the limitations of Selenium?

Following are the limitations of Selenium:

  • Selenium supports testing of only web-based applications
  • Mobile applications cannot be tested using Selenium
  • Captcha and Barcode readers cannot be tested using Selenium
  • Reports can only be generated using third-party tools like TestNG or JUnit.
  • As Selenium is a free tool, thus there is no ready vendor support through the user can find numerous helping communities.
  • The user is expected to possess prior programming language knowledge.

What is the difference between Selenium IDE, Selenium RC, and WebDriver?

Feature Selenium IDE Selenium RC WebDriver
Browser Compatibility Selenium IDE comes as a Firefox plugin, thus it supports only Firefox Selenium RC supports a varied range of versions of Mozilla Firefox, Google Chrome, Internet Explorer and Opera. WebDriver supports a varied range of versions of Mozilla Firefox, Google Chrome, Internet Explorer and Opera.
Also supports HtmlUnitDriver which is a GUI less or headless browser.
Record and Playback Selenium IDE supports record and playback feature Selenium RC doesn’t supports record and playback feature. WebDriver doesn’t support record and playback feature
Server Requirement Selenium IDE doesn’t require any server to be started before executing the test scripts Selenium RC requires server to be started before executing the test scripts. WebDriver doesn’t require any server to be started before executing the test scripts
Architecture Selenium IDE is a Javascript based framework Selenium RC is a JavaScript based Framework. WebDriver uses the browser’s native compatibility to automation
Object Oriented Selenium IDE is not an object oriented tool Selenium RC is semi object oriented tool. WebDriver is a purely object oriented tool
Dynamic Finders
(for locating web elements on a webpage)
Selenium IDE doesn’t support dynamic finders Selenium RC doesn’t support dynamic finders. WebDriver supports dynamic finders
Handling Alerts, Navigations, Dropdowns Selenium IDE doesn’t explicitly provides aids to handle alerts, navigations, dropdowns Selenium RC doesn’t explicitly provides aids to handle alerts, navigations, dropdowns. WebDriver offers a wide range of utilities and classes that helps in handling alerts, navigations, and dropdowns efficiently and effectively.
WAP (iPhone/Android) Testing Selenium IDE doesn’t support testing of iPhone/Andriod applications Selenium RC doesn’t support testing of iPhone/Android applications. WebDriver is designed in a way to efficiently support testing of iPhone/Android applications. The tool comes with a large range of drivers for WAP based testing.
For example, AndroidDriver, iPhoneDriver
Listener Support Selenium IDE doesn’t support listeners Selenium RC doesn’t support listeners. WebDriver supports the implementation of Listeners
Speed Selenium IDE is fast as it is plugged in with the web-browser that launches the test. Thus, the IDE and browser communicates directly Selenium RC is slower than WebDriver as it doesn’t communicates directly with the browser; rather it sends selenese commands over to Selenium Core which in turn communicates with the browser. WebDriver communicates directly with the web browsers. Thus making it much faster.

When should I use Selenium IDE?

Selenium IDE is the simplest and easiest of all the tools within the Selenium Package. Its record and playback feature makes it exceptionally easy to learn with minimal acquaintances to any programming language. Selenium IDE is an ideal tool for a naïve user.

What is Selenese?

Selenese is the language which is used to write test scripts in Selenium IDE.

What are the different types of locators in Selenium?

The locator can be termed as an address that identifies a web element uniquely within the webpage. Thus, to identify web elements accurately and precisely we have different types of locators in Selenium:

  • ID
  • ClassName
  • Name
  • TagName
  • LinkText
  • PartialLinkText
  • Xpath
  • CSS Selector
  • DOM

What is the difference between assert and verify commands?

Assert: Assert command checks whether the given condition is true or false. Let’s say we assert whether the given element is present on the web page or not. If the condition is true then the program control will execute the next test step but if the condition is false, the execution would stop and no further test would be executed.

Verify: Verify command also checks whether the given condition is true or false. Irrespective of the condition being true or false, the program execution doesn’t halt i.e. any failure during verification would not stop the execution and all the test steps would be executed.

. What is an XPath?

XPath is used to locate a web element based on its XML path. XML stands for Extensible Markup Language and is used to store, organize and transport arbitrary data. It stores data in a key-value pair which is very much similar to HTML tags. Both being markup languages and since they fall under the same umbrella, XPath can be used to locate HTML elements.

The fundamental behind locating elements using XPath is the traversing between various elements across the entire page and thus enabling a user to find an element with the reference of another element.

What is the difference between “/” and “//” in Xpath?

Single Slash “/” – Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the document node/start node.

Double Slash “//” – Double slash is used to create Xpath with relative path i.e. the xpath would be created to start selection from anywhere within the document.

What is Same origin policy and how it can be handled?

The problem of same origin policy disallows to access the DOM of a document from an origin that is different from the origin we are trying to access the document.

Origin is a sequential combination of scheme, host, and port of the URL. For example, for a URL https://www.softwaretestinghelp.com/resources/, the origin is a combination of http, softwaretestinghelp.com, 80 correspondingly.

Thus the Selenium Core (JavaScript Program) cannot access the elements from an origin that is different from where it was launched. For Example, if I have launched the JavaScript Program from “https://www.softwaretestinghelp.com”, then I would be able to access the pages within the same domain such as “https://www.softwaretestinghelp.com/resources” or “https://www.softwaretestinghelp.com/istqb-free-updates/”. The other domains like google.com, seleniumhq.org would no more be accessible.

So, In order to handle the same origin policy, Selenium Remote Control was introduced.

When should I use Selenium Grid?

Selenium Grid can be used to execute same or different test scripts on multiple platforms and browsers concurrently so as to achieve distributed test execution, testing under different environments and saving execution time remarkably.

. What do we mean by Selenium 1 and Selenium 2?

Selenium RC and WebDriver, in a combination, are popularly known as Selenium 2. Selenium RC alone is also referred to as Selenium 1.

Which is the latest Selenium tool?

WebDriver

How do I launch the browser using WebDriver?

The following syntax can be used to launch Browser:
WebDriver driver = new FirefoxDriver();
WebDriver driver = new ChromeDriver();
WebDriver driver = new InternetExplorerDriver();

What are the different types of Drivers available in WebDriver?

The different drivers available in WebDriver are:

  • FirefoxDriver
  • InternetExplorerDriver
  • ChromeDriver
  • SafariDriver
  • OperaDriver
  • AndroidDriver
  • IPhoneDriver

What are the different types of waits available in WebDriver?

There are two types of waits available in WebDriver:

  1. Implicit Wait
  2. Explicit Wait

Implicit Wait: Implicit waits are used to provide a default waiting time (say 30 seconds) between each consecutive test step/command across the entire test script. Thus, the subsequent test step would only execute when the 30 seconds have elapsed after executing the previous test step/command.

Explicit Wait: Explicit waits are used to halt the execution till the time a particular condition is met or the maximum time has elapsed. Unlike Implicit waits, explicit waits are applied for a particular instance only.

How to type in a textbox using Selenium?

The user can use sendKeys(“String to be entered”) to enter the string in the textbox.

Syntax:
WebElement username = drv.findElement(By.id(“Email”));
// entering username
username.sendKeys(“sth”);

How can you find if an element in displayed on the screen?

WebDriver facilitates the user with the following methods to check the visibility of the web elements. These web elements can be buttons, drop boxes, checkboxes, radio buttons, labels etc.

  1. isDisplayed()
  2. isSelected()
  3. isEnabled()

Syntax:

isDisplayed():
boolean buttonPresence = driver.findElement(By.id(“gbqfba”)).isDisplayed();

isSelected():
boolean buttonSelected = driver.findElement(By.id(“gbqfba”)).isSelected();

isEnabled():
boolean searchIconEnabled = driver.findElement(By.id(“gbqfb”)).isEnabled();

How can we get a text of a web element?

Get command is used to retrieve the inner text of the specified web element. The command doesn’t require any parameter but returns a string value. It is also one of the extensively used commands for verification of messages, labels, errors etc displayed on the web pages.

Syntax:
String Text = driver.findElement(By.id(“Text”)).getText();

How to select value in a dropdown?

The value in the dropdown can be selected using WebDriver’s Select class.

Syntax:

selectByValue:
Select selectByValue = new Select(driver.findElement(By.id(“SelectID_One”)));
selectByValue.selectByValue(“greenvalue”);

selectByVisibleText:
Select selectByVisibleText = new Select (driver.findElement(By.id(“SelectID_Two”)));
selectByVisibleText.selectByVisibleText(“Lime”);

selectByIndex:
Select selectByIndex = new Select(driver.findElement(By.id(“SelectID_Three”)));
selectByIndex.selectByIndex(2);

What are the different types of navigation commands?

Following are the navigation commands:
navigate().back() – The above command requires no parameters and takes back the user to the previous webpage in the web browser’s history.

Sample code:
driver.navigate().back();

navigate().forward() – This command lets the user to navigate to the next web page with reference to the browser’s history.

Sample code:
driver.navigate().forward();

navigate().refresh() – This command lets the user to refresh the current web page there by reloading all the web elements.

Sample code:
driver.navigate().refresh();

navigate().to() – This command lets the user to launch a new web browser window and navigate to the specified URL.

Sample code:
driver.navigate().to(“https://google.com”);

How to click on a hyper link using linkText?

driver.findElement(By.linkText(“Google”)).click();

The command finds the element using link text and then click on that element and thus the user would be re-directed to the corresponding page.

The above-mentioned link can also be accessed by using the following command.

driver.findElement(By.partialLinkText(“Goo”)).click();

The above command finds the element based on the substring of the link provided in the parenthesis and thus partialLinkText() finds the web element with the specified substring and then clicks on it.

How to handle frame in WebDriver?

An inline frame acronym as iframe is used to insert another document within the current HTML document or simply a web page into a web page by enabling nesting.

Select iframe by id
driver.switchTo().frame(“ID of the frame“);

Locating iframe using tagName
driver.switchTo().frame(driver.findElements(By.tagName(“iframe”).get(0));

Locating iframe using index

frame(index)
driver.switchTo().frame(0);

frame(Name of Frame)
driver.switchTo().frame(“name of the frame”);

frame(WebElement element)
Select Parent Window
driver.switchTo().defaultContent();

When do we use findElement() and findElements()?

findElement(): findElement() is used to find the first element in the current web page matching to the specified locator value. Take a note that only first matching element would be fetched.

Syntax:

WebElement element = driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));
findElements(): findElements() is used to find all the elements in the current web page matching to the specified locator value. Take a note that all the matching elements would be fetched and stored in the list of WebElements.

Syntax:
List <WebElement> elementList = driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));

How to find more than one web element in the list?

At times, we may come across elements of the same type like multiple hyperlinks, images etc arranged in an ordered or unordered list. Thus, it makes absolute sense to deal with such elements by a single piece of code and this can be done using WebElement List.

Sample Code

// Storing the list

List <WebElement> elementList = driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));

// Fetching the size of the list

int listSize = elementList.size();

for (int i=0; i<listSize; i++)

{

// Clicking on each service provider link

serviceProviderLinks.get(i).click();

// Navigating back to the previous page that stores link to service providers

driver.navigate().back();

}

What is the difference between driver.close() and driver.quit command?

close(): WebDriver’s close() method closes the web browser window that the user is currently working on or we can also say the window that is being currently accessed by the WebDriver. The command neither requires any parameter nor does it return any value.

quit(): Unlike close() method, quit() method closes down all the windows that the program has opened. Same as close() method, the command neither requires any parameter nor does is return any value.

Can Selenium handle windows-based pop up?

Selenium is an automation testing tool which supports only web application testing. Therefore, windows pop up cannot be handled using Selenium.

How can we handle web-based pop-up?

WebDriver offers the users a very efficient way to handle these pop-ups using Alert interface. There are the four methods that we would be using along with the Alert interface.

  • void dismiss() – The dismiss() method clicks on the “Cancel” button as soon as the pop-up window appears.
  • void accept() – The accept() method clicks on the “Ok” button as soon as the pop-up window appears.
  • String getText() – The getText() method returns the text displayed on the alert box.
  • void sendKeys(String stringToSend) – The sendKeys() method enters the specified string pattern into the alert box.

Syntax:
// accepting javascript alert
                Alert alert = driver.switchTo().alert();
alert.accept();

How can we handle windows based pop up?

Selenium is an automation testing tool which supports only web application testing, that means, it doesn’t support testing of windows based applications. However Selenium alone can’t help the situation but along with some third-party intervention, this problem can be overcome. There are several third-party tools available for handling window based pop-ups along with the selenium like AutoIT, Robot class etc.

How to assert the title of the web page?

//verify the title of the web page
assertTrue(“The title of the window is incorrect.”,driver.getTitle().equals(“Title of the page”));

How to mouse hover on a web element using WebDriver?

WebDriver offers a wide range of interaction utilities that the user can exploit to automate mouse and keyboard events. Action Interface is one such utility which simulates the single user interactions.

Thus, In the following scenario, we have used Action Interface to mouse hover on a drop down which then opens a list of options.

Sample Code:

// Instantiating Action Interface

Actions actions=new Actions(driver);

// howering on the dropdown

actions.moveToElement(driver.findElement(By.id(“id of the dropdown”))).perform();

// Clicking on one of the items in the list options

WebElement subLinkOption=driver.findElement(By.id(“id of the sub link”));

subLinkOption.click();

How to retrieve CSS properties of an element?

The values of the css properties can be retrieved using a get() method:

Syntax:
driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”);
driver.findElement(By.id(“id“)).getCssValue(“font-size”);

How to capture screenshot in WebDriver?

import org.junit.After;

import org.junit.Before;

import org.junit.Test;

import java.io.File;

import java.io.IOException;

import org.apache.commons.io.FileUtils;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

 

public class CaptureScreenshot {

WebDriver driver;

@Before

public void setUp() throws Exception {

driver = new FirefoxDriver();

driver.get(“https://google.com”);

}

@After

public void tearDown() throws Exception {

driver.quit();

}

 

@Test

public void test() throws IOException {

// Code to capture the screenshot

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

// Code to copy the screenshot in the desired location

FileUtils.copyFile(scrFile, new File(“C:\\CaptureScreenshot\\google.jpg”))

}

}

What is Junit?

Junit is a unit testing framework introduced by Apache. Junit is based on Java.

What are Junit annotations?

Following are the JUnit Annotations:

  • @Test: Annotation lets the system know that the method annotated as @Test is a test method. There can be multiple test methods in a single test script.
  • @Before: Method annotated as @Before lets the system know that this method shall be executed every time before each of the test methods.
  • @After: Method annotated as @After lets the system know that this method shall be executed every time after each of the test method.
  • @BeforeClass: Method annotated as @BeforeClass lets the system know that this method shall be executed once before any of the test methods.
  • @AfterClass: Method annotated as @AfterClass lets the system know that this method shall be executed once after any of the test methods.
  • @Ignore: Method annotated as @Ignore lets the system know that this method shall not be executed.

What is TestNG and how is it better than Junit?

TestNG is an advanced framework designed in a way to leverage the benefits by both the developers and testers. With the commencement of the frameworks, JUnit gained enormous popularity across the Java applications, Java developers and Java testers with remarkably increasing the code quality. Despite being easy to use and straightforward, JUnit has its own limitations which give rise to the need of bringing TestNG into the picture. TestNG is an open source framework which is distributed under the Apache Software License and is readily available for download.

TestNG with WebDriver provides an efficient and effective test result format that can, in turn, be shared with the stakeholders to have a glimpse on the product’s/application’s health thereby eliminating the drawback of WebDriver’s incapability to generate test reports. TestNG has an inbuilt exception handling mechanism which lets the program to run without terminating unexpectedly.

There are various advantages that make TestNG superior to JUnit. Some of them are:

  • Added advance and easy annotations
  • Execution patterns can set
  • Concurrent execution of test scripts
  • Test case dependencies can be set

How to set test case priority in TestNG?

Setting Priority in TestNG

Code Snippet

package TestNG;

import org.testng.annotations.*;

public class SettingPriority {

@Test(priority=0)

public void method1() {

}

@Test(priority=1)

public void method2() {

}

@Test(priority=2)

public void method3() {

}

}

Test Execution Sequence:

  1. Method1
  2. Method2
  3. Method3

What is a framework?

The framework is a constructive blend of various guidelines, coding standards, concepts, processes, practices, project hierarchies, modularity, reporting mechanism, test data injections etc. to pillar automation testing.

What are the advantages of the Automation framework?

The advantage of Test Automation framework

  • Reusability of code
  • Maximum coverage
  • Recovery scenario
  • Low-cost maintenance
  • Minimal manual intervention
  • Easy Reporting

What are the different types of frameworks?

Below are the different types of frameworks:

  1. Module Based Testing Framework: The framework divides the entire “Application Under Test” into the number of logical and isolated modules. For each module, we create a separate and independent test script. Thus, when these test scripts have taken together builds a larger test script representing more than one module.
  2. Library Architecture Testing Framework: The basic fundamental behind the framework is to determine the common steps and group them into functions under a library and call those functions in the test scripts whenever required.
  3. Data Driven Testing Framework: Data Driven Testing Framework helps the user segregate the test script logic and the test data from each other. It lets the user store the test data into an external database. The data is conventionally stored in “Key-Value” pairs. Thus, the key can be used to access and populate the data within the test scripts.
  4. Keyword Driven Testing Framework: The Keyword Driven testing framework is an extension to Data-driven Testing Framework in a sense that it not only segregates the test data from the scripts, it also keeps the certain set of code belonging to the test script into an external data file.
  5. Hybrid Testing Framework: Hybrid Testing Framework is a combination of more than one above mentioned frameworks. The best thing about such a setup is that it leverages the benefits of all kinds of associated frameworks.
  6. Behavior Driven Development Framework: Behavior Driven Development framework allows automation of functional validations in an easily readable and understandable format to Business Analysts, Developers, Testers, etc.

So, this brings us to the end of the Selenium Testing Interview Questions blog.This Tecklearn ‘Top Selenium Testing Interview Questions and Answers’ helps you with commonly asked questions if you are looking out for a job in Selenium Testing or Automation Testing Domain. If you wish to learn Selenium Testing and build a career in Automation Testing domain, then check out our interactive, Selenium Certification Training, that comes with 24*7 support to guide you throughout your learning period.

Table of Contents

https://www.tecklearn.com/course/selenium-training-certification/

 Selenium Certification Training

About the Course

Tecklearn’s Selenium Certification Training enables you to master the complete Selenium suite. The Selenium Training is designed to train developers and manual testers to learn how to automate web applications with a robust framework, and integrate it within the DevOps processes of an organization. This Selenium Certification Training will also help you master important concepts such as TestNG, Selenium IDE, Selenium Grid, Selenium WebDriver, etc. Get hands-on experience on widely used automation frameworks such as Data-Driven Framework, Keyword-Driven Framework, Hybrid Framework, and Behavior Driven Development (BDD) Framework. Throughout this online Instructor-led Selenium Certification Training, you will be working on real-life industry use cases.

Why Should you take Selenium Certification Training?

  • The average salary of a Selenium Test Automation Engineer is $94k per year – Indeed.com.
  • Automation Testing Market is expected to grow at a Compound Annual Growth Rate (CAGR) of 18.0% in the next three years.
  • Global software testing market to reach $50 billion by 2020 – NASSCOM. Selenium tool supports more browsers and languages than any other testing tool.

What you will Learn in this Course?

Getting started with Selenium

  • Introduction to Selenium testing
  • Significance of automation testing
  • Comparison of Manual and Automation Testing
  • Installation of Java JDK, JRE and Eclipse

Setting the environment in Eclipse for Selenium

  • Java Introduction
  • Creating a Java function and executing
  • Concepts of Java
  • Properties File
  • Reading Data from Excel File
  • Database Connection
  • Hands On

Advantages of Selenium automation testing

  • Selenium Features
  • Concept of Selenium Integrated Development Environment
  • Understanding of the Selenium IDE features
  • Addition of Script assertions and general commands
  • Deploying the first Selenium Script
  • Sample project IDE
  • Recording Selenium test case
  • Hands On

Selenium Web driver Automation

  • Architecture of Selenium Web Driver
  • Download and installation
  • Creating a Java function using Selenium and execution
  • Hands On

Deploying Web Drivers for scripting

  • Getting the HTML source of Web Element
  • Table and Form Elements
  • Firebug extension and Fire Path installation
  • Advance User Interactions and Cross Browser Testing
  • Hands On

Deep dive into Selenium Web Driver

  • Action Commands
  • Web Table / Date Picker
  • How to Implement Switching Commands in WebDriver
  • Alerts
  • Frames
  • Hands On

Switching Operations in WebDriver using Window

  • Selenium Webdriver Wait
  • Implicit wait, Explicit wait
  • Deploying searching elements using the link text, name, using XPath
  • Calendar
  • Hands On

Introduction to TestNG Framework

  • Introduction to TestNG
  • Advantages of TestNG
  • Installing TestNG on Eclipse
  • Rules to write TestNG
  • TestNG Features
  • Annotations
  • Grouping
  • Sequencing: Prioritization and Dependency
  • Enable/Disable a test case
  • Parameterization: Using Xml file and DataProvider
  • Parallel Testing & Cross Browser Testing
  • TestNG Report: HTML Report, Console Report, XML Report

JUnit Operations and Test Framework

  • Annotations, Methods in JUnit
  • Junit Test Suites, ANT Build and JUNIT reporting
  • Types of Test Automation Framework
  • Module Based Testing Framework
  • Data Driven Testing Framework
  • Keyword Driven Testing Framework
  • Hybrid Driven Testing Framework
  • How to implement Testing Framework in Project

Object Repository

  • Understanding of Object Repository
  • Learning sample scripts using object repository
  • Page Object Modelling
  • Page Factory

JavaScript Functions

  • Autosuggestion
  • Headless Browser
  • Sikuli
  • XPath

Got a question for us? Please mention it in the comments section and we will get back to you.

0 responses on "Top Selenium Testing Interview Questions and Answers"

Leave a Message

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