Recently I have installed gem 'webdrivers', '~> 4.0'
and trying to launch a chrome browser. But it's not working.
Code:
@app = Driver.new(Capybara::Session.new(:selenium_chrome))
Webdrivers::Chromedriver.current_version
Error log:
An error occurred while loading ./spec/login_spec.rb.
Failure/Error: require_relative '../pages/nav_bar.rb'
SyntaxError:
/Users/madhan_kumaravel/.rvm/gems/ruby-2.2.8/gems/webdrivers-4.1.2/lib/webdrivers/chrome_finder.rb:83: syntax error, unexpected '.'
....VersionInfo.ProductVersion")&.strip
... ^
/Users/madhan_kumaravel/.rvm/gems/ruby-2.2.8/gems/webdrivers-4.1.2/lib/webdrivers/chrome_finder.rb:87: syntax error, unexpected '.'
System.call(location, '--product-version')&.strip
^
/Users/madhan_kumaravel/.rvm/gems/ruby-2.2.8/gems/webdrivers-4.1.2/lib/webdrivers/chrome_finder.rb:91: syntax error, unexpected '.'
System.call(location, '--version')&.strip
As Marek mentioned in the comments, the gem is using the safe navigation operator which is only available in Ruby 2.3 and above. Either upgrade to Ruby 2.3 or downgrade webdrivers to 3.9.4, e.g. gem 'webdrivers', '~> 4.0'
.
I looked through the code for 3.9.4 and they don't seem to use the safe navigation operator, so it's worth giving a shot.