Selenium Interview Questions

1. Explain automation testing?

Automation testing is the process of testing an application or software using an automation testing tool. In this process, we execute the test scripts and scenarios on automation tools to generate the results. It is optimally required when we have a huge amount of regression test scenarios. Some most popular automation tools are like HP QTP/UFT, Selenium WebDriver, etc.,

2. What are the benefits of Automation testing?

Below are few of the benefits of Automation tools and Automation testing.
This is one of the common interview questions in any Automation testing job.
1. Saves time and money: Automation testing is faster in execution.
2. Reusability of code: Create one time and execute multiple times with less or no maintenance.
3. Good and easy reporting: It generates automatic reports after test execution.
4. Easy for compatibility testing: It enables parallel execution in the combination of different OS and browser environments.
5. Low-cost maintenance: It is cheaper compared to manual testing in a long run.
6. Automated testing is more reliable, powerful and versatile.
7. Automation tools allow us to integrate with Cross Browser Testing Tools, Jenkins, Github etc.
8. It is mostly used for regression testing. Supports execution of repeated test cases.
9. Minimal manual intervention. Test scripts can be run unattended and increase maximum coverage of the test cases.

3. What is Selenium and what are the different Selenium components?

Selenium is one of the most popular automated testing suites or tool. Selenium is designed in a way to support automation testing of web-based applications. It has become one of the most accepted tools amongst the testing professionals due to its open source nature.
Selenium is not just a single tool or a utility, rather its 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 create different testing and test environment requirements.
The suite package constitutes the following sets of tools:
1. Selenium Integrated Development Environment (IDE) – Selenium IDE is a record and playback tool. It is distributed as a Firefox Plugin.
2. 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.
3. 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.
4. Selenium Grid – Selenium Grid is used to distribute your test execution on multiple platforms and environments concurrently.

4. Why should we choose Selenium as a test tool?

Following are few key points through which we can understand like why should we choose Selenium:
1. It is open source
2. It supports distributed testing
3. It has regular repository developments
4. It has a large user base and support community
5. It has wide platform compatibility – Windows, Mac OS, and Linux, etc.
6. It has cross-browser compatibility – Internet Explorer, Chrome, Firefox, Safari, etc.
7. It supports multiple programming languages – Java, C#, Ruby, Perl, Python, etc.

5. What are the testing types that can be supported by Selenium?

Selenium supports the following types of testing:
1. Functional Testing
2. Regression Testing

6. What are the limitations of Selenium?

Following are few limitations of Selenium:
1. Selenium supports only web-based applications testing.
2. Selenium doesn’t support mobile applications based testing.
3. Through Selenium we can not automate or test Captcha and Barcode readers.
4. Selenium doesn’t provide own reporting facilities. We need some other third-party tools like TestNG or JUnit for reporting.
5. Selenium is a free tool, thus there is no ready vendor support through the user can find numerous helping communities.
6. The user is expected to possess prior programming language knowledge.

7. What type of tests have you automated in your framework?

Here we need to describe like which type of test cases we automate in our daily life like Sanity, Smoke, Critical paths, Regression etc. Sometimes based on the project and the test time estimation, we do focus on End to End testing.

8. How many test cases you have automated per day?

It depends on Test case scenario complexity and length. I usually automate 2-5 test scenarios per day when the complexity is limited. Sometimes just 1 or fewer test scenarios in a day when the complexity is high.

9. What is a Framework?

A framework defines a set of rules which we can follow in a systematic way to achieve the desired results. There are different types of automation frameworks and the most common ones are:
1. Data Driven Testing Framework
2. Keyword Driven Testing Framework
3. Hybrid Testing Framework
4. Behavior Driven Development Testing Framework

10. Define different types of Test Automation Frameworks?

Below are few most common Test Automation Frameworks.
1. Data-driven Framework
2. Keyword Driven Testing Framework
3. Hybrid Driven Testing Framework
4. Behavior Driven Development Testing Framework

1. Data-driven Framework

Data-driven test automation framework is one of the popular test automation frameworks which is based on separating the test scripts logic from the test data. It allows us to create test automation scripts by passing different sets of test data. The test data set is kept in the external files like Excel Spreadsheets, MS Access Tables, SQL Database, XML files etc., With the help of this framework, we could easily make the test scripts work properly for different sets of test data.

2. Keyword Driven Testing Framework

