Once you’ve installed nightwatch, you will need to create a configuration file. Configuration file can be saved as .json file or .js file. You can choose any of option and both will do the job, but I prefer .js file, because it can contain custom variables and comments. Comments in configuration file can be helpful because maybe someone from your team will use this file and can easily understand which command do which task.

After installing, nightwatch will create its default nightwatch.js configuration file. You can edit this one, but I don’t recommend, it’s easier to create your own .js file inside your project where you can have all necessary configurations. If the name of the file is nightwatch.conf.js it will be loaded by default when nightwatch command for running test is invoked from the command line. Using both configuration files is also possible, with nightwatch.conf.js always taking precedence if both are found.

Run the test:

 

nightwatch {path to the test}/MyFirstTest.js --{different options}

 

You can also create .js file with custom name (customName.js), then command to run the test should look like:

 

nightwatch --config customName.js {path to the test}/MyFirstTest.js --{different options}

 

 

I will try to explain some basic options in the config file. All options are based on key : value pair.

src_folders” : [“./tests”] — location of the tests (this “./tests” says that my config file and tests folder are in the same folder. You can put your tests in any folder, just make sure you provide correct path here. [ ] – square brackets are here because it allows array of folders that contains tests.)

output_folder” : “./reports” — location of XML reports

“page_objects_path” : “./pages” — parth to the Page Objects used in Tests

 

Below are a number of options for the selenium server process.

“start_process” : true — allows nightwatch to start selenium, selenium don’t need to be run manually.

“server_path”: “{path to the selenium.jar file}” — selenium server standalone should be downloaded and provide path to the selenium.jar file here

“webdriver.chrome.driver” : “{path to chromedriver file}” — chromedriver needs to be downloaded to run tests on chrome

 

Using screenshots in your tests:

“test_settings”: {
   “default”: {
     “screenshots”: {
       “enabled”: true, — if you want to keep screenshots
       “path”: ‘./screenshots’ — save screenshots here
    }
}

Here are listed just some basic configurations to get idea how nightwatch configuration works. If you need more and fully understanding of how to configure and use Nightwatch, I recommend official Nightwatch site with plenty of documentation and examples. Also good step-by-step tutorial can be found here.