Writing a NightwatchJS test
Similar to a functional JavaScript test, NightwatchJS uses Google Chrome to evaluate tests. However, instead of PHP files, the test files are written entirely in JavaScript and require NodeJS and yarn
to run and interact with.
Getting ready
NightwatchJS is not included as part of PHPUnit, so you will need to install it using yarn
:
- Inside the
/core
folder, runyarn install
. - Configure NightwatchJS settings by copying
.env.example
to.env
and editing as necessary. These settings will mostly be the same as your local environment settings.DRUPAL_TEST_BASE_URL
will be the value of your local site URL, for example.
How to do it…
NightwatchJS looks for tests in the following directories:
mymodule/tests/src/Nightwatch/Tests
mymodule/tests/src/Nightwatch/Commands
mymodule/tests/src/Nightwatch/Assertions
mymodule/tests/src/Nightwatch/Pages
Here, mymodule
is your custom module name, like chapter13
, which...