
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
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)
☑️ Node.js unit and API testing
We're delighted to announce that Nightwatch v2 is now available in the public NPM channel. Read the what's new docs page for an overview of the new features, improvements, and important changes.
Install with:
npm i nightwatch
# from your existing project's root dir
$ npm init nightwatch
# if you want to initialize a new project
$ npm init nightwatch 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.
Examples below are written using Nightwatch 2.
element()
global apiYou can run any of the examples by simply referring to the examples folder like below:
npx nightwatch examples/tests/angularTest.js
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
Nightwatch uses a WebDriver compatible server to control the browser. WebDriver is a W3C specification and industry standard which provides a platform and HTTP protocol to interact with a browser.
Nightwatch includes support for automatically managing the following services:
selenium-server-standalone-4.x.x.jar
can be downloaded from the Selenium releases page: https://selenium-release.storage.googleapis.com/index.htmlIt's important to note that, while the Selenium Server was required with older Nightwatch versions (
v0.9
and prior), starting with version1.0
the Selenium Server is no longer necessary.
Specific WebDriver setup guides can be found on the Docs website. Legacy Selenium drivers setup guides along with debugging instructions can be found on the Wiki.
The tests for Nightwatch are written using Mocha.
$ git clone https://github.com/nightwatchjs/nightwatch.git
$ cd nightwatch
$ npm install
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.
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 are thankful for everyone who supported Nightwatch on the OpenCollective platform.
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 116,612 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 0 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
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.