javascript 什么是与量角器一起运行的好的无头浏览器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29266167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is a good headless browser to run with protractor?
提问by tosh
New User here.
新用户在这里。
After hours of building my smoke and regression tests, I found out after reading many cases online that phantomjs is known to be a trouble to run with protractor. Jenkins has been running phantomjs for all the tasks it has been given so far.
经过数小时的构建烟雾和回归测试后,我在网上阅读了许多案例后发现,phantomjs 使用量角器运行时会遇到麻烦。Jenkins 一直在运行 phantomjs 来完成它迄今为止所分配的所有任务。
They need these tests to run as part of ci which does not have a windowing system installed.
他们需要这些测试作为未安装窗口系统的 ci 的一部分运行。
So I would appreciate it if there is a recommendation for completely headless browser or a headless chrome(that would be most beneficial) and a step by step to set it up. I already have a conf.js and a e2e.conf.js file. My code works perfectly fine with chrome.
因此,如果有关于完全无头浏览器或无头 chrome(这将是最有益的)的建议并逐步设置它,我将不胜感激。我已经有一个 conf.js 和一个 e2e.conf.js 文件。我的代码与 chrome 完美配合。
I am on a iMac and selenium webdriver, I believe.
我相信我在 iMac 和 selenium webdriver 上。
Edit: Problem = protractor doesn't work with phantomjs. What I have done = use different web elements and googled if anyone has faced a similar situation. Also googled for headless browsers that worked for protractor, unable to find a suitable solution.
编辑:问题 = 量角器不适用于 phantomjs。我所做的 = 使用不同的网络元素,如果有人遇到过类似的情况,请使用谷歌搜索。还搜索了适用于量角器的无头浏览器,但找不到合适的解决方案。
采纳答案by Asta
Your best bet is to continue with Chrome. With a bit of work you can get it to work via a CI and in a headless manner - we do this using Jenkins and Docker Ubuntu servers which are headless.
最好的办法是继续使用 Chrome。通过一些工作,您可以通过 CI 以无头方式使其工作 - 我们使用无头的 Jenkins 和 Docker Ubuntu 服务器来实现这一点。
You will need to configure Chrome to run headless using XVFB. You can start off by following the gist here https://gist.github.com/addyosmani/5336747
您需要将 Chrome 配置为使用 XVFB 无头运行。您可以按照此处的要点开始https://gist.github.com/addyosmani/5336747
You state you are on a Mac so you can either run the headless tests via Docker on your machine or you could set up a second config for the CI tests.
您声明您使用的是 Mac,因此您可以在您的机器上通过 Docker 运行无头测试,或者您可以为 CI 测试设置第二个配置。
Another resource http://tobyho.com/2015/01/09/headless-browser-testing-xvfb/
另一个资源http://tobyho.com/2015/01/09/headless-browser-testing-xvfb/
回答by guy mograbi
If anyone reached here - the answers are outdated. Chromium (on next release) now supports headless mode. no need to work hard.
如果有人到达这里 - 答案已经过时。Chromium(下一版本)现在支持无头模式。不需要努力工作。
You can read more here:
你可以在这里阅读更多:
https://developers.google.com/web/updates/2017/04/headless-chrome
https://developers.google.com/web/updates/2017/04/headless-chrome
Here is an example from command line
这是命令行中的示例
chrome \
--headless \ # Runs Chrome in headless mode.
--disable-gpu \ # Temporarily needed for now.
--remote-debugging-port=9222 \
https://www.chromestatus.com # URL to open. Defaults to about:blank.
And you can simply trigger protractor with capabilities for chrome:
您可以简单地触发具有 chrome 功能的量角器:
Activating chrome language flags when activating from protractor (selenium)
Here is the configuraiton I am using
这是我正在使用的配置
capabilities: {
'browserName': browserName,
chromeOptions: {
binary: '/Users/guymograbi/Downloads/chrome-mac/Chromium.app/Contents/MacOS/Chromium',
args: ['--headless','--disable-gpu']
}
},
Update - new versions of chrome doesn't require binary
property
更新 - 新版本的 chrome 不需要binary
属性
In my environments I found I can remove the binary
property as new version of chrome is available on stable branches
在我的环境中,我发现我可以删除该binary
属性,因为稳定分支上有新版本的 chrome 可用
My protractor configuration is
我的量角器配置是
capabilities: {
'browserName': 'chrome',
chromeOptions: {
args: [ '--headless', '--disable-gpu', '--no-sandbox', '--window-size=1920x1200' ]
},
},
And it works smoothly for weeks now. highly recommended.
它现在可以顺利运行数周。强烈推荐。
Update - how to do this in karma is super easy
更新 - 如何在业力中做到这一点非常简单
Using headless chrome in karma is super easy:
在 karma 中使用无头 chrome 非常简单:
browsers: 'ChromeHeadless'
it should work with the chrome loader and everything. more info
它应该适用于 chrome loader 和所有东西。更多信息
回答by Brine
回答by alecxe
I would continue testing in normal browsers with a head, but would use a remote selenium serveras a service - Sauce Labs
or BrowserStack
, see:
我会继续在普通浏览器中进行测试,但会使用远程 selenium 服务器作为服务 -Sauce Labs
或者BrowserStack
,请参阅:
回答by Adnan Ghaffar
If you've got Chrome 59+ installed, start Chrome with the following flag:
如果您安装了 Chrome 59+,请使用以下标志启动 Chrome:
--headless
please let me know if you need more help, will write the config for you :) enjoy
如果您需要更多帮助,请告诉我,我会为您编写配置:) 享受