Select Page
Selenium Testing

The Top Selenium 4 New Features You Should Know About

In addition to exploring the top Selenium 4 New Features, you'll also learn how the architecture of Selenium 4 is different from Selenium 3.

The Top Selenium 4 New Features You Should Know About - Blog
Listen to this blog

Now that Selenium 4 has been officially released, we thought it’ll be a great idea to compare the architecture of both Selenium 3 & 4 and explore the Selenium 4 New Features. As one of the leading automation testing companies, we have been using Selenium for years and years over numerous projects to deliver high-quality Automation Testing Services to our clients. We feel that the upgrades in Selenium 4 are all welcome features that will be useful in helping the software testing community. Now let’s kick start this blog by comparing the two architectures.

Selenium 3 Architecture:

Selenium WebDriver Architecture

  • The architecture for Selenium 3 includes the JSON Wire Protocol (JSON stands for JavaScript Object Notation).
  • The JSON Wire Protocol operates as a mediator to transfer information from the client to the server over HTTP (HyperText Transfer Protocol).
  • The Request is sent from the Selenium Client & the WebDriver Language Bindings module and received by the JSON Wire Protocol over HTTP. It is then secured by the Browser Driver module as shown in the above figure.
  • Therefore the request command is delivered to a Web Browser module where the real automation takes place as shown in the above figure.

Selenium 4 Architecture:

Selenium 4 Architecture

  • Selenium 3 includes the JSON Wire Protocol as discussed above, whereas Selenium 4 has introduced the W3C protocol as the communication medium of the browser between the client and server.
  • Here, the client has two parts called the Selenium Client and WebDriver Language Bindings. The Browser Drivers acts as the server as shown in the above figure.
  • The Selenium Client sends out a request to perform a command.
  • The Browser Drivers receives that request and then returns a response after an automation test script is executed on the web browser.

Selenium 4 New Features:

Now that we understand how both versions work, let’s explore what are the new features that Selenium 4 has to offer.

1. Selenium WebDriver:

It is an open-source API that the web driver allows to interact with the browser just like a real user.

2. Selenium IDE:

It enables us to record and playback the user interactions with the browser. The new version of Selenium IDE is now available with more features.

3. Selenium Grid:

It can be used to save time by distributing and running tests on multiple browsers, operating systems, and machines.

4. Using WebDriver Manager:

Prior to the release of Selenium 4, if you wanted to run Selenium WebDriver automation scripts in Chrome, you had to first download chromedriver.exe and then use the System.setProperty as shown below to set its path.

System.setProperty("webdriver.chrome.driver","/absolute/path/to/binary/chromedriver");

After Selenium 4 release

Step 1: Add the Maven Dependency for the WebDriver Manager

https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager

Step 2: Add the code

Instead of the “System.setProperty()” call, the class code for WebDriverManager should be used.

WebDriverManager.chromedriver().setup();

Step 3: We can also choose a specific version of the browser as shown below.

WebDriverManager.chromedriver().driverVersion(“92.0”).setup();

5. To Capture screenshot of specific web element in selenium 4:

Users being able to take a screenshot of a specific web element is another one of the best Selenium 4 New Features that can make life easier for testers. Earlier, it was possible to take a screenshot of the entire page, but there was no provision to take the screenshot of a specific web element. Though it is a simple upgrade, it can come in very handy during real-world usage.

WebElement logo =driver.findElement(By.xpath("//div[@class='logo_container']"));
File file=logo.getScreenshotAs(OutputType.FILE);
File destFile =new File(“codoid.png”);
FileUtils.copyFile(file,destfile);

6. To open the new tab on the browser in Selenium 4:

The users can save a lot of time as it is now possible to open a URL in a new tab along with the existing tab. Let’s take a look at the sample code for opening two URLs in two different tabs.

public class SampleTab {
    public static void main(String[] args) {
          System.setProperty("webdriver.chrome.driver","src/Drivers/chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com/");
        driver.switchTo().newWindow(WindowType.TAB);
        driver.navigate().to("https://codoid.com/");
    }
}

7. To Open a new window on the browser in Selenium 4:

So it doesn’t just stop with new tabs, you can also open a new window on the same browser and access two applications at the same time in Selenium 4.

public class SampleWindow {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver","src/Drivers/chromedriver.exe");
        WebDriver driver = new ChromeDriver();
            driver.get("https://www.google.com/");
            driver.switchTo().newWindow(WindowType.WINDOW);
            driver.navigate().to("https://codoid.com/");
    }
}

8. Relative Locators:

Selenium 4 has even added 5 relative locators that enable testers to find web elements relative to another element in the implemented DOM.

The Five locators newly added to Selenium 4:

  • toLeftOf()
  • toRightOf()
  • above()
  • below()
  • near()

The Key Differences between Selenium 3 and Selenium 4

S. No Selenium 3 Selenium 4
1 The Chrome Driver Extends Directly To The Remote Web Driver. The Chrome Driver Class Extends To The Chromium Driver That Has A Few Predefined Ways To Access The Dev Tool.
2 The JSON Wire Protocol Operates As A Mediator To Transfer Information From The Client To The Server Over HTTP. Since It Uses The W3C (World Wide Web Consortium) Standard Protocol, The Driver And Browser Communication Follows The Standard Procedure.
3 The Testers Always Have To Start The Hub And Node Jars Every Time They Perform Automation Testing. Testers Needn’t Have To Start The Hub And Node Jars Every Time They Perform Automation Testing.
Related Blogs

Selenium Plugins

Conclusion

So it is very evident that the Selenium 4 upgrade has a lot of good improvements to offer including better documentation. By seeing the architectural changes, we hope you will be in a better position to use the tool more effectively. As a leading QA company, we always make it a point to know the tool inside and out as it helps us utilize the full potential of the tool.

Comments(0)

Submit a Comment

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

Talk to our Experts

Amazing clients who
trust us


poloatto
ABB
polaris
ooredo
stryker
mobility