Trouble using cucumber/capybara/selenium with different browsers
I setup my env.rb the way this guy recommended is set up. I started my app locally and when I run firefox=true bundle exec cucumber features/01_login.feature I get the following
cannot load such file -- capybara/poltergeist (LoadError) /Users/gabrielpumple/bi/features/support/env.rb:3:in require' /Users/gabrielpumple/bi/features/support/env.rb:3:in
' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/lib/cucumber/rb_support/rb_language.rb:122:in load' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/lib/cucumber/rb_support/rb_language.rb:122:in
load_code_file' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/lib/cucumber/runtime/support_code.rb:180:in load_file' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/lib/cucumber/runtime/support_code.rb:83:in
block in load_files!' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/lib/cucumber/runtime/support_code.rb:82:in each' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/lib/cucumber/runtime/support_code.rb:82:in
load_files!' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/lib/cucumber/runtime.rb:184:in load_step_definitions' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/lib/cucumber/runtime.rb:42:in
run!' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/lib/cucumber/cli/main.rb:47:in execute!' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/bin/cucumber:13:in
execute!' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/bin/cucumber:13:in
' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/bin/cucumber:23:in load' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/bin/cucumber:23:in
' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in eval' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in
'
I have already installed poltergeist/phantomjs and run bundle install. My colleagues and I have the tests working properly in chrome, but we need to run them with different browsers. Any help is greatly appreciated.
Well, I got some help from a coworker and now the tests are running in firefox, and hopefully soon on ie. Here is how he changed the env.rb file
require 'cucumber/rails'
Capybara.default_selector = :css
cb = ENV['CURRENT_BROWSER']
testbrowser = cb ? cb.downcase.to_sym : :firefox
puts "-------------- current browser: #{testbrowser}........."
Capybara.register_driver :selenium do |app|
if RbConfig::CONFIG['host_os'][/linux/] && testbrowser.to_s.eql?("CHROME".downcase)
Capybara::Selenium::Driver.new(app, {:browser => :remote, :url => "http://127.0.0.1:9515"})
else
if testbrowser.eql?(:chrome)
Capybara::Selenium::Driver.new(app, :browser => :chrome, :switches => %w[--test-type])
elsif testbrowser.eql?(:safari)
Capybara::Selenium::Driver.new(app, :browser => :safari, :switches => %w[--test-type])
elsif testbrowser.eql?(:internetexplorer)
Capybara::Selenium::Driver.new(app, :browser => :internetexplorer, :switches => %w[--test-type])
else
Capybara::Selenium::Driver.new(app, :browser => testbrowser)
end
end
end
ActionController::Base.allow_rescue = false
begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
Cucumber::Rails::Database.javascript_strategy = :truncation
Then when I run a feature from the command line I use
bundle exec cucumber CURRENT_BROWSER=chrome feature/myFeature.feature
for Chrome, or
bundle exec cucumber feature/myFeature.feature
for Firefox (default). The opera driver still didn't want to work for me, and only 1% of people use it so I'm not worried, and Safari driver doesn't support modal interaction so if your test involves a validation window or interacting with a deliberate failure say on login, safari won't work. I kept the Safari option in case they update the Safari driver, or if I have a very simple test I'd like to be able to run. I will update after I have seen if it works properly on IE.
链接地址: http://www.djcxy.com/p/6604.html上一篇: `sysread':到达文件结尾(EOFError)
下一篇: 在不同的浏览器中使用黄瓜/水豚/硒有问题