user3158314
user3158314

Reputation: 107

Issue with attempting to run a test using chromedriver

I am currently having an issue when attempting to run a Ruby test using chromedriver.

I am using selenium-webdriver 3.14.0, cucumber 3.1.2, Windows 10

Whenever I run my tests using firefox, they load and run fine without any issues. However as soon as I change one of them to using chromedriver and attempt to run it, I get the following error:

unable to connect to chromedriver 127.0.0.1:9515

I have chromedriver located on my PATH and am using the following code to attempt to initialise the driver inside the ruby code:

require 'selenium-webdriver'

options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--ignore-certificate-errors')
options.add_argument('--disable-popup-blocking')
options.add_argument('--disable-translate')

driver1 = Selenium::WebDriver.for :chrome, options: options

Given (/^we navigate to the Timesheets area$/) do
driver1.navigate.to "test"
driver1.find_element(:id, 'EmailAddress').send_keys("test")
driver1.find_element(:id, 'Password').send_keys("test")
driver1.find_element(:css, 'button').click
wait = Selenium::WebDriver::Wait.new(:timeout => 5)
begin
    element = wait.until { driver1.find_element(:class => "name") }
end
    driver1.find_element(:css, 'i.fa.fa-clock-o').click
    begin
    element = wait.until { driver1.find_element(:class => "pull-left") }
    expect(element.text).to eq('Timesheets')
    end
end

    en (/^we click the Add New Timesheet Button$/) do
    driver1.find_element(:css, 'a.pull-right').click
   end

Then (/^we should be taken to the Add New Timesheet Page$/) do
wait = Selenium::WebDriver::Wait.new(:timeout => 5)
begin
    element = wait.until { driver1.find_element(:css => "h1.pull-left") }
    expect(element.text).to eq('Add Timesheet')
ensure
    driver1.quit
end
end

Any help that can be given on this would be appreciated

EDIT: Updated with Full error stacktrace:

unable to connect to chromedriver 127.0.0.1:9515 
(Selenium::WebDriver::Error::WebDriverError)
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver- 
3.14.0/lib/selenium/webdriver/common/service.rb:142:in `connect_until_stable'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3 
3.14.0/lib/selenium/webdriver/common/service.rb:72:in `block in start'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver- 
3.14.0/lib/selenium/webdriver/common/socket_lock.rb:39:in `locked'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver- 
3.14.0/lib/selenium/webdriver/common/service.rb:69:in `start'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver- 
3.14.0/lib/selenium/webdriver/chrome/driver.rb:43:in `initialize'
 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver- 
3.14.0/lib/selenium/webdriver/common/driver.rb:44:in `new'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver- 
3.14.0/lib/selenium/webdriver/common/driver.rb:44:in `for'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver- 
3.14.0/lib/selenium/webdriver.rb:86:in `for'
C:/Ruby25-x64/features/step_definitions/timesheet_steps.rb:9:in `<top 
(required)>'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber- 
3.1.2/lib/cucumber/glue/registry_and_more.rb:107:in `load'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber- 
3.1.2/lib/cucumber/glue/registry_and_more.rb:107:in `load_code_file'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber- 
3.1.2/lib/cucumber/runtime/support_code.rb:144:in `load_file'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber- 
3.1.2/lib/cucumber/runtime/support_code.rb:85:in `block in load_files!'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber- 
3.1.2/lib/cucumber/runtime/support_code.rb:84:in `each'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber- 
3.1.2/lib/cucumber/runtime/support_code.rb:84:in `load_files!'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber- 
3.1.2/lib/cucumber/runtime.rb:272:in `load_step_definitions'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber- 
3.1.2/lib/cucumber/runtime.rb:68:in `run!'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber- 
3.1.2/lib/cucumber/cli/main.rb:34:in `execute!'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-3.1.2/bin/cucumber:9:in `<top 
(required)>'
 C:/Ruby25-x64/bin/cucumber:23:in `load'
 C:/Ruby25-x64/bin/cucumber:23:in `<main>'

EDIT 2: Im now using Watir which uses Chrome by default. I am using the Interactive Ruby Console by using irb in the Command Prompt.

