Running Nightwatch E2E Tests With Headless Chrome and Vue CLI 3
I'll show you how to set up an Ubuntu server for headless Chrome, and how to configure the Vue CLI 3 Nightwatch plugin for headless mode.
Join the DZone community and get the full member experience.Join For Free
If you're using a virtual development environment like Vagrant or Docker, or perhaps using a remote server for CI, you may want to run your Nightwatch E2E tests in an environment without a dedicated GUI.
In this case, you're going to need to use Chrome in the "headless" mode; however, if you're using the Nightwatch plugin for Vue CLI 3, the default settings will be for regular Chrome, not headless.
You may also like:
In this brief tutorial, I'll show you how to set up an Ubuntu server for headless Chrome, and how to configure the Vue CLI 3 Nightwatch plugin for headless mode.
Environment Set Up
Your Ubuntu server will need to have Node, NPM, Vue CLI 3, and Chrome installed. You can use the following snippet in a Vagrantfile or manually run it from the terminal.
Vue CLI 3 Nightwatch Plugin Config
The default settings of Vue CLI 3 are for regular Chrome, not headless, so we'll need to change that.
To make Chrome run in headless mode you can simply pass some flags when you boot it from the CLI. If you're using Nightwatch you can add these flags as
args to the Chrome options in the config.
By default, the Vue CLI 3 Nightwatch plugin doesn't have a config file, so you'll need to create one in the root of your Vue project:
$ touch nightwatch.json
Note: any settings we add here will be merged with the default config.
If you followed the above tests, your set up is now complete. From the server you've installed this on, run:
$ npm run test:e2e
Fingers crossed you'll see some green ticks!
Published at DZone with permission of Anthony Gore, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.