Selenium 支持无头浏览器测试吗?
我现在正在查看 Selenium Server,我似乎没有注意到支持无头浏览器测试的驱动程序。
除非我弄错了,否则它不支持。如果您使用的是 X,您可以创建一个虚拟帧缓冲区来隐藏浏览器窗口,但这并不是真正的无头浏览器。
谁能启发我吗? Selenium 支持无头浏览器测试吗?
I'm looking at Selenium Server at the moment, and I don't seem to notice a driver that supports headless browser testing.
Unless I'm mistaken, it doesn't support it. If you're on X, you can create a virtual framebuffer to hide the browser window, but that's not really a headless browser.
Can anyone enlighten me? Does Selenium support headless browser testing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
您无需使用 PhantomJS 作为 Selenium 的替代品。 Selenium 包含一个 PhantomJS webdriver 类,它运行在 GhostDriver 平台上。只需将 PhantomJS 二进制文件安装到您的计算机上即可。在 python 中,你可以使用:
瞧。
you need not use PhantomJS as an alternative to Selenium. Selenium includes a PhantomJS webdriver class, which rides on the GhostDriver platform. Simply install the PhantomJS binary to your machine. in python, you can then use:
and voila.
WebDriver API 支持 HTMLUnit 作为测试浏览器。 Ruby 开发人员已经使用 Capybara 进行无头硒测试一段时间了,所以它绝对是可行的。
The WebDriver API has support for HTMLUnit as the browser for your testing. Ruby people have been using Capybara for a while for their headless selenium testing so it is definitely doable.
我知道这是一个旧帖子。认为这会对其他正在寻找答案的人有所帮助。
您可以使用 XVFB 在任何 Linux 发行版中安装完整的 Firefox。这可以确保您的测试是在真实的浏览器中执行的。一旦完成无头设置,您就可以使用您选择的 Webdriver 来连接并运行测试。
I know this is a old post. Thought it will help others who are looking for an answer.
You can install a full blown firefox in any linux distribution using XVFB. This makes sure your testing is performed in a real browser. Once you have a headless setup, you can use webdriver of your choice to connect and run testing.
无头浏览器是个坏主意。它们会为您提供一些测试,但与真实用户所看到的完全不同,并且它们掩盖了只有真实浏览器才会遇到的许多问题。在无头环境(例如、Windows 或带有 XVFB 的 Linux)上使用“有头”浏览器(即,除 HTMLUnit 之外的任何浏览器)会带来无限的好处。
Headless browsers are a bad idea. They get you some testing, but nothing like what a real user will see, and they mask lots of problems that only real browsers encounter. You're infinitely better off using a "headed" browser (i.e., anything but HTMLUnit) on a headless environment (e.g., Windows, or Linux with XVFB).
我注意到您说使用 X 帧缓冲区并不是真正的无头解决方案,但是,对于大多数人来说,我认为这是可以接受的。除此之外,如果您对此感兴趣,此服务将帮助您实现这一点一个解决方案。
I notice that you say that using an X framebuffer isn't a true headless solution, however, for most, I think it would be acceptable. In addition to that, this service will help get that going for you if you are interested in that as a solution.
Selenium 确实以某种方式支持无头浏览器测试。 Docker Selenium 由 SeleniumHQ 维护。这些 docker 容器开箱即用,支持 xvfb。有些工具(例如 PhantomJS)可以与 Selenium 连接。但是,Selenium 本身并未正式支持它。
就像其他人所描述的那样,PhantomJS 并不真正推荐。 Selenium 的全部意义在于自动化浏览器。但为什么要自动化一个没有人使用的浏览器呢?我从来不明白为什么开发人员经常忽视这一点。
Selenium does support headless browser testing in a way. Docker Selenium is maintained by SeleniumHQ. Those docker containers come with xvfb support with them out of the box. There are tools like PhantomJS that you can hook up with Selenium. However, it's not officially supported by Selenium itself.
Much like what others have described, PhantomJS isn't really recommended. The whole point of Selenium is to automate browsers. But why automate a browser no one uses? I never understood how that was overlooked so often by developers..
是的。 Selenium 支持无头浏览器测试,对于大量测试用例的执行速度更快、更方便。
Yes. Selenium support headless browser testing and it's more faster as well as convient for big amount of test-cases execution.
是的,selenium 支持无头浏览器测试...但我发现 HTMLUnit 大多数时候都失败...我正在寻找替代方案...PhantomJs 真的很好。你绝对可以尝试一下,与其他浏览器相比,它非常快...这对于冒烟测试非常有用...
http://phantomjs.org/
Yes ,selenium supports headless browser testing...but i found HTMLUnit failing most times...I was searching for an alternative...PhantomJs was really good.you can definitely give it a try it was very fast when compared to other browsers...It is really good for smoke testing...
http://phantomjs.org/
对于 ruby 和 macOS:
brew install phantomjs
然后:With ruby and macOS:
brew install phantomjs
then:是的,Selenium 支持无头浏览器测试。无头浏览器比实时浏览器更快。
Yes Selenium supports headless browser testing.Headless browsers are faster than real time browsers.
在 Linux 服务器上安装
chromeDriver
和google-chrome-stable
版本,其中将触发测试并在代码中添加相同的二进制文件。代码片段:
Install
chromeDriver
andgoogle-chrome-stable
version on the linux server, where the tests will be triggered and add the same binaries in your code.code snippet:
这是关于如何在运行 Django/Python 的 Ubuntu Linux 环境中将 Selenium 与 xvfb 和 Firefox 驱动程序一起使用的“现代答案”:
然后您可以按照 Django LiveServerTestCase 说明。
要使用刚刚安装的驱动程序,请执行以下操作:
Here's a "modern answer" on how to use Selenium with xvfb and Firefox driver in an Ubuntu Linux environment running Django/Python:
You can then follow the Django LiveServerTestCase instructions.
To use the driver you just installed, do something like this: