We're delighted to present the first beta version of Nightwatch v2.0! Upcoming beta releases will incrementally be made available in NPM under the next tag, so in order to install it you'll have to run the following:
npm i nightwatch@next
Over the coming weeks we will also finish updating the documentation website with more pages in the Guide section and documenting the new APIs.
Important Changes
Since the previous alpha release we have only added a few improvements and several fixes. The fixes are mainly concerning working with the new element()
api and using cucumber-js.
Improvements
- Added dragAndDrop element command which uses the new Actions API from Selenium – #2920;
- Added support to use the config file as Promise – #2896
- Added support to use glob patterns in config for
src_folders
,page_object_path
,custom_commands_path
,custom_assertion_path
options – #2910; - Added new
webdriver.log_file_name
setting to specify the filename where webdriver server logs should be written – 1277601 - Added support to write individual webdriver server logs for each test suite – 1277601
- Added support to define page object commands as an ES6 class – example db03e68;
- Added support to use Selenium WebElement ids as arguments to element commands, such as
.click()
, e.g.:
// with async
const elements = await browser.findElements('input');
await browser.click(elements[1]);
// with callback
browser.findElements('input', function(result) {
browser.click(result.value[1]);
});
Fixes
- Reverted
getAttribute
command to use the W3C endpoint instead of the Selenium atom script - #2926; - Fixed an issue where the session was hanging after a failure when using
suiteRetries
– 1277601
Examples
We've also updated the bundled examples so do make sure to check those out in order to get a better feel about the new Nightwatch 2 features.
Search for the term "Nightwatch.js" using:
- Google: examples/tests/google.js
- DuckDuckGo: examples/tests/duckDuckGo.js
- Ecosia.org: examples/tests/ecosia.js
Google search using page objects
ToDo App on AngularJs homepage
- examples/tests/angularTest.js
- this contains demo on how to use the new
element()
global api
You can run any of the examples by simply referring to the examples folder like below:
npx nightwatch examples/tests/angularTest.js
CucumberJS examples
The bundled config file which is auto-generated by Nightwatch on the first run (only if one is not already present in the project), contains configuration and examples for running the CucumberJS examples immediately, using the following:
npx nightwatch --env cucumber-js