From f633e0dcacd5f6307ef77b3a40d642310e7e60ee Mon Sep 17 00:00:00 2001 From: Paladox none Date: Wed, 17 Jan 2018 19:23:26 +0000 Subject: [PATCH] web-component-tester: Support headless mode This adds support for running chrome in headless mode. Support for running firefox in headless mode should work but currently doesn't. Moreover, i've added browser option handling to wct [1]. [1] https://github.com/Polymer/wct-local/commit/b8388d1a8d3fa907a205dc1763524a13b017e780 Bug: Issue 8023 Change-Id: I47cd9cd69fc78739219223c74d7b2edf2f97d6c7 --- polygerrit-ui/README.md | 11 +++++++++++ polygerrit-ui/app/embed_test.sh | 15 ++++++++++++++- polygerrit-ui/app/run_test.sh | 1 + polygerrit-ui/app/wct_test.sh | 15 ++++++++++++++- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/polygerrit-ui/README.md b/polygerrit-ui/README.md index d444f7972d..c2b0842bb3 100644 --- a/polygerrit-ui/README.md +++ b/polygerrit-ui/README.md @@ -126,6 +126,17 @@ For interactively working on a single test file, do the following: Then visit http://localhost:8081/elements/foo/bar_test.html +To run Chrome tests in headless mode: + +```sh +WCT_HEADLESS_MODE=1 ./polygerrit-ui/app/run_test.sh +``` + +Toolchain requirements for headless mode: + +* Chrome: 59+ +* web-component-tester: v6.5.0+ + ## Style guide We follow the [Google JavaScript Style Guide](https://google.github.io/styleguide/javascriptguide.xml) diff --git a/polygerrit-ui/app/embed_test.sh b/polygerrit-ui/app/embed_test.sh index adcc653fd5..d48279665a 100755 --- a/polygerrit-ui/app/embed_test.sh +++ b/polygerrit-ui/app/embed_test.sh @@ -14,6 +14,15 @@ mkdir -p $t/test cp $index $t/test/ cp $tests $t/test/ +if [ "${WCT_HEADLESS_MODE:-0}" != "0" ]; then + CHROME_OPTIONS=[\'start-maximized\',\'headless\',\'disable-gpu\',\'no-sandbox\'] + # TODO(paladox): Fix Firefox support for headless mode + FIREFOX_OPTIONS=[\'\'] +else + CHROME_OPTIONS=[\'start-maximized\'] + FIREFOX_OPTIONS=[\'\'] +fi + # For some reason wct tries to install selenium into its node_modules # directory on first run. If you've installed into /usr/local and # aren't running wct as root, you're screwed. Turning this option off @@ -33,7 +42,11 @@ module.exports = { }, 'plugins': { 'local': { - 'skipSeleniumInstall': true + 'skipSeleniumInstall': true, + 'browserOptions': { + 'chrome': ${CHROME_OPTIONS}, + 'firefox': ${FIREFOX_OPTIONS} + } }, 'sauce': { 'disabled': true, diff --git a/polygerrit-ui/app/run_test.sh b/polygerrit-ui/app/run_test.sh index 0edf41c5b0..df210b87d5 100755 --- a/polygerrit-ui/app/run_test.sh +++ b/polygerrit-ui/app/run_test.sh @@ -20,6 +20,7 @@ bazel test \ --test_env="WCT_ARGS=${WCT_ARGS}" \ --test_env="NPM=${npm_bin}" \ --test_env="DISPLAY=${DISPLAY}" \ + --test_env="WCT_HEADLESS_MODE=${WCT_HEADLESS_MODE}" \ "$@" \ //polygerrit-ui/app:embed_test \ //polygerrit-ui/app:wct_test diff --git a/polygerrit-ui/app/wct_test.sh b/polygerrit-ui/app/wct_test.sh index e81adfbe19..a8394cdb31 100755 --- a/polygerrit-ui/app/wct_test.sh +++ b/polygerrit-ui/app/wct_test.sh @@ -12,6 +12,15 @@ unzip -qd $t $code mkdir -p $t/test cp $TEST_SRCDIR/gerrit/polygerrit-ui/app/test/index.html $t/test/ +if [ "${WCT_HEADLESS_MODE:-0}" != "0" ]; then + CHROME_OPTIONS=[\'start-maximized\',\'headless\',\'disable-gpu\',\'no-sandbox\'] + # TODO(paladox): Fix Firefox support for headless mode + FIREFOX_OPTIONS=[\'\'] +else + CHROME_OPTIONS=[\'start-maximized\'] + FIREFOX_OPTIONS=[\'\'] +fi + # For some reason wct tries to install selenium into its node_modules # directory on first run. If you've installed into /usr/local and # aren't running wct as root, you're screwed. Turning this option off @@ -31,7 +40,11 @@ module.exports = { }, 'plugins': { 'local': { - 'skipSeleniumInstall': true + 'skipSeleniumInstall': true, + 'browserOptions': { + 'chrome': ${CHROME_OPTIONS}, + 'firefox': ${FIREFOX_OPTIONS} + } }, 'sauce': { 'disabled': true,