[英]Open new private window with Capybara and selenium-webdriver
如何同时打开2个窗口,但以私人模式打开1个窗口?
水豚的方法( link )
open_new_window
打开一个新窗口,但不接受任何参数。
还尝试了:
page.execute_script 'window.open(link, "mywindow", "private=yes");'
但是新窗口仍未处于私有模式。
我在用:
有任何想法吗?
要具有私有模式窗口和非私有模式窗口,您需要具有两个会话和两个驱动程序注册。 在当前版本的Capybara,selenium-webdriver和Firefox中,具有手动会话管理功能的操作如下:
Capybara.register_driver :selenium_firefox_private do |app|
firefox_options = ::Selenium::WebDriver::Firefox::Options.new
firefox_options.args << "-private"
Capybara::Selenium::Driver.new(app, browser: :chrome, options: firefox_options)
end
然后在测试中需要专用窗口时,将为该专用窗口创建一个新会话
# Assuming you already have a session going and are interacting with the page
# with `Capybara.javascript_driver = :selenium` or equivalent set
page.find(...) # everything called on page is happening in the original non-private session
private_session = Capybara::Session.new(:selenium_firefox_private, Capybara.app)
private_session.visit(...) # anything called on private_session will happen in the private firefox instance
另一种选择是使用Capybaara.using_driver
Capybara.using_driver(:selenium_chrome_private) do
# everything in this block would happen in a private browsing session that is auto created by Capybara (if it hadn't already been created)
page.visit('/')
end
对于您使用的过时版本也是如此,但是驱动程序注册中的Selenium配置可能会有所不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.