简体   繁体   English

测试是否使用 Watir-Webdriver 打开新的 window

[英]Testing if a new window opens with Watir-Webdriver

I'm using Watir-webdriver and I was wondering if there was a good way to check if a new window opens.我正在使用 Watir-webdriver,我想知道是否有一种好方法可以检查新的 window 是否打开。 I've googled around a bit and couldn't find anything though it feels like there should be an easy answer.我用谷歌搜索了一下,虽然感觉应该有一个简单的答案,但找不到任何东西。

I have a printer friendly link and I want to test that the link opens in a new window or tab and I would like to test this with ie, firefox, chrome and safari if possible.我有一个打印机友好的链接,我想测试该链接是否在新的 window 或选项卡中打开,我想用 firefox、chrome 和 safari 进行测试。

Thanks!谢谢!

You can check the number of windows:您可以查看 windows 的编号:

browser.windows.size

or check if a specific window exists:或检查特定的 window 是否存在:

browser.window(:title => "foo").exists?

More examples in the specs .规格中的更多示例。

You can also use index based browser window checking where you need to worry about index only and it follows zero based index ordering.您还可以使用基于索引的浏览器 window 检查您只需要担心索引的地方,它遵循从零开始的索引排序。 So, the default window is of index: 0 and if a new window opens it will be of index: 1 , the next will be of index: 2 and so on.因此,默认的 window 是index: 0 ,如果新的 window 打开,它将是index: 1 ,下一个是index: 2等等。

To check first child window if you want to test that the link opens in a new window,如果要测试链接是否在新的 window 中打开,请检查第一个子 window,

browser.window(index: 1).exists?

Or to work inside this window,或者在这个 window 内工作,

browser.window(index: 1).use do
  # do scripting here
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM