使用ruby + watir-webdriver +黄瓜和parallel_tests gem在多个浏览器中运行测试 [英] Run tests in multiple browsers with ruby + watir-webdriver + cucumber and parallel_tests gem

查看:97
本文介绍了使用ruby + watir-webdriver +黄瓜和parallel_tests gem在多个浏览器中运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Currently I use the parallel profile in cucumber.yml to load an environment specific file and hooks.rb to set the browser. I run my tests using 'parallel_cucumber features'. There is not much in my hooks.rb file:

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)?可以通过命令行传递文件名或环境吗?

Is there a way to change my hooks.rb file so that all features run against a set of browsers (firefox, chrome, safari)? Is possible to pass the file name or environment through the command line?

推荐答案

您绝对可以通过命令行传递环境名。签出我的env.rb文件:

You can definitely pass the environment name through the command line. Check out my env.rb file:

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 }

现在,当我运行黄瓜时,我通过执行以下操作来调用环境:

Now when I run cucumber, I call the environment by doing:


黄瓜BROWSER = ff

Cucumber BROWSER=ff

这篇关于使用ruby + watir-webdriver +黄瓜和parallel_tests gem在多个浏览器中运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