Keyword Driven testing is also known as table-driven testing. In Keyword-driven testing, all the operations and instructions are written in some external file like an excel worksheet. It performs automation test scripts based on the keywords specified in the excel worksheet. By using this Framework, testers can work with keywords to develop any test automation script, testers with less programming knowledge would also be able to work on the test scripts. The logic to read keywords and call the required action mentioned in the external excel sheet is placed in the main class. Keyword-driven testing is similar to data-driven testing.

3. Hybrid Driven Testing Framework

Hybrid Driven Test automation framework is the combination of two or more frameworks as mentioned above. It holds to get the benefits of other frameworks. Nowadays the client recommends this hybrid driven framework in their project or framework.

4. Behavior Driven Development Testing Framework

The purpose of this Behavior Driven Development framework is to create a platform which allows everyone like Business Analysts, Stakeholders, Developers, Testers etc,) to participate actively. It requires increased collaboration between Development and Test Teams. It doesn’t require the users to be knowledge of programming language in a good manner. In this BDD framework, we use the non-technical and natural language like English to create test specifications. Some of the tools available in the market for Behavior Driven Development is JBehave, Cucumber, etc.,

11. How to explain Test Automation Framework to the interviewer?

In this question we need to mention all in and out of our Automation Framework like which programming language we used, Types of framework used, Test Base Class (Initializing WebDriver, Implicit Waits), How we separate Element locators and tests (Page Objects, Page Factory), Utility functions file, Property files, TestNG annotations, Handling parameterization tests using Excel files, Capturing error screenshots, Generating reports(TestNG or Extent Reports), Emailing reports, Version Control System(GIT or SVN) used and Continues Integration Tool(Jenkins etc) used.

12. What are the Programming Languages supported by Selenium WebDiver?

Java, C#, Python, Ruby, Perl, PHP

13. 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:

1. ID
2. ClassName
3. Name
4. TagName
5. LinkText
6. PartialLinkText
7. Xpath
8. CSS Selector

14. What is the difference between assert and verify commands?

Assert: Assert command checks whether the given condition is true or false. For example, we can assert the condition like 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 break i.e. any failure during verification would not stop the execution and all the test steps would be executed.

15. What are Hard Assert and Soft Assert in Selenium?

Hard Assert: Hard Assert throws an AssertException immediately when an assert statement fails and the remaining code in the same @Test will not execute and test suite continues with next @Test.
Soft Assert: Soft Assert collects errors during @Test. Soft Assert does not throw an exception when an assert fails and would continue with the next step after an assert statement. If there is an exception in the program and you want to throw it then you need to use assertAll() method as a last statement in the @Test and test suite again continue with next @Test as it is. Also, we need to create an object to use Soft Assert which is not needed in Hard Assert.

16. 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();

17. What are the different types of Drivers available in WebDriver?

The different drivers available in WebDriver are:

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

18. What are the different exceptions you have faced in Selenium WebDriver?

Below are few listed exceptions:

  • ElementNotVisibleException
  • StaleElementReferenceException
  • WebDriverException
  • NoSuchWindowException
  • NoSuchElementException
  • IllegalStateException
  • TimeoutException
  • NoAlertPresentException

19. What are the different types of waits available in WebDriver?

There are three types of waits available in WebDriver:
1. 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.

2. Explicit Wait: Explicit waits are used to halt the execution until 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.

3. Fluent Wait: In fluent wait we can change the default polling period based on our requirement. For Implicit and explicit waits, the default polling time is 250 milliseconds. Also, we can ignore any exception while polling element such as No such element exception in selenium.

20. How to Login into any site if it is showing an Authentication Pop-Up for Username and Password?

To perform this we need to pass the username and password with the URL.
Syntax: http://username:password@url

21. How to input text in the text box using Selenium WebDriver?

By using sendKeys() method
For example:
WebDriver driver = new FirefoxDriver();
driver.findElement(By.xpath(“xpath of the web element “)).sendKeys(“Selenium Interview Questions”);

22. How to clear the text in the text box using Selenium WebDriver?

By using clear() method
For example:
WebDriver driver = new FirefoxDriver();
driver.findElement(By.xpath(“xpath of the web element”)).clear();

23. How to get a text of a web element?

By using getText() method

For example:
WebDriver driver = new FirefoxDriver();
String text = driver.findElement(By.xpath(“xpath of the web element”)).getText();