Skip to content

Instantly share code, notes, and snippets.

@web-padawan
Last active January 19, 2018 20:25
Show Gist options
  • Save web-padawan/7e63f24c574a596b29fb8ae58a46a4e3 to your computer and use it in GitHub Desktop.
Save web-padawan/7e63f24c574a596b29fb8ae58a46a4e3 to your computer and use it in GitHub Desktop.

What?

Testing Polymer 2 web components against headless browsers: Chrome and Firefox.

Why ?

Great for automated testing, GUI like xvfb no longer needed for these browsers.

How?

  1. Update web-component-tester dependency to 6.5.0:
rm -rf node_modules && npm i web-component-tester@^6.5.0 --save-dev
  1. Add the following plugins section to wct.conf.js config file:
module.exports = {
  plugins: {
    local: {
      browserOptions: {
        chrome: [
          'headless',
          'disable-gpu'
        ],
        firefox: [
          '-headless'
        ]
      }
    }
  }
}
  1. Run tests like you usually do: npm test, wct, polymer test etc.

Summary

  • Big test suites with hundreds of tests run faster with headless browsers
  • Headless Firefox takes a couple of more seconds to start and run tests than headless Chrome
  • Use carefully: hacky stuff like focus monkey-patching cause headless Chrome to fail

See also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment