Acceptance testing of Meteor Application using Selenium-Nightwatch and Velocity

In my previous tutorial, I presented how to develop Meteor applications in BDD style with unit testing and integration testing. It is time to explore, how to perform acceptance testing of your app. For this, we have selected the selenium-nightwatch package and velocity.

Since this is my first time using this test suite, I plan to learn about it as I write. If you have any comments, please let me know if I am using it incorrectly

I started by reading the documentation at the Github page of the Selenium-Nightwatch project and tried to install the package according to following instructions from the author. This is where my problems begun, since author stressed that it is required to run meteor with administrator privileges, what completely messed up build of all my packages and from this moment on I had to run all my meteor projects with administrator privileges. I shrieked in horror. After several hours of trial and error I messed up my whole Meteor installation and had to reinstall Node.js, Meteor and all Meteorite packages (I deleted them from ~/.meteorite directory).

I really did not want to run Meteor with admin privileges, so I spent quite some time figuring it out. Following is a bash script which will safely bring selenium-nightwatch into your project, without requiring to run meteor as administrator (yet nightwatch still has to be run with administrator privileges). Also, in my approach I install night watch globally, sine the provided scripts try to install night watch into project directory, what many times failed and also required admin privileges to run meteor.

// in terminal
$ cd toYourProjectRoot
$ mrt add selenium-nightwatch
$ sudo -H npm install -g nightwatch
$ ln -s packages/selenium-nightwatch/
$ ln -s packages/selenium-nightwatch/

Now we need to modify the launcher scripts, so that they do not call the local night watch instance, but the global one (I have commented out original functionality and added mine):

# file: packages/selenium-nightwatch/
#echo "installing nightwatch in .meteor/local/build"
#  cd .meteor/local/build
#  sudo npm install nightwatch@0.5.3
#  cd ../../../

echo "running nightwatch from app root"
#   sudo .meteor/local/build/node_modules/nightwatch/bin/nightwatch -c packages/selenium-nightwatch/nightwatch_from_app_root.json $1 $2
sudo nightwatch -c packages/selenium-nightwatch/nightwatch_from_app_root.json $1 $2

Also we modify the launcher file for velocity:

# file: packages/selenium-nightwatch/
# echo "installing night watch in .meteor/local/build"
#  cd .meteor/local/build
#  sudo npm install nightwatch@0.5.3
#  cd ../../../

echo "velocity is launching nightwatch"
#   sudo .meteor/local/build/node_modules/nightwatch/bin/nightwatch -c packages/selenium-nightwatch/nightwatch_from_velocity.json $1 $2
sudo nightwatch -c packages/selenium-nightwatch/nightwatch_from_velocity.json $1 $2

WARNING! Up to date I was not able to run selenium-nightwatch with Velocity due to the possible bug in parsing the selenium report files. I had to delete all selenium-nightwatch report files to restore the functionality. I will update this tutorial once I will be sure that it works.

We are ready to run your acceptance tests! To run tests for velocity call simply ./ in your application root.

To run tests without velocity run ./ -t path/to/testfile.js. In this tutorial we will be running the test only in terminal, since velocity was crashing our app when parsing selenium report.

We are ready to write our first test! The documentation makes it look dead simple, so let’s get right to it. First, I checked in smart.json file how velocity identifies test suites. In case of selenium-nightwatch package, this information resides in nightwatch_from_velocity.json file and tells us following "src_folders" : ["tests/nightwatch"]. So, we create a directory in /tests/nightwatch and try to code our first acceptance test.

// file: tests/nightwatch/helloworld-test.js
module.exports = {
"Hello World" : function (client) {
.waitForElementVisible("body", 1000)
.assert.title("Hello World")

We run this test in terminal with ./ -t tests/nightwatch/admin-test.js and obtain following result:


Since in our template we did not set the page title our test fails. Great, we got it working! Let’s try to write something more meaningful related to our application! In this test, we expand the example from our previous tutorial and we perform following checks:

  1. Login as admin in the introduction (home) page
  2. We navigate to “/createTutorial” page
  3. We create a new tutorial
  4. We check that after this tutorial was created, application redirects to “tutorials” page

And here is the code of the test:

module.exports = {
    "Test admin functionality - create, modify and delete tutorial" : function (client) {
            .waitForElementVisible("body", 1000)
            .click("li#login-dropdown-list a")
            .setValue("input#login-email", "")
            .setValue("input#login-password", "apple1")
            .setValue("input#tutorialName", "NightWatchTutorial")
            .setValue("input#tutorialCapacity", "10")

We run this test as ./ -t tests/nightwatch/admin-test.js and following is the output we obtain in console:


Mission accomplished, well, at least part of it! You can download the code from GitHub.


4 thoughts on “Acceptance testing of Meteor Application using Selenium-Nightwatch and Velocity

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s