Convert Figma logo to code with AI

nightwatchjs logonightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack

11,782
1,311
11,782
284

Top Related Projects

46,661

Fast, easy and reliable testing for anything that runs in a browser.

88,205

JavaScript API for Chrome and Firefox

Next-gen browser and mobile automation test framework for Node.js

30,175

A browser automation framework and ecosystem.

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

18,634

Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol

Quick Overview

Nightwatch.js is a powerful end-to-end (E2E) testing framework for web applications. It uses the W3C WebDriver API to control the browser and perform automated tests, making it a popular choice for cross-browser testing and UI automation.

Pros

  • Ease of Use: Nightwatch.js provides a simple and intuitive API for writing and running tests, making it accessible for developers of all skill levels.
  • Cross-Browser Testing: Nightwatch.js supports multiple browsers, including Chrome, Firefox, Safari, and Edge, allowing for comprehensive cross-browser testing.
  • Parallel Test Execution: Nightwatch.js can run tests in parallel, improving the overall test execution time.
  • Extensibility: Nightwatch.js can be extended with custom commands, assertions, and plugins, providing flexibility for complex testing scenarios.

Cons

  • Limited Asynchronous Handling: Nightwatch.js can sometimes struggle with handling asynchronous operations, which can lead to flaky tests.
  • Steep Learning Curve: While the API is relatively simple, the overall testing framework can have a steep learning curve, especially for developers new to E2E testing.
  • Dependency on Selenium: Nightwatch.js relies on the Selenium WebDriver, which can be a potential point of failure and may require additional configuration.
  • Limited Debugging Tools: Nightwatch.js has limited built-in debugging tools, which can make it challenging to diagnose and fix issues with failing tests.

Code Examples

Here are a few code examples demonstrating the usage of Nightwatch.js:

// Example 1: Performing a simple Google search
module.exports = {
  'Google Search Test': function (browser) {
    browser
      .url('https://www.google.com')
      .waitForElementVisible('body', 1000)
      .setValue('input[name="q"]', 'Nightwatch.js')
      .click('button[name="btnK"]')
      .assert.titleContains('Nightwatch.js')
      .end();
  }
};
// Example 2: Interacting with a form
module.exports = {
  'Form Interaction Test': function (browser) {
    browser
      .url('https://example.com/form')
      .waitForElementVisible('form', 1000)
      .setValue('input[name="name"]', 'John Doe')
      .setValue('input[name="email"]', 'john.doe@example.com')
      .click('button[type="submit"]')
      .assert.urlContains('/success')
      .end();
  }
};
// Example 3: Performing a data-driven test
const testData = [
  { username: 'user1', password: 'pass1' },
  { username: 'user2', password: 'pass2' },
  { username: 'user3', password: 'pass3' }
];

module.exports = {
  'Login Test': function (browser) {
    testData.forEach(data => {
      browser
        .url('https://example.com/login')
        .waitForElementVisible('form', 1000)
        .setValue('input[name="username"]', data.username)
        .setValue('input[name="password"]', data.password)
        .click('button[type="submit"]')
        .assert.urlContains('/dashboard')
        .back();
    });
    browser.end();
  }
};

Getting Started

To get started with Nightwatch.js, follow these steps:

  1. Install Node.js and npm (the Node.js package manager) on your system.
  2. Create a new directory for your project and navigate to it in your terminal.
  3. Initialize a new npm project by running npm init -y.
  4. Install Nightwatch.js and its dependencies by running npm install nightwatch --save-dev.
  5. Create a nightwatch.conf.js file in the root of your project directory and configure the settings for your tests.
  6. Write your first test in a new file (e.g., tests/example.js) using the Nightwatch.js API.
  7. Run your tests

Competitor Comparisons

46,661

Fast, easy and reliable testing for anything that runs in a browser.

Pros of Cypress

  • Easier setup and configuration
  • Built-in automatic waiting and retry mechanisms
  • More intuitive debugging with time-travel and real-time reloads

Cons of Cypress

  • Limited cross-browser support (primarily focused on Chrome)
  • Cannot interact with multiple browser tabs or windows
  • Lacks support for testing native mobile apps

