Running Nightwatch E2E Tests with Headless Chrome and Vue CLI 3
Tags: vue, nightwatch, e2e, chrome
Published: 2019-07-31 03:57:37

---
layout: post
title: "Running Nightwatch E2E Tests with Headless Chrome and Vue CLI 3"
published: true
description: "If you want to run automated browser tests on a server without a dedicated GUI, you'll need to run Chrome in headless mode. Here's how to do it with the Nightwatch Vue CLI 3 plugin."
tags: [vue.js,nightwatch,e2e,chrome]
cover_image: https://vuejsdevelopers.com/images/posts/versions/vue_nightwatch_headless_chrome_1200.webp
code: vcn
level: advanced
ad: ev 
---

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 "headless" mode. However, if you're using the Nightwatch plugin for Vue CLI 3, the default settings will be for regular Chrome, not headless.

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. 

> Skip to a [working version using Vagrant](https://github.com/anthonygore/vue-vagrant-headless-chrome).

## 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.

*provision.sh*

```bash
apt-get update -y && \

## Install Node and NPM

cd /opt && \
wget https://nodejs.org/dist/v10.15.3/node-v10.15.3-linux-x64.tar.xz && \
tar xf node-v10.15.3-linux-x64.tar.xz && \
ln -s -f /opt/node-v10.15.3-linux-x64/bin/node /usr/local/bin/node && \
ln -s -f /opt/node-v10.15.3-linux-x64/bin/node-waf /usr/local/bin/node-waf && \
ln -s -f /opt/node-v10.15.3-linux-x64/bin/npm /usr/local/bin/npm && \

## Install Vue CLI 3

npm install -g @vue/cli@3.5.0 && \
echo "export PATH=\"$PATH:/opt/node-v10.15.3-linux-x64/bin\"" >> /home/vagrant/.bashrc && \
source /home/vagrant/.bashrc && \

## Install Chrome

apt install -y openjdk-11-jdk && \
apt-get install -y libdbusmenu-gtk3-4 libappindicator3-1 libgtk-3-0 libxss1 xdg-utils fonts-liberation && \
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -P /tmp/ && \
dpkg -i /tmp/google-chrome*.deb
```

## 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 Nigthwatch plugin doesn't have a config file, so you'll need to create one in the root of your Vue project:

```bash
$ touch nightwatch.json
```

*nightwatch.json*

```json
{
  "test_settings": {
    "chrome": {
      "desiredCapabilities": {
        "chromeOptions": {
          "args": [
            "--headless",
            "--no-sandbox",
            "--disable-gpu"
          ]
        }
      }
    }
  }
}
```

*Note: any settings we add here will be merged with the [default config](https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-plugin-e2e-nightwatch/nightwatch.config.js).*

<content-ad />

## Running tests

If you followed the above tests, your set up is now complete. From the server you've installed this on, run:

```bash
$ npm run test:e2e
```

Fingers crossed you'll see some green ticks!

* * *

**Enjoy this article?**

Get more articles like this in your inbox weekly with the *Vue.js Developers Newsletter*.

[Click here to join!](https://vuejsdevelopers.com/newsletter?utm_source=devto&utm_medium=article)

* * *