Chromedriver and package.json

Hello,

all discovery integration tests are falling for me with Selenium::WebDriver::Error::SessionNotCreatedError: session not created: Chrome version must be between 71 and 75 (Driver info: chromedriver=2.46.628388 (4a34a70827ac54148e092aafb70504c4ea7ae926),platform=Linux 5.2.16-200.fc30.x86_64 x86_64)

Now with help of @ezr-ondrej we’ve found that updating chromedriver to the version that matches my Google Chrome (which is currently the stable - 77) does help, however this leaves a lock file in changed state in git:

diff --git a/package.json b/package.json
index edc34d26b..21175821f 100644
--- a/package.json
+++ b/package.json
@@ -26,7 +26,7 @@
     "react-intl": "^2.8.0"
   },
   "optionalDependencies": {
-    "chromedriver": "2.46.0"
+    "chromedriver": "^77.0.0"
   },
   "devDependencies": {
     "@storybook/addon-actions": "~3.4.12",

Questions:

  • Is there a way to override values in package.json? Can we implement such thing so people can freely override it just like we do this for Ruby bundler?
  • What is our update strategy for this dependency? Is it pinned because of particular Chrome version on our CI infra? Or is there a different reason? If not let’s remove the pin and install latest stable version which will most likely match for the most people and pin it manually on CI.

Thank you for bringing that up @lzap.

Yes! You can use the enviorment variable:

Not sure about the update strategy or why it is pinned but it makes sense to update it.

Thanks @sharvit.

But this will still update the package.json to version you define, right?
We do not want to force people to use one version of chrome as it shouldn’t matter, right?
I would like to come up with a solution which would enable decent freedom in chrome version.

There is a official way how to get the right chrome-driver:

That seems as bit of an overkill to me :thinking:

No, the version installed by npm doesn’t contain the actual driver but some code that can handle downloading the driver.
Once you define the env var and run npm install, it will use a postinstall that will download the driver based on your env var (or from cache, or latest).

You should be able to achieve that without updating the package.json

Shouldn’t you rather use dnf install chromedriver when you’re on Fedora? Can NPM use this? The docs suggest you can: https://github.com/giggio/node-chromedriver#skipping-chromedriver-download

You will still need to know what version of the driver to download. The npm package contain the code that allow you to use download the version you need.

Can’t we use the latest stable version of the wrapper and let the native system packages handle the actual chromedriver package? On Fedora they ensure it’s in sync with chromium so you don’t have to worry about it. At least for the average developer on Fedora that sounds like a much more stable and secure solution.

1 Like

Google Chrome is not part of Fedora repositories. Chromium is, if we can make it that it uses Chromium by default I am happy to install it.

I agree that could be a nice solution. If there is a fallback to download it from CDN I would go ahead and try look for the system chromedriver first.

Chromedriver should use Chromium no problem.

So it looks like the Fedora package chromedriver actually uses chromium-headless to do the job. Nice, let me try this:

$ sudo dnf install chromedriver
$ rm -rf node_modules/
$ npm install
Done. ChromeDriver binary available at /home/lzap/work/foreman/node_modules/chromedriver/lib/chromedriver/chromedriver

> node-sass@4.12.0 install /home/lzap/work/foreman/node_modules/node-sass
> node scripts/install.js

Cached binary found at /home/lzap/.npm/node-sass/4.12.0/linux-x64-64_binding.node

As you can see, unfortunately it is not picking it up. We should make it so it always prefer chromedriver from the OS which will be more likely to be on par with the browser version. How to do that?

Looks like TESTDRIVER_PATH=/usr/bin/chromedriver should do it. And it indeed does work fine. So here is the solution:

If you export CHROMEDRIVER_SKIP_DOWNLOAD=true or add chromedriver_skip_download=true to ~/.npmrc, does it skip downloading and automatically pick up the system wide version?

1 Like

I don’t think so, the Fedora path is pretty much hidden: /usr/lib64/chromium-browser/chromedriver but it works for me now so I won’t bother.

The documentation said it would look in $PATH and /usr/bin/chromedriver does exist so I’d expect it to work.

1 Like

Well it was not working for me. Probably old npm version, the helper env variable does help.

Looks like this is now failing integration tests on core PRs, e.g.:
https://ci.theforeman.org/job/test_develop_pr_core/2368/database=postgresql-integrations,ruby=2.5,slave=fast/testReport/junit/(root)/AboutIntegrationTest/test_0001_about_page/

@infra - Was there a recent update on jenkins workers that installed a new chromium? @ui_ux - what should be done to make sure we are always running with a compatible version?
We need to figure out how to fix this properly as it is currently blocking PR testing.

This is also causing foreman-develop-source-release to fail, meaning we are not able to build nightlies with latest code until this is fixed.

https://projects.theforeman.org/issues/28028

I opened a pr to upgrade the version of chrome driver and hopefully get tests running again, but we should fix this properly in a way that doesn’t break next time a new chromium version is released:
https://github.com/theforeman/foreman/pull/7099

1 Like