The only commands I ran are:

 require "Watir"
 b = Watir::Browser.new

I then get the following stacktrace:

Traceback (most recent call last):
   12: from C:/Ruby25-x64/bin/irb.cmd:19:in `<main>'
   11: from (irb):3
   10: from (irb):3:in `new'
    9: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/watir-6.12.0/lib/watir/browser.rb:48:in `initialize'
    8: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver.rb:86:in `for'
    7: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/common/driver.rb:44:in `for'
    6: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/common/driver.rb:44:in `new'
    5: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/chrome/driver.rb:43:in `initialize'
    4: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/common/service.rb:69:in `start'
    3: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/common/socket_lock.rb:39:in `locked'
    2: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/common/service.rb:72:in `block in start'
    1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.14.0/lib/selenium/webdriver/common/service.rb:142:in `connect_until_stable'
Selenium::WebDriver::Error::WebDriverError (unable to connect to chromedriver 127.0.0.1:9515)

Am I missing something as I have the ChromeDriver set in the Path so in my head it should run without any issues as Firefox runs like a charm

Upvotes: 1

Views: 1681

Answers (4)

Luka Vladika
Luka Vladika

Reputation: 76

please check if any chromedriver instance is already running and then kill it if so, you can try running this command in command prompt, or check manually in task manager

tasklist /v | find "chromedriver"

then set path to chromedriver in your tests, this worked for me on Windows 10

require 'watir'            
chromedriver_path = 'c:\tmp\asd\chromedriver.exe'
#interestingly, this also works
#chromedriver_path = "/tmp/asd/chromedriver.exe"
Selenium::WebDriver::Chrome.driver_path= chromedriver_path  

begin    

  puts "Opening browser." 
  b = Watir::Browser.new :chrome     
  b.goto "www.google.com"  
  puts "Navigate to google, title is #{b.title}"
  b.text_field(:id => "lst-ib").set "hope this works"
  puts "setting search parameters "

rescue => e
  puts "error happened: #{e.backtrace.inspect}, #{e.class}, #{e.message}"  
ensure
 b.close unless b.nil? 
end

If that doesn't work, again check if any chromedriver is running, and then run it yourself manually from command line, it should produce output like this

C:\tmp\asd>chromedriver.exe
Starting ChromeDriver 2.41.578737 on port 9515

And then run your tests.

I found it useful to set path to chromedriver before each test, this way you could have dozens of chromedrivers in a folder, and then pass the argument to the test, which chromedriver to use.

Hope it works, or at least gives new error to work with.

edit:

in folder where you downloaded chromedriver.exe, type these

chromedriver.exe --version

gem list watir

gem list selenium-webdriver

uninstall old versions of gems if there are any, then go to irb and type these one by one

require 'watir' 
Selenium::WebDriver::Chrome.driver_path= '/tmp/asd/chromedriver.exe'
Selenium::WebDriver::Chrome.path = '/Program Files (x86)/Google/Chrome/Application/chrome.exe'
b = Watir::Browser.new :chrome

put your paths ofcourse and paste here what error you get, also versions of chrome, driver, ruby, watir, selenium and windows. I'm not sure if cucumber has anything to do with this, it shouldn't if youre having problems even from irb.

Its just a hunch, but also check ENV variables or PATH if anything is out of ordinary.

Upvotes: 0

titusfortner
titusfortner

Reputation: 4194

Use webdrivers.gem to automatically keep your drivers up to date. PATH can get complicated, so the webdrivers gem ignores it and specifies the location that Selenium should look for the drivers independently. It also does not use shims like chromedriver-helper does, so it won't muck with any system settings. Just add the gem to your gemfile/gemspec and then require 'webdrivers' in your code.

Upvotes: 1

Alexey Spiridonov
Alexey Spiridonov

Reputation: 93

Try to use chromedriver-helper gem.

Upvotes: 0

sayhan
sayhan

Reputation: 1184

The problem is about old version of Chromedriver. Some of Selenium versions can not handle old versions of chromedriver.

Please update or install latest gem.

Upvotes: 0

Related Questions