Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@telus/nightwatch-visual

Package Overview
Dependencies
Maintainers
18
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@telus/nightwatch-visual

Nightwatch.js utility assertion for visual testing

latest
Source
npmnpm
Version
2.3.1
Version published
Maintainers
18
Created
Source

Nightwatch VISUAL License

Screenshot comparison assertion for Nightwatch.js

Description

This custom assertion allows you to easily integrate visual regression testing into a Nightwatch test suite.

It uses resemble.js to compare your code change against your approved baseline screenshots of your application.

Installation

# using npm
npm install --global @telus/build-essential
npm install --only-production --save @telus/nightwatch-visual

Usage

Update your nightwatch config:

{
  custom_assertions_path: [
    './node_modules/@telus/nightwatch-visual/assertions',
    './node_modules/@telus/nightwatch-visual/commands'
  ]
}

...

  "test_settings": {
      "nightwatch_visual": {
        "visualTesting": "enabled"
        "defaultSelector": "html",
        "defaultTolerance": 3,
        "defaultPath": "./nightwatch-visual"
      },

Mount your screenshot folder in your Dockerfile

RUN chmod -R g+w /app/tests/nightwatch-visual \

Use in your tests:

module.exports = {
  Test: function(browser) {
    browser.assert.compareScreenshot(fileName, selector, tolerance, path)
  }
}
ParameterDefaultDescription
fileNamebrowserName_browserVersion_testName.pngCustomized output when multiple screenshots on the same test: browserName_browserVersion_fileName.png
selector'html'CSS selector of the targeted component the assertion is ran against
tolerance3% of difference between the baseline and result images from which the assertion will fail
path'path.join(__dirname, '../nightwatch-visual''Folder where to save screenshots. Usefull especially when running with Docker

Workspace Structure

Screenshots will be saved in the \nightwatch-visual\your-test-name\ folders

.
├── nightwatch-visual
│   └── testName
│       ├── baseline
│       │   └── browserName_browserVersion_testName.png
│       ├── diffs
│       │   └── browserName_browserVersion_testName.png
│       └── results
│           └── browserName_browserVersion_testName.png
├── test
│   └── specs
│       └── testName.js
└── ...

Workflow

  • Taking screenshot
  • Create new folders if not exist
  • Creating baseline files if not exist
  • Comparing images
  • Return assertion result

:copyright: TELUS digital • License: ISC • Github: @telus • Twitter: @telusdigital

Keywords

telus

FAQs

Package last updated on 06 Jun 2023

Did you know?

Socket

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.

Install

Related posts