Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
nightwatch
Advanced tools
Easy to use Node.js based end-to-end testing solution for web applications using the W3C WebDriver API.
Nightwatch is an end-to-end testing framework for web applications and websites, written in Node.js. It uses the W3C WebDriver API to perform commands and assertions on DOM elements. Nightwatch is designed to be easy to set up and use, and it provides a powerful and flexible API for writing tests.
End-to-End Testing
Nightwatch allows you to perform end-to-end testing by automating browser interactions. This example initializes the browser, navigates to a URL, waits for the body element to be visible, asserts the page title, and then ends the session.
const { client } = require('nightwatch');
client.init()
.url('http://example.com')
.waitForElementVisible('body', 1000)
.assert.title('Example Domain')
.end();
Page Object Model
Nightwatch supports the Page Object Model, which helps in organizing your test code by separating the page-specific selectors and actions from the test logic. This example shows how to define a page object and use it in a test.
module.exports = {
url: 'http://example.com',
elements: {
body: 'body',
title: 'title'
}
};
// In your test file
const examplePage = client.page.example();
examplePage.navigate()
.waitForElementVisible('@body', 1000)
.assert.title('Example Domain');
Assertions
Nightwatch provides a variety of built-in assertions to validate the state of your application. This example demonstrates how to assert that the body element contains specific text.
client.init()
.url('http://example.com')
.waitForElementVisible('body', 1000)
.assert.containsText('body', 'Example Domain')
.end();
Selenium WebDriver is a popular tool for automating web applications for testing purposes. It provides a more low-level API compared to Nightwatch, which can offer more flexibility but requires more setup and boilerplate code.
Cypress is a modern end-to-end testing framework that aims to make testing fast, easy, and reliable. Unlike Nightwatch, Cypress runs in the same run-loop as your application, which allows for more consistent and reliable tests. However, it currently only supports JavaScript.
WebdriverIO is a test automation framework that allows you to run tests based on the WebDriver protocol and Appium. It offers a more extensive plugin system compared to Nightwatch, allowing for greater customization and integration with other tools.
Nightwatch is an integrated testing framework powered by Node.js and using the W3C Webdriver API. It is a complete testing solution developed at BrowserStack and which can be used for:
☑️ end-to-end testing of web applications and websites
☑️ component testing in isolation (React / Vue / Storybook / Angular)
☑️ Node.js unit, visual regression testing, accessibility testing & API testing
☑️ Native mobile app testing on Android & iOS
What's New | Release Notes | Discussions
Nightwatch v3 is an all new generation that has been built around these three pillars:
Developer Experience : The entire experience from getting started, to writing and debugging tests, has been redesigned for speed, stability, and consistent non-flaky results.
Mobile first: Test your web or native, iOS and Android, mobile applications on simulators, real mobile devices or a cloud grid like BrowserStack.
One test automation framework: Run all types of tests from unit, component, and E2E to API, visual, and accessibility with a single framework.
The Nightwatch v3 is not just a new version, it’s the result of months of engineering effort to reimagine test automation for the future. Try it out in 60 seconds and see it in action.
From your existing project's root dir:
npm init nightwatch@latest
or, if you want to initialize a new project:
npm init nightwatch@latest ./path/to/new/project
Nightwatch will do the entire setup for you based on your answers.
Nightwatch comes with a few examples, which are automatically copied to your Nightwatch project during the setup and can also be used as boilerplate to write your own tests on top of them.
You can follow the instructions given at the end of the setup to run your first test with Nightwatch.
Nightwatch enables automation testing of native mobile applications via Appium. It combines the robustness of Appium with the enhanced developer experience provided by Nightwatch. It enables end-to-end functional testing of native mobile apps on Android and iOS devices. Try it now
With Nightwatch you can test components in isolation by mounting them in the browser. Nightwatch 2 added support for component testing for popular web frameworks such as
The tests for Nightwatch are written using Mocha.
Clone the project
$ git clone https://github.com/nightwatchjs/nightwatch.git
$ cd nightwatch
$ npm install
Run tests
To run the complete test suite:
$ npm test
To check test coverage, run the command:
$ npm run mocha-coverage
and then open the generated coverage/index.html file in your browser.
See Unit testing guide for more details.
Nightwatch v3 introduces visual regression testing as an in-house plugin. The plugin takes care of
VRT can be done on real desktop & mobile browsers. Also, VRT can be run on components as part of component testing as well.
API testing is now available with Nightwatch v3. The following functionality can be achieved with API testing
Nightwatch v3 packages the aXe-core package developed by Deque Systems as a plugin. It enables 90 different types of accessibility tests for WCAG compliance.
Nightwatch was initially built by @pineviewlabs - an independent software consultancy based in Oslo, Norway, with help from contributors. In mid 2021, Nightwatch has become a part of the @BrowserStack family and it is being developed further at the BrowserStack Open-source Program Office. Read more on our blog.
We welcome any and all contributions from the community which can help improve Nightwatch. Please check out CONTRIBUTING.md for more extensive contributing guidelines.
FAQs
Easy to use Node.js based end-to-end testing solution for web applications using the W3C WebDriver API.
The npm package nightwatch receives a total of 122,284 weekly downloads. As such, nightwatch popularity was classified as popular.
We found that nightwatch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.