01st
May
Selenium Interview questions

Selenium Interview questions

  • Yogesh Sinha
  • 01st May, 2021
  • 657 Followers

About Selenium

Selenium is a free open-source portable framework for testing various web applications. It is written in Java and forms the playback tool for authoring functional tests without the knowledge of test scripting language. It allows writing tests in many popular programming languages, including C#, Groovy, Java, Perl, PHP, Python, Ruby, and Scala.

Selenium Interview questions

1) What is Selenium?

SELENIUM is a free (open-source) portable automated testing framework used to validate web applications across different browsers and platforms. SELENIUM support a wide range of programming languages like Java, C#, Python, etc to create Test Scripts.

2) Enlist major components of Selenium?

Major Components of Selenium are

  • Selenium IDE
  • Selenium RC
  • Selenium WebDriver
  • Selenium Grid

3) What are the advantages of Selenium?

Advantages of using Selenium are

  • Open-Source
  • Supports various programming languages to write test scripts.
  • Supports various operating systems and web browsers.
  • Supports Parallel Test Execution.
  • Improves accuracy
  • Supports Execution of repeated test cases
  • Large Community Support
  • Add-ons and Reusability
  • Easy to Implement

4) List some programming languages supported by Selenium to write test cases?

Python, Java, C-Sharp, JavaScript, Ruby, PHP, Perl are programming languages supported by Selenium to write test cases.

5) What is Selenium WebDriver?

Selenium WebDriver is a collection of open-source APIs which are used to automate the testing of a web application. It supports many browsers such as Firefox, Chrome, IE, and Safari.

6) What is Automation Testing?

Automation testing is a Software testing technique to test and compare the actual outcome with the expected outcome. This can be achieved by writing test scripts or using any automation testing tool. Test automation is used to automate repetitive tasks and other testing tasks which are difficult to perform manually.

7) What are locators in Selenium? List different types of Element locators in Selenium?

Locator is a command that tells Selenium IDE which GUI elements ( say Text Box, Buttons, Check Boxes, etc) its need to operate on.

Different Types of Element Locators available in Selenium are Element ID, Field Name, TEXT, Link Text, CSS Class, XPath, CSS Selectors.

8) Write an syntax to launch the browser using WebDriver?

Syntax to launch the browser using WebDriver

public class BrowserLaunchDemo {
 
    public static void main(String[] args) {
         
        //Creating a driver object referencing WebDriver interface
        WebDriver driver;
         
        //Setting webdriver.gecko.driver property
        System.setProperty("webdriver.gecko.driver", pathToGeckoDriver + "\\geckodriver.exe");
         
        //Instantiating driver object and launching browser
        driver = new YourBrowserDriver(); // ie firefox, chrome, etc
         
        //Using get() method to open a webpage
        driver.get("http://artoftesting.com");
         
        //Closing the browser
        driver.quit();
  
    }
  
}

9) List various types of Drivers and Waits available in Selenium WebDriver?

The Drivers available in Selenium WebDriver are FirefoxDriver, InternetExplorerDriver, ChromeDriver, SafariDriver, OperaDriver, AndroidDriver, IPhoneDriver, and HTMLUnitDriver.

Different Types Of Wait available in Selenium Web Driver are

  • Implicit Waits
  • Explicit Waits

10) What is JUnit? List various JUnit annotations.

JUnit is a unit testing framework for the Java programming language. JUnit has been important in the development of test-driven development and is one of a family of unit testing frameworks that is collectively known as xUnit that originated with SUnit.

Here're some basic JUnit annotations

  • @BeforeClass: Run once before any of the test methods in the class,
    public static void
  • @AfterClass: Run once after all the tests in the class have been run,
    public static void
  • @Before: Run before @Test,
    public void
  • @After: Run after @Test,
    public void
  • @Test: This is the test method to run,
    public void

11) List types of test supported by Selenium?

Selenium supported the following types of testing :

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

12) What is the use of X-path?

XPath is defined as XML path. It is a syntax or language for finding any element on the web page using XML path expression. XPath is used to find the location of any element on a webpage using HTML DOM structure.

13) What is an Object Repository ?

Object Repository is a centralized location where we can store objects information, it acts as interface between Test script and application in order to identify the objects during the execution.

14) What is heightened privileges browsers?

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

15) What is Selenese?

Selenese is the set of selenium commands which are used to test your web application. A tester can test the broken links, the existence of some object on the UI, Ajax functionality, Alerts, window, list options, and lot more using Selenese. Selenium command tells selenium automation engine to perform certain tasks

16) 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 a relative path i.e. the XPath would be created to start selection from anywhere within the document.

17) List different types of navigation commands available in Selenium?

Different types of navigation commands available in Selenium are

  • Navigate To Command

    Syntax
    driver.navigate().to("url");    
  • Forward Command

    Syntax
    driver.navigate().forward();    
  • Back Command

    Syntax
    driver.navigate().back();  
  • Refresh Command

    Syntax
    driver.navigate().refresh();   

