在不同的浏览器中使用黄瓜/水豚/硒有问题
我按照这个人推荐的方式设置了我的env.rb。 我在本地启动了我的应用程序,当我运行firefox = true bundle exec cucumber features / 01_login.feature时,我得到以下内容
无法加载此类文件 - 水豚/ poltergeist(LoadError)/Users/gabrielpumple/bi/features/support/env.rb:3:in require' /Users/gabrielpumple/bi/features/support/env.rb:3:in
/Users/gabrielpumple/bi/features/support/env.rb 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' load' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/lib/cucumber/rb_support/rb_language.rb:122:in
p547 /gems/cucumber-1.3.10/lib/cucumber/runtime/support_code.rb:180:in load_file load_file' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/lib/cucumber/runtime/support_code.rb:83:in
在load_files! load_file' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/lib/cucumber/runtime/support_code.rb:83:in
块中' /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
!' /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
gabrielpumple/ load_step_definitions' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/gems/cucumber-1.3.10/lib/cucumber/runtime.rb:42:in
运行中!' /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/cucumber:23:in load' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/bin/cucumber:23:in
/Users/gabrielpumple/.rvm/gems/ load' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/bin/cucumber:23:in
-1.9 .3-p547 / bin / ruby_executable_hooks:15:在eval' /Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in
/Users/gabrielpumple/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in'
我已经安装了poltergeist / phantomjs并运行软件包安装。 我的同事和我的测试在Chrome中正常工作,但我们需要使用不同的浏览器运行它们。 任何帮助是极大的赞赏。
那么,我从一个同事那里得到了一些帮助,现在测试正在firefox中运行,希望很快就会开始。 这是他如何更改env.rb文件
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
然后当我从我使用的命令行运行一个功能
bundle exec cucumber CURRENT_BROWSER=chrome feature/myFeature.feature
对于Chrome,或者
bundle exec cucumber feature/myFeature.feature
对于Firefox(默认)。 歌剧驱动程序仍然不想为我工作,只有1%的人使用它,所以我不担心,Safari驱动程序不支持模态交互,所以如果您的测试涉及验证窗口或与故意交互登录失败后,Safari会无法正常工作。 我保留Safari选项以防更新Safari驱动程序,或者如果我有一个非常简单的测试,我希望能够运行。 我会看到它是否能在IE上正常工作后更新。
链接地址: http://www.djcxy.com/p/6603.html上一篇: Trouble using cucumber/capybara/selenium with different browsers
下一篇: Having trouble getting cucumber 6.3 to run on rails 2.3.4