Use WebDriver (Chromium) for test automation

WebDriver enables developers to create automated tests that simulate user interaction. WebDriver tests and simulations differ from JavaScript unit tests because of the following reasons.

  • Accesses functionality and information not available to JavaScript running in browsers.
  • Simulates user events or OS-level events more accurately.
  • Manages testing across multiple windows, tabs, and webpages in a single test session.
  • Runs multiple sessions of Microsoft Edge on a specific machine.

The following section describes how to get started with WebDriver for Microsoft Edge (Chromium).

Install Microsoft Edge (Chromium)

Ensure you install Microsoft Edge (Chromium). To confirm that you have Microsoft Edge (Chromium) installed, go to edge://settings/help in the browser, and verify the version number is Version 75 or later.

Download Microsoft Edge Driver

To begin automating tests, use the following steps to ensure that the WebDriver version you install matches your browser version.

  1. Go to edge://settings/help to get the version of Edge.

    The build number for Microsoft Edge Canary on January 14, 2020

    Figure 1. The build number for Microsoft Edge Canary on January 14, 2020

  2. Navigate to the Microsoft Edge Driver downloads page and download the driver that matches the Edge version number.

    The Downloads section of the Microsoft Edge Driver page

    Figure 2. The Downloads section of the Microsoft Edge Driver page

    Note

    For more information about test automation using Microsoft Edge (EdgeHTML), see Microsoft WebDriver for Microsoft Edge (EdgeHTML).

Choose a WebDriver language binding

The last component you must download is a language-specific client driver to translate your code (Python, Java, C#, Ruby, JavaScript) into commands the Microsoft Edge Driver runs in Microsoft Edge (Chromium).

Download the WebDriver language binding of your choice. The Microsoft Edge team recommends Selenium 4.00-alpha05 or later, because it supports Microsoft Edge (Chromium). However, you are able to control Microsoft Edge (Chromium) in all older versions of Selenium, including the current stable Selenium 3 release.

Important

If you were previously automating or testing Microsoft Edge (Chromium) using ChromeDriver and ChromeOptions classes, your WebDriver code does not run on Microsoft Edge Version 80 or later. To solve this problem, update your tests to use the EdgeOptions class and install Microsoft Edge Driver.

Use Selenium 3

If you already use Selenium 3, you may have existing browser tests and want to add coverage for Microsoft Edge (Chromium) without changing your version of Selenium. To use Selenium 3 to write automated tests for both Microsoft Edge (EdgeHTML) and Microsoft Edge (Chromium), install the Selenium Tools for Microsoft Edge package to use the updated driver. The EdgeDriver and EdgeDriverService classes included in the tools are fully compatible with the built-in equivalents in Selenium 4.

Use the following steps to add the Selenium Tools for Microsoft Edge and Selenium 3 to your project.

Add the Microsoft.Edge.SeleniumTools and Selenium.WebDriver packages to your .NET project using the NuGet CLI or Visual Studio.

Use Microsoft Edge (Chromium) with WebDriver

You may run the following examples using either Selenium 3 or 4. To use with Selenium 3, the Selenium Tools for Microsoft Edge package must be installed.

Basic Usage

To use with Microsoft Edge (EdgeHTML), simply create a default instance of the EdgeDriver class.

var driver = new EdgeDriver();

Driving Microsoft Edge (Chromium)

To use with Microsoft Edge (Chromium), create a new EdgeDriver class and pass it the EdgeOptions object with the UseChromium property set to true.

var options = new EdgeOptions();
options.UseChromium = true;

var driver = new EdgeDriver(options);

Note

If the DeveloperToolsAvailability policy is set to 2, Microsoft Edge Driver is not be able to drive Microsoft Edge (Chromium) because the driver uses the Microsoft Edge DevTools. Ensure you set the DeveloperToolsAvailability policy to 0 or 1 to automate Microsoft Edge (Chromium).

Choosing Specific Browser Binaries (Chromium-Only)

You may use the EdgeOptions class with specific binaries of Microsoft Edge (Chromium). For example, you may run tests using the Microsoft Edge preview channels such as Microsoft Edge Beta.

var options = new EdgeOptions();
options.UseChromium = true;
options.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge Beta\Application\msedge.exe";

var driver = new EdgeDriver(options);

Customizing the Microsoft Edge Driver Service

When an EdgeDriver class instance is created using EdgeOptions class, it creates and launches the appropriate EdgeDriverService class for either Microsoft Edge (EdgeHTML) or Microsoft Edge (Chromium).

If you want to create an EdgeDriverService, create one configured for Microsoft Edge (Chromium) using the CreateChromiumService() method. You may find it useful for additional customizations like enabling verbose log output in the following code.

using (var service = EdgeDriverService.CreateChromiumService())
{
    service.UseVerboseLogging = true;

    var driver = new EdgeDriver(service);
}

Note

You do not need to provide the EdgeOptions object when passing EdgeDriverService to the EdgeDriver instance. The EdgeDriver class uses the default options for either Microsoft Edge (EdgeHTML) or Microsoft Edge (Chromium) depending on the service you provide.
However, if you want to provide both EdgeDriverService and EdgeOptions classes, ensure that both are configured for the same version of Microsoft Edge. For example, it is not possible to use a default Microsoft Edge (EdgeHTML) EdgeDriverService class and Chromium properties in the EdgeOptions class. The EdgeDriver class throws an error to prevent using different versions.

Use Chromium-Specific Options

If you set the UseChromium property to true, you are able to use the EdgeOptions class to access the same Chromium-specific properties and methods as when you automate other Chromium browsers.

var options = new EdgeOptions();
options.UseChromium = true;
options.AddArgument("headless");
options.AddArgument("disable-gpu");

Note

If the UseChromium property is set to true, you are not able to use properties and methods for Microsoft Edge (EdgeHTML).

Additional WebDriver installation options

Chocolatey

If you use Chocolatey as your package manager, install the Microsoft Edge Driver by running the following command.

choco install selenium-chromium-edge-driver

For more information, see Selenium Chromium Edge Driver on Chocolatey.

Docker

If you use Docker, download a pre-configured image with Microsoft Edge (Chromium) and Microsoft Edge Driver pre-installed by running the following command.

docker run -d -p 9515:9515 mcr.microsoft.com/msedge/msedgedriver

For more information, see container on Docker Hub.

Getting in touch with the Microsoft Edge DevTools team

The Microsoft Edge team is eager to hear your feedback about using WebDriver, Selenium, and Microsoft Edge. Use the Feedback icon in the Microsoft Edge DevTools or tweet @EdgeDevTools to let the team know what you think.

The Feedback icon in the Microsoft Edge DevTools

The Feedback icon in the Microsoft Edge DevTools