18) What is use of driver.close() and driver.quit command in Selenium?

The close() and quit() commands work in the way when the automation process opens only a single browser window. Both will differ in their functionality when there is more than one browser window opened during Automation.

  • driver.close() is used if you want to close the current tab which is being used.
  • driver.quit() is used when you want to close the complete browser which you have been using for Selenium WebDriver.

19) How to assert the title of the web page in WebDriver?

The Below code is used to assert the title of the web page in WebDriver.

assertTrue("The title of the window is incorrect.",driver.getTitle().equals("Title of the page"));

20) Explain what is TestNG?

TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use. It was written for Java programming language and created by Cédric Beust.

21) What is Datadriven and Keyword driven framework?

Data Driven Framework is one of the popular Automation Testing Framework in the current market. Data-Driven automated testing is a method in which the test data set is created in the excel sheet, and is then imported into automation testing tools to feed to the software under test.

The Keyword-Driven framework is a technique to externalize keywords/actions that are used in the script in a separate Object Repository (here, it is a Java Class file), which will give positive outcomes like increased code-reusability, reduced script maintenance, and higher portability.

22) What is Silk Test Tool?

Silk Test is a tool for automated function and regression testing of enterprise applications. It was originally developed by Segue Software which was acquired by Borland in 2006. Silk Test Workbench allows automation testing on a visual level (similar to former TestPartner) as well as using VB.Net as a scripting language.

23) How to insert a break point in Selenium IDE ?

Break point can be set in two ways in Selenium IDE:

  1. Right click on the command in Selenium IDE and select "Toggle Break Point".
  2. Select the command in Selenium IDE and press "B" key on the keyboard.
  3. If you want to clear the break point once again press "B" key on the keyboard.
  4. You can set multiple break points in Selenium IDE.

24) What is selenium RC?

Selenium RC is an important component in the Selenium test suite. It is a testing framework that enables a QA or a developer to write test cases in any programming language in order to automate UI tests for web applications against any HTTP website.

25) What is IntelliJ IDEA?

IntelliJ IDEA is an integrated development environment written in Java for developing computer software. It is developed by JetBrains and is available as an Apache 2 Licensed community edition, and in a proprietary commercial edition. Both can be used for commercial development.

26) How to type in a textbox in selenium?

To type in a textbox in selenium simply find the element and use sendKeys method to type the text.

Example

WebDriver driver = new FirefoxDriver();
WebElement name = driver.findElement(By.id("name"));
name.sendKeys("Interview Mocks");

27) What are TestNG Listeners in Selenium WebDriver?

A listener is defined as an interface that modifies the default TestNG's behavior. As the name suggests Listeners "listen" to the event defined in the selenium script and behave accordingly. It is used in selenium by implementing Listeners Interface.

There are many types of listeners that allows you to change the TestNG's behavior. Some of them are

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

28) Can we handle colors in Web Driver?

Yes, it is possible to handle colors in WebDriver. You can discover the color of a web element and then verify it by using the getCssValue() method, which takes CSS attribute as input and returns value of that attribute like color, font-size, etc.

Below is a sample code for verifying the color of a web element:

public void verifyColor() throws Exception{
	String color = driver.findElement(By.xpath("//a[@href='products/']")).getCssValue("color");
	String[] hexValue = color.replace("rgba(", "").replace(")", "").split(",");
	int hexValue1=Integer.parseInt(hexValue[0]);
	hexValue[1] = hexValue[1].trim();
	int hexValue2=Integer.parseInt(hexValue[1]);
	hexValue[2] = hexValue[2].trim();
	int hexValue3=Integer.parseInt(hexValue[2]);
	String actualColor = String.format("#%02x%02x%02x", hexValue1, hexValue2, hexValue3);
	Assert.assertEquals("#245dc1", actualColor);
}

29) What are the common exceptions in Selenium WebDriver?

Common Exceptions in Selenium WebDriver are

  • NoSuchElementException.
  • NoSuchWindowException.
  • NoSuchFrameException.
  • NoAlertPresentException.
  • InvalidSelectorException.
  • ElementNotVisibleException.
  • ElementNotSelectableException.
  • TimeoutException.

30) What is an Accessor in Selenium?

Accessor is one of the type of Selenese. Accessors are used for storing the value of a target in a variable. Accessors can also be used for evaluating the result and storing the result in a variable. Here are few most commonly used Accessors:-

  • storeTitle – This will store the title of a window in a variable.
  • storeText – This will store the target element text in a variable.

31) What is stale reference element error?

The stale element reference error is a WebDriver error that occurs because the referenced web element is no longer attached to the DOM. When an element is no longer attached to the DOM, i.e. it has been removed from the document or the document has changed, it is said to be stale

