Homebrew cask does some app linking magic on Mac OS X. Apparently it's not good enough because Selenium WebDriver looking for the Firefox executable can't find it. The following is an error message from an RSpec test run with Capybara driving Selenium.
What is a good way to hint the location of the Firefox executable?
Failure/Error: Unable to find matching line from backtrace
Selenium::WebDriver::Error::WebDriverError:
Could not find Firefox binary (os=macosx). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path=
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:127:in `path'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:60:in `execute'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:34:in `start_with'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:70:in `start_silent_and_wait'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:35:in `block in launch'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/socket_lock.rb:20:in `locked'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:32:in `launch'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/bridge.rb:24:in `initialize'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/common/driver.rb:31:in `new'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/common/driver.rb:31:in `for'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver.rb:67:in `for'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/capybara-2.4.4/lib/capybara/selenium/driver.rb:13:in `browser'
As the error msg says: You have to specify Selenium::WebDriver::Firefox::Binary.path for custom app paths.
# in spec_helper.rb
require 'selenium/webdriver'
Selenium::WebDriver::Firefox::Binary.path =
"/opt/homebrew-cask/Caskroom/Firefox/latest/Firefox.app/Contents/MacOS/firefox"
If you don't want to touch the test framework, you can install firefox to /Applications (default path selenium searches for) to make it work without setting the Binary.path.
brew cask install --appdir="/Applications" firefox
I just added the code for Selenium to look for this directory specifically without needing to set it or change appdir. It will be available in the selenium-webdriver gem 2.49+
Related
I currently write tests using Rails5, Rspec, Selenium, and webdrivers gems.
However, I get the error Webdrivers :: BrowserNotFound and I can't run it.
I think this is due to Selenium not finding a ChromeDriver.
However, this problem should have been solved by a webdrivers gem, but it doesn't seem to work as expected.
Details will be written below.
Error Log
1.1) Failure/Error: visit hoges_index_path
Webdrivers::BrowserNotFound:
Failed to find Chrome binary.
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/chrome_finder.rb:21:in `location'
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/chrome_finder.rb:10:in `version'
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/chromedriver.rb:46:in `browser_version'
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/chromedriver.rb:106:in `release_version'
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/chromedriver.rb:32:in `latest_version'
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/common.rb:136:in `correct_binary?'
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/common.rb:92:in `update'
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/chromedriver.rb:119:in `block in <top (required)>'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/service.rb:133:in `binary_path'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/service.rb:94:in `initialize'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/service.rb:41:in `new'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/service.rb:41:in `chrome'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/driver.rb:299:in `service_url'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/chrome/driver.rb:40:in `initialize'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/driver.rb:46:in `new'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/driver.rb:46:in `for'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver.rb:88:in `for'
# /usr/local/bundle/gems/capybara-3.28.0/lib/capybara/selenium/driver.rb:49:in `browser'
# /usr/local/bundle/gems/capybara-3.28.0/lib/capybara/selenium/driver.rb:68:in `visit'
# /usr/local/bundle/gems/capybara-3.28.0/lib/capybara/session.rb:276:in `visit'
# /usr/local/bundle/gems/capybara-3.28.0/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
# ./spec/views/hoge/index_spec.rb:28:in `block (2 levels) in <top (required)>'
TestCode
RSpec.feature 'HogeIndex', type: :system do
before(:each) do
visit hoges_index_path
end
scenario 'hoge' do
expect(all('.hoge').count).to eq 1
end
end
rails_helper.rb
RSpec.configure do |config|
~~~
Capybara.register_driver :selenium_chrome_headless do |app|
browser_options = ::Selenium::WebDriver::Chrome::Options.new
browser_options.args << '--headless'
browser_options.args << '--no-sandbox'
browser_options.args << '--disable-gpu'
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end
config.before(:each) do |example|
if example.metadata[:type] == :system
driven_by :selenium_chrome_headless, screen_size: [700, 700]
end
end
~~~~
end
I also turned on Webdrivers Debug logging.
Here is the log at that time.
2019-10-19 02:12:03 DEBUG Webdrivers Checking current version
2019-10-19 02:12:03 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
2019-10-19 02:12:04 DEBUG Webdrivers Checking current version
2019-10-19 02:12:04 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
F2019-10-19 02:12:10 DEBUG Webdrivers Checking current version
2019-10-19 02:12:10 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
2019-10-19 02:12:11 DEBUG Webdrivers Checking current version
2019-10-19 02:12:11 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
F2019-10-19 02:12:17 DEBUG Webdrivers Checking current version
2019-10-19 02:12:17 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
2019-10-19 02:12:18 DEBUG Webdrivers Checking current version
2019-10-19 02:12:18 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
F2019-10-19 02:12:25 DEBUG Webdrivers Checking current version
2019-10-19 02:12:25 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
2019-10-19 02:12:26 DEBUG Webdrivers Checking current version
2019-10-19 02:12:26 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
F
I will wait for your reply.
It is solved.
It was because Google Chrome was not installed.
I'm sorry.
I am running my rspec test with selenium webdriver. The setup looks the following way:
require 'capybara/dsl'
Capybara.app = Rack::File.new File.expand_path('../fixtures', __FILE__)
require 'selenium-webdriver'
Capybara.register_driver :firefox do |app|
options = ::Selenium::WebDriver::Firefox::Options.new
options.args << '--headless' if travis?
Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)
end
Capybara.default_driver = :firefox
When I run rspec the tests fail with
Failure/Error: visit '/select2-v3/index.html'
Selenium::WebDriver::Error::UnknownError:
newSession
# WebDriverError#chrome://marionette/content/error.js:178:5
# UnknownCommandError#chrome://marionette/content/error.js:472:5
# despatch#chrome://marionette/content/server.js:290:13
# execute#chrome://marionette/content/server.js:271:11
# onPacket/<#chrome://marionette/content/server.js:246:15
# onPacket#chrome://marionette/content/server.js:245:8
# _onJSONObjectReady/<#chrome://marionette/content/transport.js:490:9
# ./spec/select2_spec.rb:6:in `block (2 levels) in <top (required)>'
Googling around didn't give me any results.
Do you have any ideas how to fix it?
Update: I am using firefox v63.0
You need to upgrade to the latest version of geckodriver (v0.23.0) to work with Firefox 63.
I did
brew install geckodriver then tried brew link geckodriver then an error message says the target file directory already exist. So I removed the target file directory using
rm '/usr/local/bin/geckodriver' before linking again using brew link geckodriver
It just won't start - any ideas?
Tried uninstalling and reinstalling QT (4.8.6), upgraded Xcode, brew doctor, checked settings in spec_helper - it's all correct.
Failure/Error: visit controls_path
Capybara::Webkit::ConnectionError:
/usr/local/rvm/gems/ruby-2.1.1/gems/capybara-webkit-1.3.0/bin/webkit_server failed to start.
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-webkit-1.3.0/lib/capybara/webkit/connection.rb:75:in parse_port'
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-webkit-1.3.0/lib/capybara/webkit/connection.rb:81:indiscover_port'
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-webkit-1.3.0/lib/capybara/webkit/connection.rb:62:in start_server'
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-webkit-1.3.0/lib/capybara/webkit/connection.rb:25:ininitialize'
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-webkit-1.3.0/lib/capybara/webkit/driver.rb:17:in new'
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-webkit-1.3.0/lib/capybara/webkit/driver.rb:17:ininitialize'
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-webkit-1.3.0/lib/capybara/webkit.rb:11:in new'
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-webkit-1.3.0/lib/capybara/webkit.rb:11:inblock in '
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-2.4.1/lib/capybara/session.rb:79:in call'
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-2.4.1/lib/capybara/session.rb:79:indriver'
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-2.4.1/lib/capybara/session.rb:65:in initialize'
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-2.4.1/lib/capybara.rb:248:innew'
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-2.4.1/lib/capybara.rb:248:in current_session'
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-2.4.1/lib/capybara/dsl.rb:46:inpage'
# /usr/local/rvm/gems/ruby-2.1.1/gems/capybara-2.4.1/lib/capybara/dsl.rb:51:in block (2 levels) in <module:DSL>'
# ./spec/features/controls_spec.rb:17:inblock (3 levels) in '
I honestly have no idea what finally made it work - but I got it working.
Uninstalled basically everything and reinstalled things piece by piece, but during it all I got lost on testing after a particular step and it started working without my noticing what I had just done.
When in doubt: reinstall I guess =/
I'm trying to get Jasmine to run in the command line (headless), but have had no success. With our current configuration:
Gemfile:
gem 'jasmine', :git => "git://github.com/pivotal/jasmine-gem.git"
gem 'jasmine-headless-webkit', :git => "git://github.com/johnbintz/jasmine-headless-webkit.git"
My current configuration of jasmine specs runs in the browser. rake jasmine:ci, however, opens a browser, and then aborts shortly thereafter with this error message:
/Users/`<me>`/.rvm/gems/ruby-2.0.0-p353/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/firefox/launcher.rb:79:in `connect_until_stable': unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError)
I looked at the github page for jasmine-headless-webkit, and saw that the project is listed as dead. So! I tried to replace the jasmine & jasmine-headless-webkit gem with jasmine-rails, and I got this error:
ERROR: TypeError: 'undefined' is not an object (evaluating 'jasmine.Matchers.prototype')
TRACE:
-> file:///Users/<me>/<myapp>/tmp/jasmine/assets/jasmine-specs.js: 711
-> file:///Users/<me>/<myapp>/tmp/jasmine/assets/jasmine-specs.js: 736
-> file:///Users/<me>/<myapp>/tmp/jasmine/assets/jasmine-specs.js: 738
-> file:///Users/<me>/<myapp>/tmp/jasmine/assets/jasmine-specs.js: 862
rake aborted!
Error executing command: "/Users/<me>/.phantomjs/1.9.7/darwin/bin/phantomjs" "/Users/<me>/.rvm/gems/ruby-2.0.0-p353/gems/jasmine-rails-0.9.0/lib/jasmine_rails/../assets/javascripts/jasmine-runner.js" "/Users/<me>/<myapp>/tmp/jasmine/runner.html?spec="
Since most users seemed to want to run their jasmine specs using phantom, as part of the 2.0 release we made that the default. The ability to run jasmine:ci with selenium was extracted into its own gem.
This is really bugging me as there is a bit (not a lot) on the internet about the following error when running cap deploy:cold
cannot load such file -- rvm/capistrano (LoadError)
The solution seems to be gem install rvm-capistrano. Everyone else says installing that gem fixed the error, but for me it does nothing.
The offending lines are:
# Add RVM's lib directory to the load path.
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
# Load RVM's capistrano plugin.
require "rvm/capistrano"
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"")
set :rvm_type, :user
###
You should remove the following line too.
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
That, and installing the rvm-capistrano gem solved similar issue for me.