javagoogle-chromeselenium-chromedriverwebdrivermanager-java

Using multiple Chrome versions with webdrivermanager fails


My issue: chromedriver and chrome versions do not match in my test runs

I use a custom docker image for my test runs (RHEL Linux). In this I install the latest version of Google Chrome rpm, and another older version of Chrome for testing. The main reason I am doing this is the Google Chrome RPM handles all the dependencies for me since the Chrome for testing only comes as a zip, but I also want to have a specific slightly older version for certain purposes (which Google chrome rpm package does not provide, it's always latest).

Google Chrome (RPM) installs in

/usr/bin/google-chrome 
/usr/bin/google-chrome -> /etc/alternatives/google-chrome
/etc/alternatives/google-chrome -> /usr/bin/google-chrome-stable

E.g. when I execute "google-chrome --version" in the docker image I get

122.0.6261.57

Chrome for testing (ZIP) gets installed in

/usr/local/opt/chrome-linux64

with:

/usr/local/bin/chrome -> /usr/local/opt/chrome-linux64/chrome
120.0.6099.109 

Furthermore, I install chromedriver for both versions in my

~/.cache/selenium/chromedriver/

so this has two subfolders with the respective versions mentioned above. And also /usr/local/bin/chromedriver is linked to the latest version (122)

Now when I run selenium with webdrivermanager, trying to use "just google-chrome" I get the following result:

INFO  @ c.d.i.w.c.CustomChromeDriverCreator | Starting the initialization of 'chrome' WebDriver instance
DEBUG @ i.g.b.w.WebDriverManager | Using WebDriverManager 5.5.3
DEBUG @ i.g.b.w.c.ResolutionCache | Created new resolution cache file at /home/jenkins/.cache/selenium/resolution.properties
TRACE @ i.g.b.w.v.VersionDetector | Reading online commands.properties to find out driver version
DEBUG @ i.g.b.w.v.VersionDetector | Detecting chrome version using online commands.properties
DEBUG @ i.g.b.w.v.Shell | Running command on the shell: [google-chrome, --version]
DEBUG @ i.g.b.w.v.Shell | Result: Google Chrome 122.0.6261.57
TRACE @ i.g.b.w.v.VersionDetector | Detected browser version is 122.0.6261.57
INFO  @ i.g.b.w.WebDriverManager | Using chromedriver 122.0.6261.57 (resolved driver for Chrome 122)
DEBUG @ i.g.b.w.c.ResolutionCache | Storing resolution chrome=122 in cache (valid until 11:49:24 22/02/2024 UTC)
DEBUG @ i.g.b.w.c.ResolutionCache | Storing resolution chrome122=122.0.6261.57 in cache (valid until 10:49:24 23/02/2024 UTC)
TRACE @ i.g.b.w.c.CacheHandler | Checking if chromedriver exists in cache
TRACE @ i.g.b.w.c.CacheHandler | Filter cache by chromedriver -- input list [/home/jenkins/.cache/selenium/chromedriver/linux64/120.0.6099.109/LICENSE.chromedriver, /home/jenkins/.cache/selenium/chromedriver/linux64/120.0.6099.109/chromedriver, /home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/LICENSE.chromedriver, /home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/chromedriver, /home/jenkins/.cache/selenium/resolution.properties] -- output list [/home/jenkins/.cache/selenium/chromedriver/linux64/120.0.6099.109/LICENSE.chromedriver, /home/jenkins/.cache/selenium/chromedriver/linux64/120.0.6099.109/chromedriver, /home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/LICENSE.chromedriver, /home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/chromedriver] 
TRACE @ i.g.b.w.c.CacheHandler | Filter cache by 122.0.6261.57 -- input list [/home/jenkins/.cache/selenium/chromedriver/linux64/120.0.6099.109/LICENSE.chromedriver, /home/jenkins/.cache/selenium/chromedriver/linux64/120.0.6099.109/chromedriver, /home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/LICENSE.chromedriver, /home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/chromedriver] -- output list [/home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/LICENSE.chromedriver, /home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/chromedriver] 
TRACE @ i.g.b.w.c.CacheHandler | Filter cache by LINUX -- input list [/home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/LICENSE.chromedriver, /home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/chromedriver] -- output list [/home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/LICENSE.chromedriver, /home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/chromedriver] 
TRACE @ i.g.b.w.c.CacheHandler | Filter cache by 64 -- input list [/home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/LICENSE.chromedriver, /home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/chromedriver] -- output list [/home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/LICENSE.chromedriver, /home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/chromedriver] 
DEBUG @ i.g.b.w.WebDriverManager | Driver chromedriver 122.0.6261.57 found in cache
INFO  @ i.g.b.w.WebDriverManager | Exporting webdriver.chrome.driver as /home/jenkins/.cache/selenium/chromedriver/linux64/122.0.6261.57/chromedriver

So webdrivermanager finds the right browser (google-chrome v122) and the matching chromedriver.

But then my tests fail with an error:

1) Error in custom provider, org.openqa.selenium.SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 122
Current browser version is 120.0.6099.109 with binary path /usr/local/bin/chrome

But according to https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver/01fde32d0ed245141e24151f83b7c2db31d596a4 the default search path should be

/usr/bin/google-chrome

so why does it pick /usr/local/bin/chrome ?

Same goes for https://github.com/bonigarcia/webdrivermanager/blob/7cb9dcf7ee66dec78230454aecac5533b5f7858a/src/main/resources/commands.properties#L11

Note: in my code I am just calling

WebDriverManager.chromedriver().setup();

I am not setting any binary path options in this case.

If the chromedriver instance was set up with the latest version (122), should it not also start that browser when being used?


Solution

  • So I finally found an approach that works:

    then the selection of both browser and matching chromedriver will work as expected with webdrivermanager (5.7.0 at least)