Code Comparison

Nightwatch example:

module.exports = {
  'Demo test' : function (browser) {
    browser
      .url('https://example.com')
      .waitForElementVisible('body', 1000)
      .assert.titleContains('Example')
      .end();
  }
};

Cypress example:

describe('Demo Test', () => {
  it('Visits the example page', () => {
    cy.visit('https://example.com')
    cy.get('body').should('be.visible')
    cy.title().should('include', 'Example')
  })
})

Both Nightwatch and Cypress are popular end-to-end testing frameworks for web applications. Nightwatch offers broader browser support and the ability to test across multiple tabs, making it suitable for complex scenarios. On the other hand, Cypress provides a more developer-friendly experience with its intuitive API and powerful debugging tools. The choice between the two often depends on specific project requirements and team preferences.

88,205

JavaScript API for Chrome and Firefox

Pros of Puppeteer

  • Offers more granular control over browser automation
  • Supports both Chrome and Firefox browsers
  • Provides a rich API for PDF generation and performance analysis

Cons of Puppeteer

  • Steeper learning curve for beginners
  • Limited built-in support for test assertions and reporting
  • Requires more setup and configuration for test automation frameworks

Code Comparison

Nightwatch example:

module.exports = {
  'Demo test': function(browser) {
    browser
      .url('https://example.com')
      .waitForElementVisible('body')
      .assert.titleContains('Example')
      .end();
  }
};

Puppeteer example:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.waitForSelector('body');
  const title = await page.title();
  console.assert(title.includes('Example'));
  await browser.close();
})();

Both Nightwatch and Puppeteer are powerful tools for browser automation and testing. Nightwatch provides a higher-level API with built-in test assertions and reporting, making it easier for beginners to get started. Puppeteer offers more fine-grained control over browser interactions and supports advanced features like PDF generation and performance analysis. The choice between the two depends on the specific project requirements and the team's expertise.

Next-gen browser and mobile automation test framework for Node.js

Pros of WebdriverIO

  • More extensive plugin ecosystem and third-party integrations
  • Better support for modern JavaScript features and async/await syntax
  • Easier setup and configuration process, especially for beginners

Cons of WebdriverIO

  • Steeper learning curve for complex scenarios and custom configurations
  • Slightly slower test execution compared to Nightwatch
  • Documentation can be overwhelming due to the large number of features

Code Comparison

WebdriverIO:

describe('My Login Application', () => {
    it('should login with valid credentials', async () => {
        await browser.url('https://example.com/login');
        await $('#username').setValue('myuser');
        await $('#password').setValue('mypassword');
        await $('button[type="submit"]').click();
        await expect($('#logged-in-message')).toBeExisting();
    });
});

Nightwatch:

module.exports = {
    'Login Test': function(browser) {
        browser
            .url('https://example.com/login')
            .setValue('#username', 'myuser')
            .setValue('#password', 'mypassword')
            .click('button[type="submit"]')
            .assert.elementPresent('#logged-in-message');
    }
};

Both WebdriverIO and Nightwatch are powerful end-to-end testing frameworks for web applications. WebdriverIO offers more flexibility and modern features, while Nightwatch provides a simpler API and faster execution. The choice between them depends on project requirements and team preferences.

30,175

A browser automation framework and ecosystem.

