titusfortner / webdrivers

Keep your Selenium WebDrivers updated automatically
MIT License
593 stars 111 forks source link

Driver version cache exception for Chrome does not work #171

Closed davidstosik closed 4 years ago

davidstosik commented 4 years ago

Summary

From the README:

Special exception for chromedriver and msedgedriver

Cache time will be respected as long as a driver binary exists and the major versions of the browser and the driver match. For example, if you update Chrome or Edge to v76 and its driver is still at v75, webdrivers will ignore the cache time and update the driver to make sure you're using a compatible version.

I've just experienced a scenario where that did not happen.

Debug Info

Please provide the following information for bug reports:

Here's all the debugging data I have:

Chrome version: image

# Running rspec on a Rails project's feature spec that runs chrome driver:
$ bin/rspec spec/features/someting_spec.rb
...
     1.2) Failure/Error: spec.run
          Selenium::WebDriver::Error::SessionNotCreatedError:
            session not created: This version of ChromeDriver only supports Chrome version 81
...

$ ~/.webdrivers/chromedriver --version
ChromeDriver 81.0.4044.138 (8c6c7ba89cc9453625af54f11fd83179e23450fa-refs/branch-heads/4044@{#999})

$ ruby -r"webdrivers/chromedriver" -e "%i(latest_version chrome_version current_version required_version).each{|m|puts Webdrivers::Chromedriver.send(m)}"
81.0.4044.138
83.0.4103.61
81.0.4044.138
0

$ ruby -r"webdrivers/chromedriver" -e "puts Webdrivers::VERSION"
4.3.0

$ ruby -r"webdrivers/chromedriver" -e "puts Webdrivers::ChromeFinder.version"
83.0.4103.61

$ RAILS_ENV=test rails webdrivers:chromedriver:update
2020-05-22 13:05:42 INFO Webdrivers Updated to chromedriver 81.0.4044.138

$ cat ~/.webdrivers/chromedriver.version
81.0.4044.138

I have a hunch the ~/.webdrivers/chromedriver.version cache file was created within the last 24 hours, but cannot confirm that, as it was deleted in order to fix the problem.

Expected Behavior

Having Chrome 83.* running, while chromediver is at version 81.*, I would expect, as mentioned in the README, that the version number cache would be ignored, and chromedriver updated to its latest version 83.*, "to make sure [I'm] using a compatible version".

Actual Behavior

The following error is raised:

          Selenium::WebDriver::Error::SessionNotCreatedError:
            session not created: This version of ChromeDriver only supports Chrome version 81

Deleting ~/.webdrivers/chromedriver.version fixed the issue.

kapoorlakshya commented 4 years ago

@davidstosik Thank you for the detailed bug report. I am able to reproduce it by following your steps.

What's interesting is that we have an unit test for this exact scenario, which is passing (/spec/webdrivers/chromedriver_spec.rb:109). I haven't looked at the caching related code in a while, so I'll try to make time this weekend to debug this issue. However, a PR to fix this from you or anyone else is always welcome!

kapoorlakshya commented 4 years ago

@davidstosik I have updated the specs to catch this bug and also have a possible fix that passes the test you shared:

$ bin/console
irb(main):001:0> `cat "C:/Users/Lakshya Kapoor/.webdrivers/chromedriver.version"`
=> "81.0.4044.138"

irb(main):002:0> File.mtime "C:/Users/Lakshya Kapoor/.webdrivers/chromedriver.version"
=> 2020-05-24 19:20:10 -0700

irb(main):003:0> %i(latest_version chrome_version current_version required_version).each{ |m| puts Webdrivers::Chromedriver.send(m) }
83.0.4103.39 # latest driver version
83.0.4103.61 # my Chrome version
81.0.4044.138 # current driver version
0 # required version
=> [:latest_version, :chrome_version, :current_version, :required_version]

irb(main):004:0> Webdrivers::Chromedriver.update
=> "C:/Users/Lakshya Kapoor/.webdrivers/chromedriver.exe"

irb(main):005:0> `cat "C:/Users/Lakshya Kapoor/.webdrivers/chromedriver.version"`
=> "83.0.4103.39"

irb(main):006:0> File.mtime "C:/Users/Lakshya Kapoor/.webdrivers/chromedriver.version"
=> 2020-05-24 19:21:34 -0700

As you can see, the default cache timeout value of 24 hours was ignored and the latest compatible driver version for Chrome 83.0.4103 was downloaded. I'll push the fix to master once I'm done testing it locally.

kapoorlakshya commented 4 years ago

@davidstosik I just pushed the fix (564907d71a3969ad8bc9c50485a3c1c37ae13aa6) to master. And the specs were updated in fcea4dc29f023fe9335b101e526699d659798850. Would you mind loading the gem from the master branch and running through some tests of your own? Just want to get another set of eyes on the fix before I release it.

If everything looks good, I'll try to push out a patch release within this week.

kapoorlakshya commented 4 years ago

v4.4.0 has been released with this fix.