Select Page
Codoid Blog

Hopper Day – Exploring Selenium 4 Features

Being a leading QA Company, we write blogs on all prominent software testing topics and tools using our real-world experience. So stay sharp by subscribing to our Newsletter.

Hopper Day - Exploring Selenium 4 Features Codoid Blog
Listen to this blog

Today (09-Nov-2019) at Codoid, our automation testing experts have organized an internal workshop event to explore Selenium 4 salient features. R&D workshops of this kind is conducted every month and we named today’s workshop as ‘Hopper Day’.

At the end of the ‘Hopper Day’ event, we will publish our findings in the form of a blog article which will immensely benefit the Software Testing Community.

Why we named it as ‘Hopper day’?

Grace Hopper was an American computer scientist. She was a pioneer of computer programming and created a compiler that converted English terms into machine code understood by computers. Without her contributions to the computing world, modern programming wouldn’t have been in existence. Her contribution is an infinite source of motivation for today’s tech community. In all these R&D workshops, as a leading automation testing company we aspire to contribute our ideas, findings, and innovations to the Software Testing Community.

Selenium 4 Features

Selenium 4 Features

In today’s Hopper Day event, we have explored the upcoming Selenium 4 features.

Full Page Screenshot

In Selenium 4, we can take full page screenshot using firefox driver.

File file = ((FirefoxDriver)driver).getFullPageScreenshotAs(OutputType.FILE);
FileUtils.copyFileToDirectory(file, new File("drivers"));
  

Relative Locator

Relative Locator is a new way to find web elements, it helps us to find web elements based on their visual location relative to other elements.

driver.findElement(withTagName("p").near(By.className("cls1"),120));
  

Casting from Chrome

If you have ChromeCast, then you can mirror your Chrome Tab to another device using Local or Remote WebDriver.

WebDriver driver = new ChromeDriver();
((ChromeDriver)driver).startTabMirroring("Device Name");
  

Open New Window & Tab

In Selenium 4.0, you can open new window & tab using “newWindow” command.

WebDriver driver = new FirefoxDriver();   
driver.switchTo().newWindow(WindowType.WINDOW);
driver.switchTo().newWindow(WindowType.TAB);
  

Selenium Grid – Distributed Execution

Selenium Grid has only two components Hub and Node. On the other hand in Selenium Grid 4, we have four components namely – Router, Sessions Map, Distributor, and Node. Selenium 4 has introduced new architecture for Grid. Refer the following blog article for more details – Selenium Grid 4 – Distributed Execution.

Chrome DevTools Interface

You can retrieve Chrome Console logs using DevTools interface.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.Log;
import org.slf4j.*;

public class Selenium4Devtools {
    final static Logger logger = LoggerFactory.getLogger(Selenium4Devtools.class);

    public static void main(String args[]){
        System.setProperty("webdriver.chrome.driver", "drivers/chromedriver.exe");
        WebDriver driver = new ChromeDriver();

        try{
            DevTools devTools = ((ChromeDriver)driver).getDevTools();
            devTools.createSession();
            devTools.send(Log.enable());
            devTools.addListener(Log.entryAdded(), entry -> logger.error(entry.asSeleniumLogEntry().getMessage()));
            driver.get("https://www.codoid.com");
        }
        catch(Exception e){
            e.printStackTrace();
        }
        finally {
            driver.quit();
        }
    }
}
  

Docker Nodes

You can start Selenium Grid Nodes using Docker.

java -jar selenium-server-4.0.0-alpha-1.jar node -D selenium/standalone-firefox:latest '{"browserName": "firefox"}'
  

Detect Drivers

When you start Selenium Grid node, you no need to pass driver configuration variables as shown below.

java -Dwebdriver.gecko.driver="C:geckodriver.exe" -jar selenium-server-standalone-3.4.0.jar -role webdriver -hub http://192.168.1.3:4444/grid/register -port 5566
  

In Selenium 4, you can download and save the required driver files inside the folder where you have saved Selenium Server.jar. The node initiating command will pick up the appropriate driver using –detect-drivers argument.

java -jar selenium-server-4.0.0-alpha-1.jar node --detect-drivers
  

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