使用 FirefoxDriver 时隐藏浏览器
我使用Selenium和FirefoxDriver,当实例它时,FireFox浏览器自动打开,我们如何隐藏它?
WebDriver 驱动程序 = new FirefoxDriver();
谢谢,
I use Selenium with FirefoxDriver, when instance it, FireFox browser auto open, how we can hide it?
WebDriver driver = new FirefoxDriver();
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您也许可以使用 Win32 附加到窗口句柄并隐藏它,但除此之外,我认为无法做到这一点。
Selenium 中的 FirefoxDriver 旨在自动化真正的 Firefox 浏览器(而不是它的某种代表)进行 UI 测试。因此,真正的浏览器需要运行才能工作。
如果您想要一个不可见的 UI 驱动程序,则需要使用 HtmlUnit 驱动程序。
然而正如该网站所说:
所以我会小心地信任 HtmlUnit 驱动程序。
src: http://seleniumhq.org/docs/03_webdriver.html#webdriver-implementations
编辑
另外,我想补充一点,通常自动化测试将在没有用户的专用机器上进行。在这种情况下,无论天气如何,您都可以看到浏览器。
You might be able to attach to the window handle using Win32 and hide it, but other than that I don't think it can be done.
The FirefoxDriver in Selenium is meant for automating the real firefox browser (not some representation of it) for UI testing. Because of this the real browser needs to be running for it to work.
If you want a non-viewable UI driver you'll need to use the HtmlUnit driver.
However as the site says:
So I would be careful trusting the HtmlUnit driver.
src: http://seleniumhq.org/docs/03_webdriver.html#webdriver-implementations
EDIT
Also, I would add that typically the automated testing would be on a dedicated machine with no users. In which case it shouldn't matter weather or not you can see the browser.
如果您不想打开像Firefox这样的真实浏览器,那么您应该使用Html Unit Driver (Remote Web Driver)。首先添加命名空间,然后编写代码。祝你好运。
使用 OpenQA.Selenium;
使用 OpenQA.Selenium.Remote;
if you don't want to open the real browser like Firefox, then you should use the Html Unit Driver (Remote Web Driver). Firstly add the namespace and then write your code. Best of Luck.
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
启动 GUI 比启动非 GUI 浏览器要长。当您有一个庞大的项目并且不希望测试花费很长时间才能完成时,这一点非常重要。
Starting a GUI is longer than starting a non-gui browser. It's really important when you have a huge project and don't want your test to take an eternity to finish.
不确定您想要实现什么,但据我了解,您希望 Firefox Windows 在硒测试运行时不要中断您的工作。因此您可以在另一个桌面上运行测试。例如使用此工具:桌面。简单且便宜的解决方案。
Not sure, what you try to achieve, but as far as I understood you want firefox windows not to interrupt your work while selenium tests are running. So you can run your tests in another desktop. Use for example this tool: Desktops. Easy and cheap solution.