Easy WebDriver management with Wix WebDriver Manager

Max Kolotilkin
Wix Engineering
Published in
3 min readJun 22, 2020

Selenium WebDriver is a common standard when it comes to web automation. This framework allows us to work with websites and web applications programmatically using real web browsers like Chrome or Firefox. Similarly Appium is an — automation framework for mobile applications. The latter was built on the same basis as Selenium, which allows you to use similar approaches when working wit either one.

Both these frameworks require launching a driver to connect to either a web browser, a mobile device or a mobile device simulator. The simplest setup looks like this:

WebDriver webDriver = new ChromeDriver();// some code here…webDriver.quit();

This code will run the Chrome browser locally with default settings. We all know that this is just the beginning, of course. Next you need to add other things, like select which browser to run, configure that browser with certain settings — like removing cookies, clearing history, specifying a download folder, setting up user profile, and so on. Besides browser configuration you might also want to add the possibility of running a remote browser in some cloud environment. Implementing all these features will basically result in creating a separate module that will be responsible for managing those browsers.

When a new automation project starts, you have to copy this module into it. While also maybe adding more stuff to satisfy all new requirements. After implementing everything, you copy your new stuff into the previous project. See a problem brewing here? Basically, just a few projects later you find yourself copying code from one class to another and trying not to forget something. That’s why we created the WebDriverManager so you could focus on developing tests instead of moving infrastructural code between projects.

Basic usage

Before going into details, let’s describe some key concepts about this module:

1. WebDriver type — type of browser to run. Alongside standard browsers like Chrome, Firefox, Safari or Edge, WebDriverManager also supports iOS and Android drivers via Appium.

2. Run on — were to run the browser. Selenium and Appium support running drivers locally on your computer or remotely on either a dedicated machine or in a cloud service (i.e. BrowserStack, SauceLabs, etc).

3. Strategy type — either NewInstance or Recycled. Used to specify if a new browser instance needs to be launched per every test (NewInstance), or if just one instance needs to be reused from test to test with clean-up procedures (Recycled).

Now that we are familiar with the concepts of the Manager, we can dive deeper into code. WebDriver Manager is available in the Maven Central repository so all you need to do is just to add it as a dependency:

<dependency>
<groupId>com.wix</groupId>
<artifactId>wix-webdriver-manager</artifactId>
<version>1.2.0</version>
</dependency>

And in your TestBase class all you need to write is this next:

WebDriverManager wdm = new WebDriverManager();
WebDriver driver = wdm.getAvailableWebDriver();
//…wdm.releaseWebDriver(driver);

Yes, it’s that easy!

A huge advantage of the Manager is that it comes with handy default configurations. If you’re developing a small project (or just testing tasks) you can use it as is without a need to spend time writing a lot of infrastructure code. And you still have all the power and possibilities to configure things the way you want, whatever you want!

Advanced usage

How do I configure WebDriver with what i need, you ask? There’s a special config class for custom configuration:

WebDriverConfig config = new WebDriverConfig.WebDriverConfigBuilder()
.withWebDriverType(“firefox”)
.withFirefoxVersion(“75”)
.withScreenResolution(“1920x1024”)
.build();
WebDriverManager wdm = new WebDriverManager(config);//…wdm.releaseWebDriver(driver);

And here’s how you can set things up to run in a cloud:

WebDriverConfig config = new WebDriverConfig.WebDriverConfigBuilder()
.withWebDriverType(“edge”)
.withScreenResolution(“1920x1024”)
.withPlatform(“Window”)
.withBinariesManager(true)
.withCloudService(“browserstack”)
.withCloudUserName(“cloud_user”)
.withCloudUserPass(“cloud_pass”)
.build();
WebDriverManager wdm = new WebDriverManager(config);//…wdm.releaseWebDriver(driver);

WebDriver Manager supports a variety of different setups. That’s not all though!

We also support mobile automation via the Appium Framework. Here the approach is the same:

WebDriverConfig config = new WebDriverConfig.WebdriverConfigBuilder()
.withWebDriverType(“ios”)
.withIOSPlatformVersion(“13”)
.withIOSDeviceName(“iPhone 11 Max”)
.withMobileApplicationPath(“/Users/username/App/myapp.app”)
.build();
WebDriverManager wdm = new WebDriverManager(config);
IOSDriver driver = wdm.getAvailableWebDriver();
// …wdm.releaseWebDriver(webDriver);

Finalizing

As you could see, the WebDriver Manager is powerful and yet easy to use tool to help you manage your web drivers in automation projects. No need to clone the repository, just add it as a dependency to your project and start playing with it right away.

In case you have any suggestions or feature request you can learn more about contributing here: https://github.com/wix/wix-webdriver-manager

--

--