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.
Related
I can not run ruby scripts on digital-ocean droplet. I tried running with selenium-webdriver and watir gems, but doesn't work.
I tried running with different versions of chromedriver, changed also selenium-webdriver's gem versions, but didn't work.
My ruby -v: ruby 2.3.1p112
selenium-webdriver -v: (3.141.0)
Chromedriver -v: 2.46
require 'selenium-webdriver'
options = Selenium::WebDriver::Chrome::Options.new(args: ['start-maximized','disable-gpu', 'no-sandbox', 'disable-setuid-sandbox', 'disable-dable-dev-shm-usage'], binary: ('/bin/chromedriver'))
options.headless!
driver = Selenium::WebDriver.for(:chrome, options: options)
Error I get:
/usr/share/rvm/gems/ruby-2.3.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok': unknown error: Chrome failed to start: exited abnormally (Selenium::WebDriver::Error::UnknownError)
unknown error: DevToolsActivePort file doesn't exist)
Thanks for attention!
This is how I get Chrome to run in headless mode:
options = Selenium::WebDriver::Chrome::Options.new(args: ['headless'])
driver = Selenium::WebDriver.for :chrome, options: options
You are passing some of the args through incorrectly, headless mode should be included. You also shouldn't need binary: ('/bin/chromedriver') if your chromedriver.exe is added to your PATH correctly.
So for your above example, the following should work:
options = Selenium::WebDriver::Chrome::Options.new(args: ['headless',
'start-maximized','disable-gpu', 'no-sandbox', 'disable-setuid-sandbox',
'disable-dable-dev-shm-usage'])
driver = Selenium::WebDriver.for :chrome, options: options
Hope this helps,
Dan
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 get the error: unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) when I run this code:
require 'watir-webdriver'
require 'headless'
headless = Headless.new
headless.start
begin
browser = Watir::Browser.start "https://google.com"
rescue Exception => e
puts e
puts "Exiting..."
exit
end
browser.goto "http://google.com"
puts browser.url
browser.close
I am using: I am using Firefox version 38.7.0, Headless gem version 2.2.3 and Selenium-Webdriver gem version 2.53.0.
I have tried:
Updating selenium-webdriver
Uninstalling headless, selenium and Firefox and reinstalling
them.
Restarting the server
Updating Firefox to 45.0
The same code works fine in other test environments.
Updates:
I have tried running the same code with Chrome as suggested by a poster. I got the error message: unable to connect to chromedriver 127.0.0.1:9515
Just to be sure everything is installed right I just ran the following:
yum install xorg-x11-server-Xvfb
Response:
Package xorg-x11-server-Xvfb-1.15.0-36.el6.centos.x86_64 already installed and latest version
Nothing to do
I also ran:
yum install firefox
Response:
Package firefox-38.7.0-1.el6.centos.x86_64 already installed and latest version
Nothing to do
So it turns out that it was a user rights issue that was causing the problem. I logged in as the root user and was pleasantly surprised to see that the code ran without any errors.
I have Rails 4.2 app, using bundler, rvm.
Added capybara and selenium-webdriver to Gemfile, bundle install ok.
I wrote small class that use selenium for some purpose:
require 'capybara'
class GoogleSite
include Capybara::DSL
def initialize
Capybara.default_driver = :selenium
end
def find_all(param)
url = 'https://google.com'
visit url
end
end
GoogleSite.new.find_all({v: "4"})
When I am calling it from rails console i got error:
Capybara's selenium driver is unable to load selenium-webdriver,
please install the gem and add gem 'selenium-webdriver' to your
Gemfile if you are using bundler.
On line with "visit url"
When I call this script from IRB or by ruby file.rb, it's working fine but not from rails console when i include it in lib and call as a class.
I want to use capybara with poltergeist (rails controller will create sidekiq job that will call this class) but I am trying to debug with selenium (to see errors and correct form filling).
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.