In today's Testing Analyst workshop, we played around with Nightmare.js, a JavaScript browser automation library that is useful for testing website interfaces.
It is easier to work with Nightmare on your computer, rather than to use it in Cloud9. Here are the instructions to install and get started.
JavaScript normally runs in the browser. Node.js is a version of JS that can run on a server, in a terminal, or on some other device. It allows you to easily prepare and run Nightmare scripts.
Nightmare is a library that you can install through the Node Package Manager (npm). With npm, when you install Nightmare, all of its dependencies will also be installed.
Create a folder on your computer where you want to run Nightmare scripts. Then, save the package.json
file included in this Gist to that folder. This file informs npm that you will use Nightmare and its dependencies.
npm i
This command is short for "install" and it will set up Nightmare and all the dependencies for you.
Try one of the scripts in this Gist, or your own, to make sure everything is working. Navigate to the folder in your terminal using cd
and then run:
node filename.js
We covered some basic features of Nightmare today. Check out the documentation and examples to see what other features can help you.
If you want to learn more about how to "select" elements from the HTML page so that you can click on them, type into them, or extract information from them in your Nightmare scripts, check out this article.