What is a good headless browser to run with protractor?

前端 未结 5 998
一整个雨季
一整个雨季 2020-12-30 04:31

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

5条回答
  •  萌比男神i
    2020-12-30 05:03

    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

提交回复
热议问题