我正在使用 watir 2.0.1,当前如果脚本正在 url 上运行,则在 IE 浏览器的一个选项卡中说 ABC.com,如果我在其他选项卡或浏览器的新实例中打开相同的 url ABC.com,则执行将切换到这个新标签打开。因此,我无法在同一个 URL 上执行多个脚本/执行
这是 Project1 中 Script1.rb 的代码,
require 'watir'
browser = Watir::Browser.new
browser.goto 'https://example.com'
browser = Watir::Browser.attach(:title, /ABC Application/)
browser.button(:text,"Register").click
sleep 2
browser.text_field(:id,"First_Name").set "Script_1_FirstName"
sleep 2
browser.text_field(:id,"Last_Name").set "Script_1_LastName"
等等...
当 Script1 在浏览器实例 1 中填写 ABC 应用程序的注册表时,同时(比如在 Script1 输入名字后,我将触发 Script2.rb 以对注册表单页面进行一些基本验证。
这是 Project2 中 Script2.rb 的代码,
require 'watir'
browser1 = Watir::Browser.new
browser1.goto 'https://example.com'
browser1 = Watir::Browser.attach(:title, /ABC Application/)
//At this time Script2 will execute properly in IE Instance2 as there is
//no Register button at IE instance1(Because Script1 is already on
//Register form page)
browser1.button(:text,"Register").click
//The movement Register form opens in IE instance2,Script1 finds same page
//elements on IE instance2 so currently Script1 is automatically start its
//execution on IE instance2 which will affect Script2 Execution.
if(browser1.text_field(:id,"First_Name").text.include("")
puts "First name field is blank by default"
else
raise "First name field is not blank by default"
if(browser1.text_field(:id,"Last_Name").text.include("")
puts "Last name field is blank by default"
else
raise "Last name field is not blank by default"