开发者

Testing if a new window opens with Watir-Webdriver

开发者 https://www.devze.com 2023-03-19 15:56 出处:网络
I\'m using Watir-webdriver and I was wondering if there was a good way to check if a new window opens. I\'ve googled around a bit and couldn\'t find anything tho开发者_如何学Gough it feels like there

I'm using Watir-webdriver and I was wondering if there was a good way to check if a new window opens. I've googled around a bit and couldn't find anything tho开发者_如何学Gough 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.

Thanks!


You can check the number of windows:

browser.windows.size

or check if a specific window exists:

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. 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.

To check first child window if you want to test that the link opens in a new window ,

browser.window(index: 1).exists?

Or to work inside this window,

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号