Skip to main content
Version: 2x

@qavajs/steps-visual-testing

Cucumber step library to perform visual (screenshot) testing using pixelmatch.

Installation

npm install @qavajs/steps-visual-testing

Configuration

Register the steps in your qavajs config:

import Memory from './memory';

export default {
require: [
'@qavajs/steps-visual-testing/index.js'
],
memory: new Memory()
}

Usage

Screenshots passed to the steps can be either a Buffer or a base64-encoded PNG string. They must be stored in memory under an alias before being referenced in a step.

Compare two screenshots

Then I expect '$actual' screenshot to equal '$expected'

Compares $actual against $expected using the default threshold of 0.1.

Compare two screenshots with custom parameters

Then I expect '$actual' screenshot to equal '$expected':
| threshold | 0.4 |
ParameterTypeDefaultDescription
thresholdnumber0.1Matching threshold (0–1). Lower values require a closer match; higher values allow more difference.

Failure attachments

When images do not match (or cannot be compared, e.g. size mismatch), the step automatically attaches three images to the Cucumber report:

  • actual — the actual screenshot
  • expected — the expected screenshot
  • delta — a diff image highlighting pixel differences

Steps


I expect {string} screenshot to equal {string}

Compare two screenshots from memory (saved as base64)

paramtypedescription
actualstringalias of actual screenshot
expectedstringalias of expected screenshot
Then I expect '$actual' screenshot to equal '$expected'

I expect {string} screenshot to equal {string}: [DataTable]

Compare two screenshots from memory (saved as base64) with provided compare parameters

paramtypedescription
actualstringalias of actual screenshot
expectedstringalias of expected screenshot
paramsDataTabletable of key-value params

Supported params:

paramtypedescription
thresholdnumberMatching threshold, ranges from 0 to 1. Smaller values make the comparison more sensitive
Then I expect '$actual' screenshot to equal '$expected':
| threshold | 0.5 |