Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chromedriver now checks Selenium::WebDriver::Chrome#path. #39

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ rvm:
- 2.4.1
- jruby-9.2.0.0
addons:
chrome: stable
chrome: stable

before_script:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install chromium-browser libgconf-2-4 ; fi
64 changes: 53 additions & 11 deletions lib/webdrivers/chromedriver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@ class Chromedriver < Common
class << self

def current_version
Webdrivers.logger.debug "Checking current version"
Webdrivers.logger.debug 'Checking current version'
return nil unless downloaded?
string = %x(#{binary} --version)
Webdrivers.logger.debug "Current version of #{binary} is #{string}"
normalize string.match(/ChromeDriver (\d+\.\d+)/)[1]

ver = `#{binary} --version`
Webdrivers.logger.debug "Current #{binary} version: #{ver}"

# Matches 2.46, 2.46.628411 and 73.0.3683.75
normalize ver[/\d+\.\d+(\.\d+)?(\.\d+)?/]
end

def latest_version
raise StandardError, "Can not reach site" unless site_available?
raise StandardError, 'Can not reach site' unless site_available?

# Versions before 70 do not have a LATEST_RELEASE file
return Gem::Version.new('2.46') if release_version < '70.0.3538'

# Latest webdriver release for installed Chrome version
release_file = "LATEST_RELEASE_#{release_version}"
latest_available = get(URI.join(base_url, release_file))
Webdrivers.logger.debug "Latest version available: #{latest_available}"
Gem::Version.new(latest_available)
end

Expand Down Expand Up @@ -68,23 +75,58 @@ def chrome_version
raise NotImplementedError, 'Your OS is not supported by webdrivers gem.'
end.chomp

if ver.nil? || ver.empty?
raise StandardError, 'Failed to find Chrome binary or its version.'
end

# Google Chrome 73.0.3683.75 -> 73.0.3683.75
ver[/(\d|\.)+/]
end

def chrome_on_windows
reg = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
ps = "(Get-Item (Get-ItemProperty '#{reg}').'(Default)').VersionInfo.ProductVersion"
`powershell #{ps}`
if browser_binary
Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
return `powershell (Get-ItemProperty '#{browser_binary}').VersionInfo.ProductVersion`
end

# Default to Google Chrome
reg = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
kapoorlakshya marked this conversation as resolved.
Show resolved Hide resolved
executable = `powershell (Get-ItemProperty '#{reg}' -Name '(default)').'(default)'`.strip
Webdrivers.logger.debug "Browser executable: '#{executable}'"
ps = "(Get-Item (Get-ItemProperty '#{reg}').'(default)').VersionInfo.ProductVersion"
`powershell #{ps}`.strip
end

def chrome_on_linux
`google-chrome --version`
if browser_binary
Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
return `#{browser_binary} --product-version`.strip
end

# Default to Google Chrome
executable = `which google-chrome`.strip
Webdrivers.logger.debug "Browser executable: '#{executable}'"
`#{executable} --product-version`.strip
end

def chrome_on_mac
loc = Shellwords.escape '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
`#{loc} --version`
if browser_binary
Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
return `#{browser_binary} --version`.strip
end

# Default to Google Chrome
executable = Shellwords.escape '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
Webdrivers.logger.debug "Browser executable: #{executable}"
`#{executable} --version`.strip
end

#
# Returns user defined browser executable path from Selenium::WebDrivers::Chrome#path.
#
def browser_binary
# For Chromium, Brave, or whatever else
Selenium::WebDriver::Chrome.path
end
end
end
Expand Down
24 changes: 20 additions & 4 deletions spec/chromedriver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,45 @@
chromedriver.remove
chromedriver.download
cur_ver = chromedriver.current_version.version
latest_ver = chromedriver.latest_version.version[0..3] # "72.0.3626.69" - > "72.0"
latest_ver = chromedriver.latest_version.version
expect(cur_ver).to eq latest_ver
end

it 'downloads specified version by Float' do
chromedriver.remove
chromedriver.version = 2.29
chromedriver.download
expect(chromedriver.current_version.version).to eq '2.29'
expect(chromedriver.current_version.version).to include '2.29'
end

it 'downloads specified version by String' do
chromedriver.remove
chromedriver.version = '74.0.3729.6'
chromedriver.version = '73.0.3683.68'
chromedriver.download
expect(chromedriver.current_version.version).to eq '74.0'
expect(chromedriver.current_version.version).to eq '73.0.3683.68'
end

it 'removes chromedriver' do
chromedriver.remove
expect(chromedriver.current_version).to be_nil
end

if Selenium::WebDriver::Platform.linux? && ENV['TRAVIS']
# Ubuntu 14.04 (trusty) is limited to v65
context 'when using a Chromium version < 70.0.3538' do
before do
chromedriver.remove
chromedriver.version = nil
Selenium::WebDriver::Chrome.path = `which chromium-browser`.strip
end

it 'downloads chromedriver 2.46' do
chromedriver.update
expect(chromedriver.current_version.version[/\d+.\d+/]).to eq('2.46')
end
end
end

context 'when offline' do
before { allow(chromedriver).to receive(:site_available?).and_return(false) }

Expand Down