Top Selenium Interview Questions (2024) | TechGeekNext


Top Selenium Interview Questions (2024)

  1. What is Selenium?
  2. How does selenium communicate with the browser?
  3. What is Robot Operating System?
  4. What is Selenium Grid?
  5. What is Selenium Web Driver?
  6. Explain Selenium WebDriver Architecture?
  7. How Selenium WebDriver works?
  8. How to Automate Web Pages with Selenium WebDriver?
  9. What is the difference between Selenium and Selenium WebDriver?
  10. Write a WebDriver script that fetches the TechGeeknext homepage, verifies its title, prints the comparison result, and closes it before terminating the program?

Q: What is Selenium?
Ans:

Selenium is an open-source framework for testing web applications that can be used on any device. Selenium provides a playback tool for functional tests so no need to learn a test scripting language.

You can automate the testing of web applications with Selenium. You can write test scripts in languages such as Java, Python, Ruby, and C# and run them on browsers and virtual machines. Some teams do this on their own, while others use a cloud-based provider.

Q: How does selenium communicate with the browser?
Ans:

As the name suggests, Selenium's Remote Control (RC) uses a browser's remote control to inject automated scripts into a browser. Browsers interact with Selenium RC Server. Browsers are injected with JavaScript functions as soon as a web page is loaded. RC had an advantage over the Web Driver because it provides users with an automated HTML file of test results, whereas the Web Driver lacks this feature.

Q: What is Selenium Grid?
Ans:

Selenium Grid allows us to run multiple test cases at the same time on multiple remote machines. As a result, there is an increase in execution speed. For example, let us say we have a test suite with both complex and simple test cases. Depending on the complexity of the test cases, we can separate them and run them separately.

The main advantage of Selenium Grid is that test cases can be executed more quickly and in parallel. There are a number of test cases that are executed in different environments on different remote machines with the help of Selenium RC.

Take a look at our suggested post :

Q: What is Selenium WebDriver?
Ans:

Selenium Web Driver works directly on the browser and triggers the automation test written by the tester by using the browser's in-built features.

HTMLUnit browsers(HTMLUnit browsers are headless browsers that also implies they are invisible to the user, in other words they do not have a GUI) are a great way to test web drivers because they reduce the time it takes to load the page elements. This reduces the time it takes to run test cases.

Web Driver is faster than Selenium RC because it controls the browser from the OS level.

Q: Explain Selenium WebDriver Architecture?
Ans:

Selenium WebDriver API allows browsers and browser drivers to communicate with each other. The Selenium Client Library, JSON Wire Protocol, Browser Drivers, and Browsers make up the four layers of the architecture.

  1. Selenium Client Library
    Languages such as Java, Ruby, Python, C#, and others are included in the Selenium Client Library. The Selenium code will be translated to Json format after the test cases have been triggered.
  2. JSON WIRE PROTOCOL
    Javascript Object Notation (JSON) is an acronym for Javascript Object Notation. It is responsible for sending data from the server to the client. The JSON Wire Protocol is primarily used for data transport between HTTP servers. The http protocol is used to make generated Json available to browser drivers.
  3. Browser Drivers
    A browser driver is specific to each browser. Browser drivers communicate with their individual browsers and carry out commands by parsing Json sent by the browser. Any instructions received by the browser driver are immediately executed by the browser. The response is then returned in the form of an HTTP response.

Q: How Selenium WebDriver works?
Ans:

When a user writes and executes WebDriver code in Selenium, the following events occur in the background:

  1. An HTTP request is generated and sent to the appropriate browser driver (Chrome, IE, Firefox). For each Selenium command, there is a separate request.
  2. An HTTP server sends the request to the browser driver.
  3. The HTTP server determines which actions/instructions the browser must perform.
  4. The browser follows the above-mentioned instructions/steps.
  5. The HTTP server then gets the status of the execution and passes it to an automation script, which displays the outcome ( as passed or an exception or error).

Q: How to Automate Web Pages with Selenium WebDriver?
Ans:

There are normally seven steps to any Selenium test script, which apply to all test cases and all applications under test (AUT):

  1. Create a WebDriver instance that is particular to the Browser.
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    WebDriver driver = new FirefoxDriver();
  2. Go to the Web page that has to be automated like driver.get("https://techgeeknest.com/text-box")
  3. Locate the HTML elements on the web page to get the “Full Name” text box.
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    WebElement usernameElement = driver.findElement(By.id("userName"));
  4. Use the following code to perform an action on an HTML element:
    usernameElement.sendKeys("John Thomas");
  5. We can utilise the appropriate WebDriver for the browser on which we need to test our application. Using a test framework, run tests and record results.

Q: What is the difference between Selenium and Selenium WebDriver?
Ans:

Despite the fact that Selenium and Selenium WebDriver are both part of the same framework, they have some distinctions. Let's have a look at some examples -

  1. Selenium is a framework that consists of multiple independent products such as Selenium IDE, Selenium RC, WebDriver, and Selenium Grid, rather than a single tool. WebDriver, on the other hand, is a single tool that is part of the Selenium framework.
  2. Selenium supports and provides framework and tools for quality assurance professionals who can create both code-based and code-less automation. WebDriver primarily offers a code-based automation technique.

Q: Write a WebDriver script that fetches the techgeeknext homepage, verifies its title, prints the comparison result, and closes it before terminating the program?
Ans:

package newproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//to use Chrome, uncooment below import
//import org.openqa.selenium.chrome.ChromeDriver;
public class TestExample {


    public static void main(String[] args) {
        //For Firefox Browser
        /* GeckoDriver (web browser engine) is the link between your tests
        *in Selenium and the Firefox browser
        */
    	System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
		WebDriver driver = new FirefoxDriver();

		//For Chrome Browser
		//System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
		//WebDriver driver = new ChromeDriver();

        String baseUrl = "https://www.techgeeknext.com/";
        String expectedTitle = "Welcome to TechGeekNext!";
        String actualTitle = "";

        // navigate to the Base URL
        driver.get(baseUrl);

        // get the title of the page
        actualTitle = driver.getTitle();

        //compare the title of the page and print the result

        if (actualTitle.contentEquals(expectedTitle)){
            System.out.println("Title Matching!");
        } else {
            System.out.println("Title Not Matching!");
        }

        //close Firefox
        driver.close();

    }

}








Recommendation for Top Popular Post :