32) What is parameterization in TestNG?

Parameterization in TestNG is an execution strategy, which allows us to run a test case automatically, multiple times with different input values. This test design will let users read data from storage, for example from a file or database, rather than using hard-coded values.

33) What is waitfor command in Selenium?

A "waitFor" command waits for some condition to become true. They will fail and halt the test if the condition does not become true within the current timeout setting.

waitFor commands are more appropriate to be used on AJAX-based dynamic websites that change values and elements without reloading the whole page.

34) What are the different mouse-hover operations in selenium?

Different mouse hover actions in Selenium are Move Mouse, Build and Perform.

Example Code

Actions actions = new Actions(driver);
WebElement mainMenu = driver.findElement(By.linkText("menulink"));
actions.moveToElement(mainMenu);

WebElement subMenu = driver.findElement(By.cssSelector("subLinklocator"));
actions.moveToElement(subMenu);
actions.click().build().perform();

35) What is Page Factory?

Page Factory is an inbuilt Page Object Model concept for Selenium WebDriver but it is very optimized. It is used to initialize the elements of the Page Object or instantiate the Page Objects itself.

36) What is regression testing?

Regression testing is a type of software testing that seeks to uncover new software bugs in existing functional and non-functional areas of a system after changes such as enhancements, patches or configuration changes/upgrades, have been made to the application.

37) What is a Robot class?

Robot class is an AWT package used to generate keyboard/mouse events to interact with OS windows and native apps. The primary purpose of Robot is to support selenium automated tests projects to build on the Java platform.

38) What is Equivalence partitioning?

Equivalent Partitioning is a black box technique (code is not visible to tester) which can be applied to all levels of testing like unit, integration, system, etc. In this technique, you divide the set of test conditions into a partition that can be considered the same.

  • It divides the input data of software into different equivalence data classes.
  • You can apply this technique, where there is a range in the input field.

39) How to take screenshots in Selenium WebDriver?

In order to capture a screenshot in Selenium, you can use TakesScreenshot method. This method notifies the WebDriver that it should take a screenshot in Selenium and store it.

Below is syntax to take screenshot in Selenium

File file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String screenshotBase64 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.BASE64);

40) List some commonly used Automation Testing tools for Functional Automation?

Below is the top 10 Automation Testing tools for Functional Automation.

  • Selenium
  • QTP or UFT
  • Katalon Studio
  • TestComplete Tool
  • Ranorex Studio
  • Sahi Tool
  • Telerik TestStudio
  • Tosca Testsuite
  • WatiN Tool
  • Watir Tool

41) What is Selenium Grid?

Selenium Grid is a feature in Selenium that allows you to run test cases in different machines across different platforms. The control of triggering the test cases is on the local machine, and when the test cases are triggered, they are automatically executed by the remote machine.

42) List some Continuous Integration tools?

Continuous integration (CI) is the practice of automating the integration of code changes from multiple contributors into a single software project. The CI process is comprised of automatic tools that assert the new code's correctness before integration.

Below is the list some Continuous Integration tools

  • Buddy.
  • TeamCity.
  • Jenkins.
  • Travis CI.
  • Bamboo.
  • GitLab CI.
  • CircleCI.
  • Codeship

43) What is Parallel Test Execution in Selenium?

Parallel test execution involves running a suite of automated tests in parallel as opposed to sequentially. You don't execute your tests one by one. Rather, you take the entire batch and split it up amongst multiple servers so that each server can run a single test at a time.

44) List types of synchronization in selenium?

Synchronization in Selenium can be classified into two categories:

  • Unconditional Synchronization: In this case, only the timeout value to be specified. The tool will wait till a certain time before proceeding.

    Example
    Wait(), Thread.Sleep()
    The main advantage of this method is that it will come for help when we interact with a third party system such as an interface.
  • Conditional Synchronization: In this case, a condition also will be specified along with the timeout value. The tool will wait to check the condition and will come out if nothing happens. However, it is important to set a timeout value also in conditional synchronization so that the tool will proceed even if the condition is not met. There two different types of conditional statements in selenium webdriver and they are an implicit wait and explicit wait.

45) What are actions classes in selenium?

Actions class is an ability provided by Selenium for handling keyboard and mouse events. In Selenium WebDriver, handling these events includes operations such as drag and drop, clicking on multiple elements with the control key, among others. These operations are performed using the advanced user interactions API. It mainly consists of Actions that are needed while performing these operations.

Action class is defined and invoked using the following syntax:

Actions action = new Actions(driver);
action.moveToElement(element).click().perform();

1 comment(s) :

  •   Reply
    img

    Rahul Gupta

    03rd May, 2020
    "It's just a basic few questions not appropriate for interviews, there are lots of common selenium interview questions which is not covered. first add details then spend money on seo.

Leave A Comment :

Valid name is required.

Valid name is required.

Valid email id is required.