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

devextreme-screenshot-comparer

v2.0.17

Published

Screenshot comparer for visual testing

Downloads

10,714

Readme

TypeScript version Node.js version

Usage

Take a single screenshot and validate it:

import {​​​​​​​ createScreenshotsComparer, compareScreenshot }​​​​​​​ from 'devextreme-screenshot-comparer';
test('Full size pager', async (t) => {​​​​​​​​
    await t
        .expect(await compareScreenshot(t, 'pager-full-allpages.png'))
}​​

Take and validate several screenshots without failing a test:

// create comparer for collect results
const {​​​ takeScreenshot, compareResults }​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ = createScreenshotsComparer(t);
await t
    ... // perform test actions and take the first screenshot
    .expect(await takeScreenshot('pager-1.png', pagerElement))
    ...// perform other actions and take the second one
    .expect(await takeScreenshot('pager-2.png', pagerElement))
    // check the result and show errors
    .expect(compareResults.isValid())
    .ok(compareResults.errorMessages());

Files and folders structure

 .
 +- testing -- default root path
    +- tests
    |  +- etalons
    |  |  +- pager-screehshot1.png
    |  +- pager.ts -- testfile with takeScreenshot(t, 'screehshot1');
    +- screenshots
    |  +- pager-screehshot1.png
    |  +- pager-screehshot1.png
    |  +- pager-screehshot1_mask.png
    |  +- pager-screehshot1_text_mask.png
    +- artifacts
       +- compared-screenshots
       |  +- pager-screehshot1.png
       |  +- pager-screehshot1_etalon.png
       |  +- pager-screehshot1_mask.png
       +- pager-screehshot1 - generated only when `debug` mode enabled;
          +- ... -- step by step image transformations used for comparison;
          +- log.txt -- comparison logs 
         

Configuration

Default config:

const screenshotComparerDefault = {
  path: './testing',
  screenshotsRelativePath: '/screenshots', 
  destinationRelativePath: '/artifacts/compared-screenshots',
  generatePatch: false,
  highlightColor: { r: 0xff, g: 0, b: 0xff },
  maskRadius: 5,
  attempts: 2,
  attemptTimeout: 500,
  looksSameComparisonOptions: {
    strict: false,
    tolerance: 5,
    ignoreAntialiasing: true,
    antialiasingTolerance: 5,
    ignoreCaret: true,
  },
  textComparisonOptions: {
    strict: false,
    ignoreAntialiasing: true,
    ignoreCaret: true,
  },
  enableTextMask: true,
  textMaskRadius: 2,
  textDiffTreshold: 0.05,
};
  • Common options:
    • path - path to the screenshots root folder;
    • screenshotsRelativePath - a relative path for storing screenshots to compare (base part is the path property)
    • destinationRelativePath - a relative path for storing comparison results (base part is the path property)
    • generatePatch - save updated screenshots to the 'artifacts/screenshots' subfolder, keep etalon screenshots' tree hierarchy;
    • maskRadius - radius of ignored pixels when using a mask file;
    • attemps - count of attempts to get a valid screenshot;
    • attempTimeout - timeout between attemps;
    • ignoreSizeDifference - ignore the size difference between compared images
    • looksSameComparisonOptions - see look-same for more details;
  • Text comparison options:
    • enableTextMask - if enabled, comparer generates a mask over text glyphs. Comparison inside the mask area ignores subpixel diffs;
    • textMaskRadius - radius of the mask area around text glyph;
    • textDiffTreshold - a value between [0..1]. 0 means that no diff allowed betwen original and current text glyphes, 1 ignores differences within the mask area at all;
    • textComparisonOptions - see look-same for more details;

You can override the default configuration using .testcaferc.json. For example, override the path:

{
  "screenshots-comparer": {
    "path": "./testing/testcafe"
  }
}

or for any takeScreenshot call:

.expect(await takeScreenshot('', null, { looksSameComparisonOptions: { tolerance: 30 } }));

License

DevExtreme Screenshot Comparer is released as MIT-licensed