Selenium Tests in Kotlin: WebDriverManager

Selenium WebDriver allows controlling different types of browsers (such as Chrome, Firefox, Opera, Edge, and so on) programmatically using different programming languages (Java, Kotlin, JavaScript, Python, C#, …). Browser is driven using a native mechanism, so we need a binary file (driver) in between the test using the WebDriver API and the actual browser

WebDriver general scenario
WebDriver general scenario

The following picture shows a fine-grained diagram of the different flavour of WebDriver binaries and browsers:

WebDriver scenario for Chrome, Firefox, Opera, PhantomJS, Edge, and Internet Explorer

Concerning Kotlin, in order to locate these drivers, the absolute path of the binary controlling the browser should be exported in a given environment variable before creating a WebDriver instance, as follows:

Driver management is painful

  • Driver (chromedriver, geckodriver, etc.) must be downloaded manually for the proper platform running the test (i.e. Windows, Linux, Mac)
  • A proper driver version must match the browser version.
  • Browser is constantly updated (and drivers too).
  • Tests are not portable (different operative systems, path to driver).

Here is a simple sollution..

WebDriverManager is a Java library that allows automating the management of the binary drivers (chromedriver, geckodriver, etc.) required by Selenium

The WebDriverManager API is quite simple, providing a singleton object for each of the above-mentioned browsers:

WebDriverManager — Design

WebDriverManager — Conclusions

  • WebDriverManager is used in different projects in the Selenium ecosystem. For instance:

-> io.appium » java-client: https://github.com/appium/java-client

-> com.codeborne » selenide: https://github.com/selenide/selenide

  • WebDriverManager concept has been ported to other languages:

-> webdriver-manager (Node.js): https://github.com/angular/webdriver-manager

-> webdriver_manager (Python): https://github.com/SergeyPirogov/webdriver_manager

-> WebDriverManager.Net (.Net): https://github.com/rosolko/WebDriverManager.Net

-> Webdrivers Gem (Ruby): https://github.com/jeffnyman/webdriver_manager

References

A sample code can be found here: https://github.com/dilshan5/ui-automation-kotlin

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dilshan Fernando

Quality Engineering | Test Automation Engineer | AWS Certified Solutions Architect | Problem Solver