Nightwatch is an automated testing framework for web applications and websites, written in Node.js and using the W3C WebDriver API (formerly Selenium WebDriver. It is a complete browser (End-to-End) testing solution which aims to simplify the process of setting up Continuous Integration and writing automated tests.
Nightwatch VRT extends nightwatch.js with an assertion that captures a screenshot of a DOM element identified by a selector and compares the screenshot against a baseline screenshot. If the baseline screenshot does not exist, it will be created the first time you run the test and the assertion will pass.
BrowserStack is a cloud web and mobile testing platform that enables developers to test their websites and mobile applications across on-demand browsers, operating systems and real mobile devices, without requiring users to install or maintain an internal lab of virtual machines, devices or emulators.
This is a sample nightwatch project to run your functional, visual regression tests programmatically on your local and also on cloud platform using BrowserStack.
-
Install node via
brew install node
Or download Node.js -
Do
git clone https://github.com/NageshJoy007/nightwatch-poc.git
-
To download required node_modules specified in package.json
npm install
Go into project folder and run below commands:
-
To run tests using scripts in package.json
npm test
-
To run your tests by default : on firefox
nightwatch ./tests/sample
-
To run your tests using specific browser
nightwatch -e firefox
-
To run your tests & generate html reports
nightwatch -e chrome --reporter html-reporter.js
-
To run your tests on two different browsers parallelly
nightwatch -e chrome,firefox --reporter html-reporter.js
-
To run your tests using specific tag
nightwatch -e chrome --tag smoke --reporter html-reporter.js
-
You can pass different nightwatch configurations/test settings to your tests run time from cli
nightwatch -c ./conf/local.conf.js -e chrome --reporter html-reporter.js
-
To run your tests using BrowserStack - Nightwatch Integration with BrowserStack
-
Get your browserstack account license for automation
-
Export the environment variables for the Username and Access Key of your BrowserStack account
export BROWSERSTACK_USERNAME=<browserstack-username> && export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
-
Or Update
*.conf.js
files inside theconf/
directory with yourbrowserstack-username
andbrowserstack-access-key
.
nightwatch -c ./conf/browserstack.conf.js -e chrome --reporter html-reporter.js
Ornpm run test-bs
- You can also run your tests for local/internal applications using BrowserStack
node scripts/local.runner.js -c conf/browserstack.local.conf.js -e chrome
Ornpm run test-bs-local
- To test on different sets of os, browsers check out our platform configurator
-
-
You can run visual regression tests of your application as below
nightwatch -e chrome -c ./conf/vrt.conf.js --reporter html-reporter.js
nightwatch -e chrome -c ./conf/vrt.bs.conf.js --reporter html-reporter.js
* Reports will generate under tests_output folder.
* You can view your BStack test results on the BrowserStack [Dashboard](https://www.browserstack.com/automate)