如何在测试套件中的下一次测试之前关闭所有窗口? [英] How to close all the windows before the next test in a test suite?

查看:53
本文介绍了如何在测试套件中的下一次测试之前关闭所有窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[7] pry(#<RSpec::Core::ExampleGroup::Nested_1>)> page.execute_script "window.close()"
Selenium::WebDriver::Error::NoSuchWindowError: Script execution failed. Script: window.close();
 The window could not be found

[8] pry(#<RSpec::Core::ExampleGroup::Nested_1>)> page.driver.browser.window_handles
=> ["f1-2"]

我打开了一个带有两个选项卡的浏览器,上面的命令确实关闭了一个选项卡,但最后一个选项卡永远不会关闭.它是打开的,但是当我尝试运行 page.execute_script "window.close()" 时,它给出了上述错误.

I had a browser open with two tabs, the above command does close one but the last tab never closes. It is open but when I try to run page.execute_script "window.close()" it gives the above error.

page.driver.browser.window_handles.each do |handle|
  page.driver.browser.switch_to.window(handle)
  page.execute_script "window.close()"
end

上面的代码曾经对我有用,但现在不再适用了.它给出了同样的错误.

The above code was working for me sometime back but doesnt work anymore. It gives the same error.

更新:

当我使用时,

page.driver.browser.window_handles.each do |handle| 
   page.driver.browser.switch_to.window(handle) 
   page.driver.browser.close 
end

它给出了以下错误 Selenium::WebDriver::Error::UnknownError: 'auto_id' 没有引用打开的标签

it gives the following error Selenium::WebDriver::Error::UnknownError: 'auto_id' does not refer to an open tab

推荐答案

page.driver.browser.close 在每个示例之后关闭当前选项卡,最后(第二个)选项卡自行关闭.

page.driver.browser.close closes current tab towards the end and the last (second) tab closes itself after each example.

这篇关于如何在测试套件中的下一次测试之前关闭所有窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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