npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nightwatch-visual-testing

v2.0.0

Published

This package helps, performing visual testing using NightwatchJS

Downloads

29

Readme

Visual testing using NightwatchJS

This package allows you to perform visual testing using NightwatchJS, it internally extends nightwatch.js.

Whats new?

Just launched a new v2 of this package.

  • Supports Nightwatch v2
  • Additional feature of taking and comparing screenshot of any element, by passing the locator
  • Removed dependency from nightwatch-api

Details and high-level working

  • Perform visual testing using NightwatchJS
  • Uses NightwatchJS provided built-in assertions and commands
  • Uses assertions to capture screenshot of the page (DOM) and compares the screenshot against the reference (baseline) screenshot.
  • If the baseline does not exists, it will be created the very first time you run the test and assertion will pass
  • If the baseline does exists, the comparision of screenshot will be performed pixel to pixel and the difference would be shown in red.

Installation

  • If using nightwatch v1, be sure to install using command:
npm install nightwatch-visual-testing@1
  • For nightwatch v2, install:
npm install nightwatch-visual-testing

Configuration

  1. Add custom command and assertion configuration to your nightwatch.conf.js. You can refer the link
  custom_commands_path: [
    './node_modules/nightwatch-visual-testing/commands'
  ],
  custom_assertions_path: [
    './node_modules/nightwatch-visual-testing/assertions'
  ]
  1. Lastly pass the visual configuration, under the test_settings within the nightwatch.conf.js to be
default: {
  globals: {
    visual_regression_settings: {
      outputDir: './tests_output',
      threshold: 0.5
    },
  },
  • outputDir : Refers to directory path, where the reports needs to be generated (Default: set to 'reports' directory)
  • threshold: Refers to the matching threshold, which ranges from 0 - 1. Smaller the values makes the comparison sensitive (Default: set to 0.5)

Usage

To use the above, we simply need to use the custom assertion compareScreenshot or compareElementScreenshot.

  1. The compareScreenshot currently accepts 2 parameter

| Name | Type | Description | | -------------------- | ------- | ---------------------------- | | name (mandatory) | string | name of the test | | message (mandatory) | string | message on sucess of the test |

module.exports = {
  'Test dikshitashirodkar.com main content is correct': (browser) => {
    browser
      .url('https://dikshitashirodkar.com')
      .assert.compareScreenshot('First test', 'Screenshot captured!')
      .end()
  }
}

Note: Only available in the v2 of this package along with Nightwatchjs v2

  1. The compareElementScreenshot accepts below parameters

| Name | Type | Description | | --------------------- | ------- | ---------------------------- | | using (optional) | string | The locator strategy to use. See W3C Webdriver - locator strategies - default accepts css selector| | selector (mandatory) | string | The CSS/Xpath selector used to locate the element.| | name (mandatory) | string | name of the test | | message (mandatory) | string | message on sucess of the test |

Uses default css selector

module.exports = {
  'Test dikshitashirodkar.com main content is correct': (browser) => {
    browser
      .url('https://dikshitashirodkar.com')
      .assert.compareElementScreenshot('span[title="GitHub"]', 'Testing github logo', 'Captured screenshot OK!')
      .end()
  }
}

Uses any other locate strategy

module.exports = {
  'Test dikshitashirodkar.com main content is correct': (browser) => {
    browser
      .url('https://dikshitashirodkar.com')
      .assert.compareElementScreenshot('xpath', '//span[@title="GitHub"]', 'Testing github logo', 'Captured screenshot OK!')
      .end()
  }
}

Output

A baseline screenshots will be created for the very first time, under tests_output directory.

Note: This package works with NightwatchJS & NightwatchJS with CucumberJS integration too :)