Run Nightwatch tests on Jenkins
In this article, you will learn how to create and run Nightwatch tests on Jenkins
Jenkins is a long-term industry standard for continuous integration. Jenkins can be used to execute tests on the same instances or on cloud-service providers such as BrowserStack. You can also review the results post the execution of the tests.
- Installed Jenkins instance
- Nightwatch tests uploaded on Git
Run on Jenkins instance
1. Choose "Freestyle project" and name the project according to your project
2. Setup source code management to fetch tests from the git repository to fetch the latest test version.
Make sure the git branch is mentioned correctly. You can find the source code management settings under "Configure->General".
3. Setup Node plugin by going to
dashboard -> Manage Jenkins -> Plugin Manager, searching for
NodeJS Plugin and installing it.
Jenkins executes the pipeline in a blank shell instance. In order to use
npm commands, the NodeJS plugin would have to be installed.
4. Setup the pipeline to use the NodeJS plugin by select the Node JS option under
5. Add an
Execute shell build step along with following commands.
npm install npm test
Your build is ready to be triggered. When you build this job, you will notice that your tests are running on the Jenkins instance.
Run on Cloud Service Providers from Jenkins
Run on BrowserStack
In order to run your tests on BrowserStack from Jenkins, setup the environment variables by going to "Manage Jenkins-> Configure System -> Environment Variables"
Setup the following 2 environment variables
The setup is done. You can execute the tests by updating the test exection shell command in the build steps
npm test -- --env browserstack
Once you build, the tests will be executed on BrowserStack.
View JUnit XML reports
Nightwatch publishes XML reports after test-run the same can be used in Jenkins to publish test reports.
1. Make sure Junit Jenkins Plugin is installed
2. Add a post-build action to publish the XML report. Nightwatch by default uses
the tests_output folder to write reports.
3. Run your tests to see the JUnit report in Jenkins.
View HTML reports
Nightwatch also publishes HTML reports which can be published to Jenkins
1. Make sure you have installed the HTML Jenkins plugin.
2. Nightwatch by default writes HTML report to
tests_output/nightwatch-html-report/ that will be used by Jenkins to publish the report.
3. Run your tests to see the HTML report under
Improve this article