Learn Selenium- Let WebDriverManager Manage Your Browser’s Driver Executable

To launch a browser using Selenium WebDriver, we must need to download browser’s driver executable file and need to setup its path. You are responsible to run your scripts on any platform and any system. You may need to keep updating browser driver executable files. It is really hectic to manage if your scripts are running on different machines with different platform and browser versions.

System.setProperty(webdriver.chrome.driver, /path/to/binary/chromedriver); System.setProperty(webdriver.gecko.driver, /path/to/binary/geckodriver);

WebDriverManager is a Java library which allows to automate the management of the binary drivers (e.g. chromedrivergeckodriver, etc.) required by Selenium WebDriver. Remember it is not provided by Selenium WebDriver. We need to integrate Selenium Webdriver and  WebDriverManager.

In order to use WebDriverManager from tests in a Maven project, you need to add the following dependency in your pom.xml (Java 8 or upper required):

<dependency>

<groupId>io.github.bonigarcia</groupId>

<artifactId>webdrivermanager</artifactId>

<version>3.4.0</version>

<scope>test</scope>

</dependency>

If you want to launch Chrome, just add below line before launching browser:-

WebDriverManager.chromedriver().setup();

Other supported browsers are:-

WebDriverManager.chromedriver().setup();
WebDriverManager.firefoxdriver().setup();
WebDriverManager.operadriver().setup();
WebDriverManager.phantomjs().setup();
WebDriverManager.edgedriver().setup();
WebDriverManager.iedriver().setup();

Java Program:-

public class ChromeLaunch {

    private WebDriver driver;

    @BeforeMethod
    public static void setupClass() {
        WebDriverManager.chromedriver().setup();
        driver = new ChromeDriver();
    }

    @Test
    public void test() {
       driver.get("https://atablogs.agiletestingalliance.org/");

    }

    @After
    public void teardown() {
        if (driver != null) {
            driver.quit();
        }
    }

}

 

 

#HapyLearning

If you want to participate in #ATAGTR2019 QuizATAhon – do not miss to visit the following page

https://gtr.agiletestingalliance.org/quizatahon.html

Leave a Reply