gpt4 book ai didi

ruby - selenium-webdriver/ruby/rspec2 - 以干净的 session 或清除 cookies 或隐私浏览启动 IE

转载 作者:太空宇宙 更新时间:2023-11-03 18:17:39 24 4
gpt4 key购买 nike

我将 selenium-webdriver 与 ruby​​ 和 rspec2 一起使用。

我有很多 Web 测试自动化,为此我需要使用 IE,并且我需要使用干净的 session (特别是清除 cookie)运行每个测试。

在这种情况下,selenium-webdriver 使用 InternetExplorerDriver (IEDriverServer.exe),documentation表示:

There are 2 solutions for problem with cookies (and another session items) shared between multiple instances of InternetExplorer.

The first is to start your InternetExplorer in private mode. After that InternetExplorer will be started with clean session data and will not save changed session data at quiting. To do so you need to pass 2 specific capabilities to driver: ie.forceCreateProcessApi with true value and ie.browserCommandLineSwitches with -private value. Be note that it will work only for InternetExplorer 8 and newer, and Windows Registry HKLM_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Main path should contain key TabProcGrowth with 0 value.

The second is to clean session during InternetExplorer starting. For this you need to pass specific ie.ensureCleanSession capability with true value to driver. This clears the cache for all running instances of InternetExplorer, including those started manually.

我的问题很简单:谁能举例说明如何在 Ruby/Rspec2 中完成此操作。

例如,我目前有:

before(:each) do
@driver = Selenium::WebDriver.for :internet_explorer
@driver.manage.window.maximize
@base_url = "https://www.example.com/"
@accept_next_alert = true
@driver.manage.timeouts.implicit_wait = 30
@verification_errors = []
end

如何使用 Ruby/Rspec 将此类 IE 参数传递给 IE 驱动程序?

非常感谢您的帮助。

最佳答案

我知道这篇文章已有一个月了,但以防万一有人仍然需要它。在我做了一些研究之后,我终于可以在没有任何 session 或每次测试的 cookie 的情况下启动新的 IEDriver。这是代码:

before(:each) do
caps = Selenium::WebDriver::Remote::Capabilities..internet_explorer('ie.ensureCleanSession' => true, 'ie.browserCommandLineSwitches' => 'private')
@driver = Selenium::WebDriver.for(:internet_explorer, :desired_capabilities => caps)
@driver.manage.window.maximize
@base_url = "https://www.example.com/"
@accept_next_alert = true
@driver.manage.timeouts.implicit_wait = 30
end

祝你好运!

关于ruby - selenium-webdriver/ruby/rspec2 - 以干净的 session 或清除 cookies 或隐私浏览启动 IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23523346/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com