Running Nightwatch tests in Acquia Cloud IDEs
- Last updated
- 1 minute read
Goal
Learn how to run Nightwatch tests to test your Drupal application on Acquia Cloud IDEs.
Overview
This is a follow up to "Running Nightwatch tests in Acquia Code Studio". As one "normally" may want to run some tests prior to actually committing and opening a merge request in Code Studio, it would stand to reason that we may want to run our tests on the Cloud IDE first. For that purpose lets explore what we would need to do to achieve that.
-
A simple Nightwatch test
To start, let's first copy our simple Nightwatch test from our "Running Nightwatch tests in Acquia Code Studio" tutorial. This test verifies Drupal is up and running by navigating to the Drupal login page and checking to see if the expected fields are present. If you already have Nightwatch tests for your application, you can go ahead and skip to the next step.
At the root of our project, we will create the directories "tests/src/Nightwatch/Tests" and "tests/src/Nightwatch/Commands". For the purposes of this tutorial, we will only be using the first one to hold our simple test that checks whether we can access Drupal's login screen. In the other, you can put any custom Nightwatch commands you may have that help with running your tests.
So, once we have our tests directory, let's go ahead and create a file called "checkDrupalLoginScreen.js" and add the following inside:
Make note of the tag "myproject" we added to our test as we will use it later to run it.
-
Setup
Drupal and Nightwatch settings
Find your Drupal core directory. If you installed your application using Acquia's acquia/drupal-recommended project, that should be "docroot/core". Inside Drupal's core directory create a file named ".env".
Open this file in the IDE and add the following variables inside:
Yarn
Lets make sure Yarn is installed. Open a terminal window and run:
The first command installs Yarn (in case it wasn't already installed) and the 2nd makes it available to the current terminal.
Once yarn is installed we can install core's front end dependencies, which includes chromedriver, which will help us run our tests.
Chromedriver
Acquia Cloud IDEs ship with several tools in place that help make our developer lives easier. One such tool is Chromedriver which is used for running Drupal's functional Javascript tests. We can launch Chromedriver by running:
Passing the
&
character at the end of the command allows the process to continue running in the background.Once Chromedriver is successfully running we can proceed to run our tests.
When we are finished, we can stop the Chromedriver process by running
-
Running our tests
Finally to run our tests we have a few options. From the root of our project we can:
- Run all tests we have in our project (this will include Drupal core's Nightwatch tests as well which may not always be wanted):
- Run tests of a particular tag (e.g only tests related to our project):
- Run all tests included in a particular file e.g.:
- Run a particular test case in a particular file: