Selenium 4 Features- Running Edge headless
Kushan Shalindra Amarasiri
Head of Quality Engineering at Social Catfish
In this article series I will be highlighting the most important features of Selenium 4 for the QA community.
In this article I will show how we can run Edge headless which is good feature. Running Edge headless will help us to execute the test automation scripts much faster in Edge and with less CPU and Memory usage.
First of all add the Selenium 4 maven dependency and the WebDriver Manager dependency to the pom.xml file.
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.0.0-beta-4</version> </dependency> <dependency> <groupId>io.github.bonigarcia</groupId> <artifactId>webdrivermanager</artifactId> <version>4.4.3</version>
</dependency>
Next call the edge chromium and headless setting as edge options
@BeforeTest public void setup() { WebDriverManager.edgedriver().setup(); EdgeOptions options=new EdgeOptions(); options.setCapability("UseChromium", true); options.addArguments("headless"); driver = new EdgeDriver(options); }
Add your test method and run the test
@Test public void test1() { sa = new SoftAssert(); driver.get("https://demo.guru99.com/V4/"); driver.findElement(By.name("uid")).sendKeys("mngr332873"); driver.findElement(By.name("password")).sendKeys("umEtyvy"); driver.findElement(By.name("password")).submit(); driver.findElement(By.name("btnLogin")).click(); WebDriverWait wait = new WebDriverWait(driver, 20); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("https://td[contains(text(),'Manger Id : mngr320768')]"))); Assert.assertEquals(driver.findElement(By.xpath("https://tr[@class='heading3']/td")).getText(), "Manger Id : mngr320768");
}
Finally add the tear down method to close the headless browser instance
@AfterTest public void teardown() { driver.close(); driver.quit();
}
Run the test script and the script will run Edge in headless mode.