ruby - 使用 ruby​​ + watir-webdriver + cucumber 和 parallel_tests gem 在多个浏览器中运行测试

标签 ruby cucumber

目前,我使用 cucumber.yml 中的并行配置文件来加载特定于环境的文件,并使用 hooks.rb 来设置浏览器。我使用“parallel_cucumber 功能”运行我的测试。我的 hooks.rb 文件里没有太多内容:

Before do
  @browser = Watir::Browser.new :firefox
end

After do 
  @browser.close
end

配置文件如下所示:

parallel: FIG_NEWTON_FILE=local.yml --no-source --color --format pretty

有没有办法更改我的 hooks.rb 文件,以便所有功能都针对一组浏览器(firefox、chrome、safari)运行?是否可以通过命令行传递文件名或环境?

最佳答案

你绝对可以通过命令行传递环境名称。查看我的 env.rb 文件:

case ENV['BROWSER']
  when 'ff', 'Firefox'
    browser = Selenium::WebDriver.for :firefox
    browser_name = 'Firefox'
  when 'chrome'
    browser = Selenium::WebDriver.for :chrome
    browser_name = 'Chrome'
  when 'debug'
    debug_profile = Selenium::WebDriver::Firefox::Profile.new
    debug_profile.add_extension "firebug-1.9.1-fx.xpi"
    browser = Selenium::WebDriver.for :firefox, :profile => debug_profile
    browser_name = 'Firefox (Firebug)'
  when 'mobile'
    mobile_profile = Selenium::WebDriver::Firefox::Profile.new
    mobile_profile['general.useragent.override'] = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)
      AppleWebKit/420+ (KHTML, like Gecko) Version/3.0
      Mobile/1A535b Safari/419.3"
    browser = Selenium::WebDriver.for :firefox, :profile => mobile_profile
    browser_name = 'Mobile'
  when 'headless'
    headless_profile = Headless.new
    headless_profile.start
    browser = Selenium::WebDriver.for :firefox
    browser_name = 'Firefox'
  else
   browser = Selenium::WebDriver.for :firefox
   browser_name = 'Firefox'
end

if URLS[ENV['URL']].nil?
  environment = 'dev'
  url = 'http://' + URLS['dev']
  domain = URLS['dev']
else
  environment = ENV['URL'].upcase
  url = 'http://' + URLS[ENV['URL']]
  domain = URLS[ENV['URL']]
end

if ENV['CLIENT'].nil?
  client = 'user/password'
else
  client = ENV['CLIENT']
end

puts "Browser      " + browser_name
puts "URL          " + url
puts "Environment: " + environment
puts "Client:      " + client
puts "Domain:      " + domain

test_env = {   :browser => browser,
               :browser_name => browser_name,
               :url => url,
               :env => environment,
               :client => client,
               :login => nil,
               :domain => domain }

现在,当我运行 Cucumber 时,我通过以下方式调用环境:

Cucumber BROWSER=ff

关于ruby - 使用 ruby​​ + watir-webdriver + cucumber 和 parallel_tests gem 在多个浏览器中运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21371181/

相关文章:

ruby-on-rails - rails : change a relationship to be polymorphic

php - 获取 Ruby 的 OpenSSL::HMAC.hexdigest() 的输出与 PHP 的 hash_hmac() 相同

java - 除了场景大纲之外,还有其他方法可以多次运行 cucumber 场景吗?

ruby-on-rails - 在 Rails 中对暂存/生产环境进行冒烟测试的最佳方法是什么?

java - IntelliJ 不运行更新的代码并运行以前分支的代码

Ruby Regexp : + vs *. 特殊行为?

ruby - 在 Ruby 中使用链表进行正确的垃圾收集?

ruby - Cookie 数据大小超过 4K - 但其 'only' 1100 字节已加密

java - cucumber -JVM : Call a Scenario or ScenarioOutline inside a step definition

checkbox - 当表单中出现多个相似字段时,更好的 cucumber (基于 capybara )选择