Pros of Selenium

  • Wider language support (Java, Python, C#, Ruby, JavaScript)
  • More extensive ecosystem with numerous tools and integrations
  • Greater community support and resources

Cons of Selenium

  • Steeper learning curve, especially for beginners
  • Requires more setup and configuration
  • Can be slower in execution compared to Nightwatch

Code Comparison

Selenium (Java):

WebDriver driver = new ChromeDriver();
driver.get("https://www.example.com");
WebElement element = driver.findElement(By.id("search"));
element.sendKeys("test");
element.submit();

Nightwatch:

module.exports = {
  'Demo test': function(browser) {
    browser
      .url('https://www.example.com')
      .setValue('#search', 'test')
      .submitForm('#search-form');
  }
};

Summary

Selenium offers broader language support and a more extensive ecosystem, making it suitable for complex testing scenarios across various platforms. However, it can be more challenging to set up and use, especially for beginners.

Nightwatch, on the other hand, provides a more straightforward approach with its Node.js-based framework, making it easier to get started and potentially faster in execution. However, it may lack some of the advanced features and integrations available in Selenium's ecosystem.

The choice between the two depends on project requirements, team expertise, and the desired level of customization and integration with other tools.

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

Pros of Playwright

  • Cross-browser support for Chromium, Firefox, and WebKit
  • Built-in auto-wait functionality for improved test stability
  • Powerful API for handling modern web features like shadow DOM

Cons of Playwright

  • Steeper learning curve for beginners
  • Less extensive documentation compared to Nightwatch
  • Relatively newer project with a smaller community

Code Comparison

Playwright:

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await browser.close();
})();

Nightwatch:

module.exports = {
  'Demo test' : function (browser) {
    browser
      .url('https://example.com')
      .waitForElementVisible('body')
      .end();
  }
};

Summary

Playwright offers more advanced features and cross-browser support, making it suitable for complex web applications. Nightwatch, on the other hand, provides a simpler API and extensive documentation, making it more accessible for beginners. Both tools have their strengths, and the choice between them depends on the specific project requirements and team expertise.

18,634

Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol

Pros of Appium

  • Cross-platform support for mobile and desktop applications
  • Supports multiple programming languages (Java, Python, Ruby, etc.)
  • Allows testing on real devices and emulators/simulators

Cons of Appium

  • Slower test execution compared to Nightwatch
  • More complex setup and configuration process
  • Steeper learning curve for beginners

Code Comparison

Appium (JavaScript):

const driver = await wdio.remote(opts);
await driver.init();
await driver.$('~myButton').click();
await driver.deleteSession();

Nightwatch:

module.exports = {
  'My Test': (browser) => {
    browser
      .url('http://example.com')
      .click('#myButton')
      .end();
  }
};

Appium focuses on mobile app testing with a more flexible approach, supporting various platforms and languages. It's ideal for complex mobile testing scenarios but requires more setup time. Nightwatch is primarily for web application testing, offering a simpler syntax and faster execution. It's better suited for web-based projects and beginners. The code examples show Appium's session-based approach for mobile testing, while Nightwatch uses a more straightforward syntax for web testing.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Nightwatch.js

npm Node.js CI codecov Discord

Nightwatch.js Logo

HomepageDeveloper GuideAPI ReferenceAboutBlog

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

🚀 Nightwatch v3

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.

⚙️ Get started in 60 seconds

1. Install Nightwatch from NPM

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-cli-gif

2. Answer a few questions about your preferred setup:

  • What is your Language - Test Runner setup?
  • Where do you want to run your e2e tests?
  • Where you'll be testing on?
  • Where do you plan to keep your end-to-end tests?
  • What is the base_url of your project?

Nightwatch will do the entire setup for you based on your answers.

3. Run a Demo Test:

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.

image

Nightwatch mobile app testing

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

Go beyond E2E

Component testing

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

  1. React
  2. VueJS
  3. Angular
  4. Storybook

Nightwatch unit tests

The tests for Nightwatch are written using Mocha.

  1. Clone the project

    git clone https://github.com/nightwatchjs/nightwatch.git
    
    # change directory
    cd nightwatch
    
    # install the dependencies
    npm install
    
  2. 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.

Other types of testing

Visual Regression Testing

Nightwatch v3 introduces visual regression testing as an in-house plugin. The plugin takes care of

  1. Capturing screenshots
  2. Comparison with baseline to highlight visual differences
  3. Report to review the differences
  4. Approve the changes

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

API testing is now available with Nightwatch v3. The following functionality can be achieved with API testing

  1. Request assertions
  2. Response assertions
  3. Viewing API tests in the HTML report
  4. Mock server

Accessibility 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.

🦉 About Nightwatch

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.

Contributing

We welcome any and all contributions from the community which can help improve Nightwatch. Please check out CONTRIBUTING.md for more extensive contributing guidelines.

Licence

MIT

NPM DownloadsLast 30 Days