We've been running integration tests successfully against Rails 2 using Selenium on both chrome and firefox. However, we've recently upgraded to Rails 3 and are running into issues creating a chrome webdriver instance.
When we attempt to create, we get the following stack:
irb(main):002:0> profile = Selenium::WebDriver::Chrome::Profile.new
translate])#<Selenium::WebDriver::Chrome::Profile:0x64f2fd0 #extensions=[], #model=nil>
irb(main):003:0> profile['download.prompt_for_download'] = false
false
irb(main):004:0> driver = Selenium::WebDriver.for(:chrome, :profile => profile, :switches => %w[--ignore-certificate-errors --disable-popup-blocking --disable-translate])
ArgumentError: wrong number of arguments (0 for 1)
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/platform.rb:157:in `open'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/platform.rb:157:in `ip'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/platform.rb:170:in `interfaces'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/port_prober.rb:23:in `free?'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/port_prober.rb:5:in `above'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/chrome/service.rb:33:in `default_service'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/chrome/bridge.rb:14:in `initialize'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/driver.rb:37:in `new'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/driver.rb:37:in `for'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver.rb:67:in `for'
from (irb):4
Any tips?
I saw this when I had included a gem which included the "backports" gem as part of its dependencies into my Gemfile. The backports gem rewrites some Ruby 1.8 internals, which overwrote parts of the UDPSocket core class. Try getting rid of the backports gem and giving it a shot.
ChromeDriver Installation:
Download Chromedriver 2.x from "http://chromedriver.storage.googleapis.com/index.html?path=2.8/." Unzip it and save it in a folder on any drive. Set path by following steps :
Copy the path till chromedriver.exe
Right click on Computer and select ‘Properties’
Select ‘Advanced system variables’
Select ‘Environment variables’
Click on Edit button for ‘Path’ variable of ‘User variables’
Append the chromedriver path
Save changes.
Run Selenium Test :
Now run your selenium test. It will run on the chrome browser.
Sample Code
require 'selenium-webdriver'
$driver = Selenium::WebDriver.for :chrome
$driver.navigate.to "https://www.google.co.in/"
$driver.manage().window().maximize()
$driver.quit()
NOTE : You need to install latest chromedriver for latest version of Chrome browser
This was caused by an interference with the backports gem and the fact that the socket library reuses IO.open although it changes the interface.
Upgrading backports to v2.6.7 or above should resolve this.
Related
I'm running Ubuntu 16.04 and I'm trying to run a headless Chrome browser in ruby with chromedriver.
I've installed chromedriver on Ubuntu using these instructions and then I run this via the ruby irb console:
require 'selenium-webdriver'
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
#driver = Selenium::WebDriver.for(:chrome, options: options)
Traceback (most recent call last):
10: from /home/weefee/.rvm/rubies/ruby-2.5.1/bin/irb:11:in `<main>'
9: from (irb):5
8: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver.rb:86:in `for'
7: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/driver.rb:44:in `for'
6: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/driver.rb:44:in `new'
5: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/chrome/driver.rb:44:in `initialize'
4: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/service.rb:69:in `start'
3: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/socket_lock.rb:39:in `locked'
2: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/service.rb:72:in `block in start'
1: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/service.rb:142:in `connect_until_stable'
Selenium::WebDriver::Error::WebDriverError (unable to connect to chromedriver 127.0.1.1:9515)
Any idea on how to fix it? A few notes:
Some people seem to encounter issues with rbenv and the shim that it sets up. I'm not using rbenv at all, so that's irrelevant here.
The above works when I try it on my OSx laptop. Of course there I can easily install chromedriver with brew install chromedriver and it just seems to work
Alternatively, I uninstalled chromedriver and re-installed it using the chromedriver-helper gem. Still the same result.
I've been tearing my hair out for a while on this - any help would be appreciated. Thanks!
UPDATE
I dug deeper into the source of the selenium-webdriver gem to see exactly what it was doing when trying to connect to the chromedriver process.
I was able to replicate the following in my ruby console on the server using the same commands the selenium-webdriver gem uses:
#
# Start the Chromedriver Process
#
require 'childprocess'
process = ChildProcess.build(*["/usr/local/bin/chromedriver", "--port=9515"])
process.leader = true
process.alive? #=> false
process.start
process.alive? #=> true
#
# Create a Socket connection to 127.0.0.1:9515
#
require 'socket'
require 'selenium-webdriver'
host = Selenium::WebDriver::Platform.localhost #=> "127.0.1.1"
port = Integer(Selenium::WebDriver::Chrome::Service::DEFAULT_PORT) #=> 9515
timeout = 5
# Create and connect to socket
addr = Socket.getaddrinfo(host, port, Socket::AF_INET, Socket::SOCK_STREAM)
sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
sockaddr = Socket.pack_sockaddr_in(port, addr[0][3])
# First need to rescue the writable error and then connect again
# to get the actual error. No idea why but even the official
# rubydocs use this pattern: https://apidock.com/ruby/Socket/connect_nonblock
begin
sock.connect_nonblock(sockaddr)
rescue IO::WaitWritable
IO.select(nil, [sock], nil, 5)
sock.connect_nonblock(sockaddr)
end
#=> Errno::ECONNREFUSED (Connection refused - connect(2) for 127.0.1.1:9515)
So it seems the core error is that the socket refuses to connect on that (local) address and port, even though chromedriver is very much running on that port.
I don't know much about sockets at all - is this a common error?
Thanks!
I have tried it on the Ubuntu 16.04 (updated) and ruby which comes with the system ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu].
From what I guess is that you are using wrong, old (in the guide there is version 2.26 which will not work with current chrome), chromedriver, which is not compatible with the current stable chrome.
The current stable chrome is Unpacking google-chrome-stable (71.0.3578.98-1) ... and so you need to get chromedriver as close as possible to the chrome version.
To get complete list of chromedrivers' versions click here.
In my case that would be a 71.0.3578.80 version:
wget -N http://chromedriver.storage.googleapis.com/71.0.3578.80/chromedriver_linux64.zip
You can then continue as shown at the instructions.
Then you will get working selenium-webdriver:
irb
irb(main):001:0> require 'selenium-webdriver'
=> true
irb(main):003:0> options = Selenium::WebDriver::Chrome::Options.new
=> #<Selenium::WebDriver::Chrome::Options:0x00000002ee6db0 #args=#<Set: {}>, #binary=nil, #prefs={}, #extensions=[], #options={}, #emulation={}, #encoded_extensions=[]>
irb(main):004:0> options.add_argument('--headless')
=> #<Set: {"--headless"}>
irb(main):005:0> #driver = Selenium::WebDriver.for(:chrome, options: options)
=> #<Selenium::WebDriver::Chrome::Driver:0x..f95c429ee62a3a152 browser=:chrome>
Note: If you have issues installing ffi install libffi-dev via apt-get.
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get --only-upgrade install google-chrome-stable
This will keep your version up to date and available. I have had this solve similar problems that were encountered during CI testing. You should be able to setup your #driver afterwards.
from this line:
Selenium::WebDriver::Error::WebDriverError (unable to connect to chromedriver 127.0.1.1:9515)
it suggests you are trying to connect to 127.0.1.1, while your localhost should be 127.0.0.1, could you check your configuration?
All the provided solutions were great recommendations, but ultimately tukan's answer led me down the path of carefully checking versions.
The setup I had didn't work on Ubuntu 14.04, which is about 5 years old at the time of this writing. I re-built the whole thing on an Ubuntu 16.04 machine and it worked perfectly.
I don't know what causes the error, but it seems to be something at the operating system level.
I have this code in my Cucumber Hooks file to run the ghost driver it was working until yesterday I start seeing the error message:
Before do
Selenium::WebDriver::PhantomJS.path = 'C:\phantomjs-2.1.1-windows\bin\phantomjs.exe'
#browser = Watir::Browser.start "https://www.google.com", :phantomjs
#browser.window.maximize
end
Error message:
LoadError: cannot load such file -- selenium/webdriver/phantomjs
Yes, we've removed support for PhantomJS as of Selenium 3.8.
The PhantomJS project is no longer being maintained. If you actually do need headless, please investigate either the Chrome or Firefox headless options.
For those who encounter this error, you can work around it by locking your selenium-webdriver version in your Gemfile like so:
gem 'selenium-webdriver', '~> 3.6.0'
and then bundle update to downgrade.
(You may not even have selenium-webdriver specified in your Gemfile currently if it's just being loaded as a dependency of watir or some other library.)
The long term fix, of course, is to move off of PhantomJS to Chrome or Firefox headless.
I'm using Cucumber with Capybara and Selenium-Webdriver. Until now, I've always used Chrome but the project has requested some cross browser tests for Firefox too.
When running in Firefox, I just get a blank window and webpage doesn't appear.
This is the error I get:
Selenium::WebDriver::Error::WebDriverError: no sessionId in returned payload
My setup is:
Firefox V54
Cucumber 2.4
Selenium-webdriver 3.4.0
geckodriver 0.17
My firefox profile:
if ENV['firefox']
Capybara.default_driver = :selenium
Capybara.register_driver :selenium do |app|
options = {
:js_errors => false,
}
Capybara::Selenium::Driver.new(app, :browser => :firefox)
end
Any ideas why I only get a blank window when Firefox starts up in the test?
You claim to be running geckodriver v0.17 (which should work with the other versions you list) however that error would imply you're not. Try running bundle exec geckodriver --version and seeing what it returns. I'm guessing you've got a gem installed that attempts to manage the download of geckodriver and an older version is actually being used when you run your tests. If that is the case check with the specific gem documentation on how to update the installed geckodriver.
I am attempting to run the following ruby code via RubyMine:
require 'rubygems'
require 'watir-webdriver'
browser = Watir::Browser.new :firefox
browser.goto 'http://www.apple.com'
When I run I get the following error:
firefox connection in 60 seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError)
from /Users/mark/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/firefox/launcher.rb:55:in block in launch'
from /Users/mark/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/socket_lock.rb:43:inlocked'
from /Users/mark/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/firefox/launcher.rb:51:in launch'
from /Users/mark/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/firefox/bridge.rb:43:ininitialize'
from /Users/mark/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/driver.rb:53:in new'
from /Users/mark/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/driver.rb:53:infor'
from /Users/mark/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver.rb:84:in for'
from /Users/mark/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/browser.rb:46:ininitialize'
from /Users/mark/cheezy/first_script.rb:3:in new'
from /Users/mark/cheezy/first_script.rb:3:in'
from -e:1:in load'
from -e:1:in'
I have the latest Watir-Webdriver gem installed .
Any ideas please?
Thanks
For Firefox 48+ you need to use geckodriver.
Download from here: https://github.com/mozilla/geckodriver/releases
Selenium instructions: https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver
Watir instructions: http://watir.github.io/watir-6-beta/
Please let me know if you have any further issues.
I am trying to get cucumber tests to run on our headless centOS box.
I have installed Xvfb, firefox, and my test suite, which functions on our non-headless(headed?) machines.
Versions
CentOS: 6.2
firefox: 23.0.1
headless: 1.0.1
selenium-webdriver: 2.35.0
watir-webdriver: 0.6.4
ruby: 1.9.3
In irb:
1.9.3-p448 :001 > require 'watir-webdriver'
=> true
1.9.3-p448 :002 > require 'headless'
=> true
1.9.3-p448 :004 > headless = Headless.new
=> #<Headless:0x000000025e0860 #display=99, #autopick_display=true, #reuse_display=true, #dimensions="1280x1024x24", #video_capture_options={}, #destroy_at_exit=true>
1.9.3-p448 :005 > headless.start
=> #<Proc:0x000000025e5180#/usr/local/rvm/gems/ruby-1.9.3-p448/gems/headless-1.0.1/lib/headless.rb:175>
1.9.3-p448 :006 > b = Watir::Browser.new(:firefox)
Selenium::WebDriver::Error::WebDriverError: unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/firefox/launcher.rb:79:in `connect_until_stable'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/firefox/launcher.rb:37:in `block in launch'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/firefox/socket_lock.rb:20:in `locked'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/firefox/launcher.rb:32:in `launch'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/firefox/bridge.rb:24:in `initialize'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/common/driver.rb:31:in `new'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/common/driver.rb:31:in `for'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver.rb:67:in `for'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/watir-webdriver-0.6.4/lib/watir-webdriver/browser.rb:46:in `initialize'
from (irb):6:in `new'
from (irb):6
from /usr/local/rvm/rubies/ruby-1.9.3-p448/bin/irb:13:in `<main>'
I have the same issue when trying to run the tests (this is just easier to reproduce).
I checked out the other questions here, but I am already using the latest version. According to the changelog they support firefox 23. Does anyone have any ideas? Thanks in advance!
UPDATE 8/28/2013 0900:
I was getting this error when I tried to run Xvfb.
[dix] Could not init font path element catalogue:/etc/X11/fontpath.d, removing from list!
[dix] Could not init font path element built-ins, removing from list!
I fixed it by using
yum -y install libXfont
But I am still getting the same error.
UPDATE 8/28/2013 0930:
As per TDHM's suggestion, I downgraded firefox to 17.0.8 by running
yum downgrade firefox
But I am still getting the same error.
A co-worker of mine managed to fix the issue.
Run this line of code:
$ dbus-uuidgen > /var/lib/dbus/machine-id
And the problem is fixed. This is the source for the fix
I'm not sure, but see if downgrading Firefox version works. Because many times latest version of Selenium has problems with latest browser versions.