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.
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 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-browserstack.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
nightwatch -e chrome --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
browserstack.conf.js.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-chrome
-
* Reports will generate under tests_output folder.