[英]Watir/Rspec Browser Loop
I need some help using multiple browsers in a loop with Watir/Rspec. 我需要一些使用Watir / Rspec在循环中使用多个浏览器的帮助。
I can get this to work with using Watir, but do not know how to get this to work with Rspec. 我可以使用Watir来使用它,但不知道如何使用Rspec。
Watir (working code): Watir(工作代码):
require 'watir-webdriver'
require 'rspec'
browsers = [:ff, :chrome]
browsers.map do |x|
$browser = Watir::Browser.new x
$browser.goto('http://www.google.ca')
$browser.text_field(:id, 'gbqfq').set 'Juventus'
$browser.send_keys :enter
$browser.close
end #End loop
Rspec (not working): Rspec(不工作):
require 'watir-webdriver'
require 'rspec'
browsers = [:ff, :chrome]
browsers.map do |x|
$browser = Watir::Browser.new x
$browser.goto('http://www.google.ca')
describe 'loop' do
it 'does something' do
$browser.text_field(:id, 'gbqfq').set 'Juventus'
$browser.send_keys :enter
$browser.close
end
end #End describe
end #End loop
This is what happens with the code above: 这是上面的代码:
It seems when I include Rspec describe
the loop does not work as I had intended it to. 似乎当我包含Rspec
describe
循环不起作用,因为我有意。
Finally figured it out :) 终于想通了:)
Here is the code for anyone that wants to do multiple browser testing without making different specs for each browser. 以下是任何想要进行多次浏览器测试的人的代码,而不为每个浏览器制作不同的规范。
require 'watir-webdriver'
require 'rspec'
browsers = [:ff, :chrome]
browsers.map do |x|
describe 'Browser' do
before(:all) do
@browser = Watir::Browser.new x
end
it 'goes to Google.ca' do
@browser.goto('http://www.google.ca')
end
it 'searches' do
@browser.text_field(:id, 'gbqfq').when_present(3).set 'Juventus'
@browser.send_keys :enter
sleep 0.5 #roughly takes 0.5s for the images to load.
end
it 'closes browser' do
@browser.close
end
end #end describe
end #end loop
I think for this to work properly you need to initialize the browser after describe
whereas before I was initializing the browser before describe
我认为这个正常工作,你需要初始化浏览器后
describe
,而我被初始化浏览器之前之前describe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.