'How to run selenium scripts without adding chrome web driver properties every time chrome updates with latest versions

we have some selenium scripts which are configured in CI and running in chrome browser. once a while chrome browser is updated to latest versions and CI jobs are failing due to latest versions and to get back those jobs in to normal we add new chrome webdriver version in webdriver.properties file....is there a way without adding version properties every time manually. the automation script level or anything to add under pom.xml level to auto update/get properties directly without adding any properties every time manual interventions...please post any possible solutions.. FYI we are using selenium 3.12 driver version in core project.



Solution 1:[1]

I would suggest you use a Webdriver manager so it will always pick the latest chrome driver version and you don't need to put chromedriver.exe in your project and no version issue will be there. Also, it does not need any other property to set.

Code for chrome :

public void WebDriverManagerTest()
    {
        //setup the chromedriver using WebDriverManager
        WebDriverManager.chromedriver().setup();

        //Create driver object for Chrome
        WebDriver driver = new ChromeDriver();

        //Navigate to a URL
        driver.get("https://stackoverflow.com/");

        //quit the browser
        driver.quit();
    }

Please add below dependency in pom.xml :

<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>3.8.0</version>
</dependency>

Solution 2:[2]

One thing is that you can create a class and method and when you want just use class name in xml file . Which is easy but learn TestNG. Above code which is shared by @Helping Hands is also belongs to TestNG framework.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Helping Hands
Solution 2 Krishna