App & Browser Testing Made Easy

Give your users a seamless experience by testing on 3000+ real devices and browsers. Don't compromise with emulators and simulators

Home Guide How to launch Edge browser in Selenium

How to launch Edge browser in Selenium

By Jash Unadkat, Technical Content Writer at BrowserStack -

Chrome, Firefox, and Safari are undoubtedly the leading browsers worldwide as they comprise almost 85% of the total browser market share. This might make it seem like one can avoid optimizing their sites for a browser like Microsoft Edge. However, that’s not the case.

As per a report by StatCounter, the legacy versions of Edge still make up 7.9% of the total desktop browser market share in the US. Besides, Edge also has significant brand recognition as it comes from the Microsoft family. Thus, to provide a truly browser-agnostic experience, it becomes imperative for teams to test their web applications on Edge.

This article will demonstrate the fundamental steps to launch Edge browser using Selenium WebDriver for automated testing. It will also detail how Mac users can test on Edge legacy.

Note: Microsoft recently launched the new version of Edge in Jan 2020 that was built using the Chromium engine. As a result, Microsoft distinguishes between both versions with unique naming conventions – Edge, and Edge legacy. As per the support document from Microsoft, Edge legacy represents the older browser versions that were built using the EdgeHTML engine (e.g – v17,18), and Chromium-based Edge is just termed as Microsoft Edge.

Configuring the Edge Driver

Prerequisites:

  • Installing the Windows 10 environment on the machine to run tests for legacy versions (15,16,17) of Edge
  • Downloading accurate WebDriver server version
  • Ensuring that the updated version of Selenium is being used

Now let’s get started with the steps for configuration.

  1. The primary step is to check the version of the OS build being used. Based on the OS version build, download the corresponding Edge driver.
  2. To check the OS Build, go to Start > Settings > System > About. In the example in this article, OS version build is 17134.
  3. Download the driver for the desired Edge version from the official source as per the OS version build identified earlier. Once the zip file is downloaded, unzip it and copy the .exe file to a specific location.
  4. The next step is to import it in the project file. It’s assumed that the user knows how to set up a basic Selenium project.
    One can refer to this article on Selenium with Java to understand how to set-up a basic Selenium with Java project in Eclipse IDE.
  5. Define the Edge driver with its accurate path using the system setProperty method and instantiate the Edge driver.
// Set the driver path
System.setProperty("webdriver.edge.driver", "C://EdgeDriver.exe");

// Start Edge Session
WebDriver driver = new EdgeDriver();

driver.get("https://google.com");

driver.quit();

At this point, the Edge driver has been configured. Now let’s perform a sample test scenario. In this scenario, the code will automate 3 fundamental steps:

  1. Launch the Edge browser
  2. Navigate to the Google website
  3. Enter “BrowserStack Guide” as a search query

Note: To interact with web-elements, one must know how to locate elements in Selenium. Refer to this detailed guide on locators in Selenium to learn about it in detail.

Code for launching Edge Browser using Selenium:

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;


public class Edge_Test{
public static void main(String[] args) {

//Setting system properties of EdgeDriver
System.setProperty("webdriver.edge.driver", "C://EdgeDriver.exe");

//Creating an object of EdgeDriver
WebDriver driver = new EdgeDriver();
driver.manage().window().maximize();

//Deleting all the cookies
driver.manage().deleteAllCookies();

//Specifiying pageLoadTimeout and Implicit wait
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

//launching the specified URL
driver.get("https://www.google.com/");

//Locating the elements using name locator for the text box
driver.findElement(By.name("q")).sendKeys("BrowserStack Guide");

// locator for Google search button
WebElement searchIcon = driver.findElement(By.name("btnK"));
searchIcon.click();
}
}

Executing the script above will launch the Edge browser, navigate to the Google website, and enter the term BrowserStack Guide as a search query.


Also read: How to run Selenium Tests on IE using Selenium IE Driver.


How can Mac users test on Edge?

An easy and effective solution for Mac users is to leverage platforms like BrowserStack for testing web-apps on both the latest and legacy versions of Edge browsers installed on real devices. The image below showcases how a user can perform a remote test session on Edge v18 directly from any browser.

Test on Edge Browser Versions

BrowserStack’s real device cloud enables Windows and Mac users to perform both manual and automated tests for their web-applications on 3000+ real devices and browsers. This ensures that teams can perform comprehensive cross browser testing for their web-applications in real-user conditions. BrowserStack also allows them to conduct mobile app testing and automated app testing on real iOS and Android devices.

Try Selenium Testing on Edge Browser Now

Tags
Automation Testing Cross browser testing Selenium Selenium Webdriver

Featured Articles

How to run Selenium tests on Chrome using ChromeDriver?

How to run Selenium tests using Firefox WebDriver

Curated for all your Testing Needs

Actionable Insights, Tips, & Tutorials delivered in your Inbox
By subscribing , you agree to our Privacy Policy.
thank you illustration

Thank you for Subscribing!

Expect a curated list of guides shortly.