[英]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.