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
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'm trying to tests my puppet modules, but I get an error message that it can't find class.
I've written a couple of internally used Puppet modules; now that I have my head around puppet, I want to write tests. Since I ran into issues, I decided to essentially start over with a new clean module to figure out what I need to do.
$puppet module generate wet-splunk
<<snip interactive questions>>
$cd splunk
$rake spec
<path snip>ruby -I/Users/wet/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rspec-support-3.4.1/lib:/Users/wet/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.1/lib /Users/wet/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.1/exe/rspec --pattern spec/\{classes,defines,unit,functions,hosts,integration,types\}/\*\*/\*_spec.rb --color
F
Failures:
1) splunk with defaults for all parameters should contain Class[splunk]
Failure/Error: it { should contain_class('splunk') }
Puppet::PreformattedError:
Evaluation Error: Error while evaluating a Function Call, Could not find class ::splunk for host.example.com at line 1:1 on node host.example.com
# ./spec/classes/init_spec.rb:5:in `block (3 levels) in <top (required)>'
Finished in 0.21712 seconds (files took 3.14 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/classes/init_spec.rb:5 # splunk with defaults for all parameters should contain Class[splunk]
/Users/wet/.rbenv/versions/1.9.3-p0/bin/ruby -I/Users/wet/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rspec-support-3.4.1/lib:/Users/wet/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.1/lib /Users/wet/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.1/exe/rspec --pattern spec/\{classes,defines,unit,functions,hosts,integration,types\}/\*\*/\*_spec.rb --color failed
Checking the files though I think they contain what they should:
manifests/init.pp
# <snip documentation boilterplate>
class splunk {
}
spec/classes/init_spec.rb
require 'spec_helper'
describe 'splunk' do
context 'with defaults for all parameters' do
it { should contain_class('splunk') }
end
end
The Could not find class ::splunk is the part that has me confused.
The way I read the spec file is it looking inside init for class{'splunk': ... } That could be me misreading it as it seems odd they would start with a broken spec file, but just in case I tried testing for package instead.
manifests/init.pp
class splunk {
package{'splunk':
ensure => 'present',
}
}
spec/classes/init_spec.rb
require 'spec_helper'
describe 'splunk' do
context 'with defaults for all parameters' do
it { should contain_package('splunk') }
end
end
I still get a similar error message:
$ rake spec
/Users/wet/.rbenv/versions/1.9.3-p0/bin/ruby -I/Users/wet/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rspec-support-3.4.1/lib:/Users/wet/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.1/lib /Users/wet/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.1/exe/rspec --pattern spec/\{classes,defines,unit,functions,hosts,integration,types\}/\*\*/\*_spec.rb --color
F
Failures:
1) splunk with defaults for all parameters should contain Package[splunk]
Failure/Error: it { should contain_package('splunk') }
Puppet::PreformattedError:
Evaluation Error: Error while evaluating a Function Call, Could not find class ::splunk for host.example.com at line 1:1 on node host.example.com
# ./spec/classes/init_spec.rb:6:in `block (3 levels) in <top (required)>'
Finished in 0.21168 seconds (files took 3.17 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/classes/init_spec.rb:6 # splunk with defaults for all parameters should contain Package[splunk]
Sorry to ask such a basic question; I really appreciate your help. I'd really love links to good tutorials on testing Puppet code; I'd love to use Vagrant to have some confidence my code is actually going to do what I want it to.
Update:
I believe I have followed #Peter_Souter's suggestions; I still get the error that it can't find the class. I'm posting the contents of the files referenced to try and validate I did the right thing and in case there are other errors.
$ cat .fixtures.yml
fixtures:
symlinks:
"splunk": "#{source_dir}"
$ cat spec_helper.rb
require 'puppetlabs_spec_helper/module_spec_helper'
$ cat Rakefile
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]
desc "Validate manifests, templates, and ruby files"
task :validate do
Dir['manifests/**/*.pp'].each do |manifest|
sh "puppet parser validate --noop #{manifest}"
end
Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
end
Dir['templates/**/*.erb'].each do |template|
sh "erb -P -x -T '-' #{template} | ruby -c"
end
end
$ cat Gemfile
source 'https://rubygems.org'
puppetversion = ENV.key?('PUPPET_VERSION') ? "#{ENV['PUPPET_VERSION']}" : ['>= 3.3']
gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 0.8.2'
gem 'puppet-lint', '>= 1.0.0'
gem 'facter', '>= 1.7.0'
gem 'rspec-puppet', '~> 2.1', :require => false
gem 'rspec-core', '3.1.7', :require => false
The way that rspec-puppet simulates the catalog for testing, it makes a fixtures directory with the required modules in it. So right now it's running it on an empty directory so it can't find your module. We generally fix that with the puppetlabs-spec-helper which makes a simlink to your current repository in that fixtures directory.
I'd recommend adding the following into your files:
# .fixtures.yml
fixtures:
symlinks:
"splunk": "#{source_dir}"
# spec_helper.rb
require 'puppetlabs_spec_helper/module_spec_helper'
# Rakefile
require 'puppetlabs_spec_helper/rake_tasks'
# Gemfile
gem 'rspec-puppet', '~> 2.1', :require => false
gem 'rspec-core', '3.1.7', :require => false
Can you try that and tell me if it works for you?
If somebody stumble around this Thread as I do. The for me correct answer is given in:
Why do I get puppet-rspec 'class does not exist' when it does?
means you have to do:
puppet module generate foo-bar
and then to fix this issue
bundle exec rspec-puppet-init
It's not nice but better then handling with hidden dot files.
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+
I'm trying to get my specs working headlessly in docker - They run fine locally on my mac but when I run them inside the docker container I get this error (repeated multiple times)
Selenium::WebDriver::Error::JavascriptError:
arguments[0] is undefined
# [remote server] https://foobar.com/ line 68 > Function:1:1:in `anonymous'
# [remote server] https://foobar.com/:68:20:in `handleEvaluateEvent'
# ./spec/features/foo_spec.rb:15:in `block (2 levels) in <top (required)>
Xvfb is running: Xvfb :99.0 -screen 0 1366x768x16
I've also tried doing a xvfb-run rspec and got the same errors.
spec_helper.rb:
Capybara.default_driver = :selenium
Capybara.javascript_driver = :selenium
What's going on that this can't run inside docker?
The reason for this error is this:
>> webdriver.execute_script("return typeof arguments[0]", "foo")
=> "undefined"
Apparently this is a bug with Firefox 35 and webdriver. There is an issue open for it - https://code.google.com/p/selenium/issues/detail?id=8390.
I have a problem with Capistrano deploying to a server with RVM and gemsets
executing `deploy:assets:precompile'
* executing "cd /var/app/releases/20111229233555 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
*** [err ::] rake aborted!
*** [err ::] Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
*** [deploy:update_code] rolling back
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.2#mygemset' -c 'cd /var/app/releases/20111229234715 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'"
This is my Capfile
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'rvm/capistrano'
set :rvm_bin_path, "$HOME/.rvm/bin"
set :rvm_ruby_string, '1.9.2#mygemset'
set :rvm_type, :user
load 'deploy/assets'
When I log in as the very same user which is used by Capistrano the failing command is executed without any problems.
It seems that Capistrano is using some other environment.
Here is my ~/.rvmrc file:
rvm_gemset_create_on_use_flag=1 rvm_trust_rvmrcs_flag=1
Is there a way how to check which ruby and gemset is used at the execution time?
node.js is and V8 are installed on the system, and all needed gems are in Gemfile:
here is my rvm info:
ruby:
interpreter: "ruby"
version: "1.9.2p290"
date: "2011-07-09"
platform: "x86_64-linux"
patchlevel: "2011-07-09 revision 32553"
full_version: "ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]"
homes:
gem: "/home/capistrano/.rvm/gems/ruby-1.9.2-p290#mygemset"
ruby: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290"
binaries:
ruby: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290/bin/ruby"
irb: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290/bin/irb"
gem: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290/bin/gem"
rake: "/home/capistrano/.rvm/gems/ruby-1.9.2-p290#mygemset/bin/rake"
setting up PATH in the deploy.rb solved this issue:
default_environment['PATH'] = "/usr/local/bin:/usr/bin:/bin:/opt/bin:$PATH"
it's a Gentoo distribution and the PATH var seems to be empty when using cap deploy, so I copied the content of server PATH and now it works
This issue went away for me when I installed nodejs (using apt-get) on my server. As I stated in this Stackoverflow answer, it's the most practical choice because you don't need to include any dependencies in your Gemfile.