New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

cypress-visual-testing

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypress-visual-testing

Module for adding visual regression testing to Cypress

latest
Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
3
200%
Maintainers
1
Weekly downloads
 
Created
Source

Cypress Visual Testing

NPM

Build Status

Module for adding visual regression testing to Cypress.

Getting Started

Install:

$ npm install cypress-visual-testing

Add the following config to your cypress.json file:

{
  "screenshotsFolder": "cypress/snapshots/actual",
  "trashAssetsBeforeRuns": true,
  "env": {
    "type": "actual",
    "missingBase": "strict"
  }
}

Add the plugin to cypress/plugins/index.js:

const getCompareSnapshotsPlugin = require('cypress-visual-testing/dist/plugin');

module.exports = (on) => {
  getCompareSnapshotsPlugin(on);
};

Add the command to cypress/support/commands.js:

const compareSnapshotCommand = require('cypress-visual-testing/dist/command');

compareSnapshotCommand();

To Use

Add cy.compareSnapshot('home'); in your tests specs whenever you want to test for visual regressions, making sure to replace home with a relevant name. You can also add an optional error threshold: Value can range from 0.00 (no difference) to 1.00 (every pixel is different). So, if you enter an error threshold of 0.50, the test would fail only if 0.51 percent of pixels are different.

For example:

it('should display the login page correctly', () => {
  cy.visit('/03.html');
  cy.get('H1').contains('Login');
  cy.compareSnapshot('login', 0.0);
  cy.compareSnapshot('login', 0.1);
});

You can target a single HTML element as well:

cy.get('#my-header').compareSnapshot('just-header')

Looking for more examples? Review docker/cypress/integration/main.spec.js.

Take the base images:

$ ./node_modules/.bin/cypress run --env type=base --config screenshotsFolder=cypress/snapshots/base

# use comma separated format for multiple config commands
$ ./node_modules/.bin/cypress run \
  --env type=base \
  --config screenshotsFolder=cypress/snapshots/base,testFiles=\"**/*regression-tests.js\

Find regressions:

$ ./node_modules/.bin/cypress run --env type=actual

Example

example

TODO

  • Allow end user to customize options (screenshot directory)
  • Test functionality of taking screenshots without running visual regression
  • Prevent "base" tests runs from actually running the regular Cypress tests

Keywords

testing

FAQs

Package last updated on 21 Jan 2020

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