如何在没有浏览器的机器上运行 Cucumber、selenium 和 capybara?
我正在使用水豚和硒在本地计算机上运行黄瓜测试。对于涉及javascript的页面,Selenium会激活firefox并在firefox中爬行页面来完成任务。他们在我的本地机器上合作得很好。
但是,在我的临时环境中,我没有 GUI 浏览器。有没有办法在无浏览器环境下使用selenium?或者还有其他方法可以在无浏览器环境中使用 Cucumber 测试 javascript 吗?
I am using capybara and selenium to run my cucumber test on my local machine. For the pages that involves javascript, Selenium activates firefox and crawls through the pages in firefox to do the tasks. They cooperates very well on my local machines.
However, in my staging environment, I do not have a GUI browser in it. Is there a way for selenium in a no-browser environment? Or is there any other way to test javascript with cucumber in a no-browser environment?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,如果您运行的是 Linux/Mac,有一种简单的方法可以在 Headless 中运行 Firefox。您可以使用 Xvfb 标准 xwindow 实用程序来实现此目的。有一个 gem 将其包装到 ruby 实用程序类 headless
Yes there is a simple way to run firefox in headless if you're running linux/mac. You can achieve this by using Xvfb standard xwindow utility. There is a gem that wraps it into ruby utility class headless
我尝试过几种无头浏览器 - Culerity、Akephalos、Capybara-Webkit,用于针对我们的(javascript 重)应用程序运行测试。
所有这些都会导致在真实浏览器中运行相同测试时不会发生的错误 - 因此我会赞同上面的建议:最好的选择是安装浏览器并在 Xvfb 中运行它。
I've tried several headless browsers - Culerity, Akephalos, Capybara-Webkit for running tests against our (javascript-heavy) application.
All of them resulted in errors that did not occur when the same tests were run in a real browser - so I will second the advice above: your best bet is to get a browser installed and run it in Xvfb.
HTMLUnitDriver 是完全无头的 - http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/htmlunit/HtmlUnitDriver.html
There is HTMLUnitDriver which is completly headless - http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/htmlunit/HtmlUnitDriver.html
如果有办法让 Selenium 无头运行,我还没有找到,而且我花了很长时间寻找。
您可能想看看像 Celerity 这样的东西来运行无头测试。但缺点是您需要使用 Jruby,这还不错。
If there is a way to get Selenium to run headless, I have yet to find it and I spent a long time looking.
You probably want to look at something like Celerity to run headless tests. The drawback however is that you need to use Jruby which isn't that bad at all.