Ruby中的Selenium WebDriver:防止测试最后关闭浏览器窗口 [英] Selenium WebDriver in Ruby: Preventing the test from closing the browser window at end

查看:273
本文介绍了Ruby中的Selenium WebDriver:防止测试最后关闭浏览器窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎有很多其他人遇到的确切的相反问题-无论最终结果如何,我在Ruby中进行的Selenium测试都会关闭浏览器窗口.通过或失败,它将始终关闭浏览器.我想停止这个.

I appear to be having the exact opposite problem many other people have - in that my Selenium tests in Ruby will close the browser window at test end, no matter what the end result is. Pass or fail, it will always close the browser. I would like to stop this.

上下文:

以前,我使用IntelliJ IDEA用Java编写测试代码.在这种情况下,除非您使用driver.quit(),否则不会一直关闭用于Selenium测试的浏览器窗口.这实际上非常有用,因为它意味着如果测试失败,浏览器窗口将保持打开状态-这意味着我可以查看浏览器在浏览器中的停止位置,并帮助找出失败的原因.这对于测试 writing 也是有用的,因为这意味着我基本上可以从我停下来的地方开始编写下一个块,而不必手动在另一个浏览器中运行并行选项卡来获取下一个块给定屏幕中的一组选择器.

Previously I coded tests in Java using IntelliJ IDEA. Browser windows for Selenium tests in this case would NOT close at all period unless you used driver.quit(). This is actually quite useful as it means that the browser window would stay open if the test failed - which meant I could look at where it stopped in the browser and help figure out why it failed. This was also useful for test writing as it meant that I could essentially pick up where I left off to write the next block instead of having to keep a parallel tab going in another browser by hand to get the next set of selectors in the given screen.

我在使用RubyMine的Ruby中发现,以任何容量结束测试时,浏览器都会关闭.这有点问题.从技术上讲,我可以对失败进行分析,但这意味着我将很难再追溯失败的原因(浏览器上的后退按钮,键入字段以弄清用户界面中的异常是否导致了失败,等等).当然,屏幕截图会占用硬盘空间. ;)

I've found in Ruby using RubyMine that the browser will close when the test ends in any capacity. This is a bit of a problem. While technically I could take a screencap on failure, it'd mean that I'd have a harder time retracing why it failed (back button on browser, typing in fields to work out if a quirk in our UI caused it, etc). And of course, screencaps take up hard drive space. ;)

我已经尝试了Chrome的detach = true(和True)命令开关,但没有用.

I've tried the detach=true (and True) command switch for Chrome and that has not worked.

设置:

  • IDE:RubyMine
  • 宝石:selenium-webdriver
  • 浏览器:Chrome,使用ChromeDriver. (在Ruby中,这仅涉及使用WebDriver)
  • 操作系统:OSX

不是没有头,没有使用其他框架/测试环境.从字面上看,这是几行设置,然后在沼泽标准.rb中按RubyMine中的运行按钮.

Not headless, using no other frameworks/testing environments. It is quite literally a few lines of setup and then hitting the run button in RubyMine in a bog-standard .rb.

摘要:

我在Ruby的在线或其他地方找不到任何现有的问题,特别是为了防止RubyMine中的Selenium测试关闭测试端的窗口.在这种情况下,测试结束"指的是成功(到达.rb的结尾)或失败(在这种情况下为回溯).我希望窗口在打到driver.quit行之前一直保持打开状态.有什么办法可以设置吗?

I haven't been able to find any existing questions here or in other places online for Ruby specifically for keeping a Selenium test in RubyMine from closing the window on test end. "Test end" in this case refers to success (reaching the end of the .rb) or failure (Tracebacks, in this case). I would prefer that the window would stay open until it'd hit a driver.quit line. Is there any way I can set this up?

非常感谢.我希望这不是多余的.我也希望这会在将来对其他测试人员有所帮助:)

Thank you very much. I hope this isn't redundant. I also hope this will help other testers in the future :)

推荐答案

您可以使用:desired_capabilities设置此标志:

You can use the :desired_capabilities to set this flag:

caps = Selenium::WebDriver::Remote::Capabilities.chrome("goog:chromeOptions" => {detach: true})
driver = Selenium::WebDriver.for :chrome, desired_capabilities: caps

请注意,旧示例将使用"chromeOptions",但对于较新的Chrome版本,则需要使用"goog:chromeOptions".

Note that old examples will be using "chromeOptions", but for newer Chrome versions, it will need to be "goog:chromeOptions".

这篇关于Ruby中的Selenium WebDriver:防止测试最后关闭浏览器窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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