What is a good headless browser to run with protractor?

China☆狼群 提交于 2019-11-30 06:41:54

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.

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

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.

Another resource http://tobyho.com/2015/01/09/headless-browser-testing-xvfb/

If anyone reached here - the answers are outdated. Chromium (on next release) now supports headless mode. no need to work hard.

You can read more here:

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:

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

In my environments I found I can remove the binary property as new version of chrome is available on stable branches

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:

 browsers: 'ChromeHeadless'

it should work with the chrome loader and everything. more info

alecxe

I would continue testing in normal browsers with a head, but would use a remote selenium server as a service - Sauce Labs or BrowserStack, see:

You could run your Protractor tests against CodeShip or Drone.io, both of which offer Chrome and/or Firefox running headless for free. No really...

If you've got Chrome 59+ installed, start Chrome with the following flag:

--headless

please let me know if you need more help, will write the config for you :) enjoy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!