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

oll-visual-tester

v1.1.8

Published

Create page screenshots and then easily compare them.

Downloads

10

Readme

OLL Visual Tester

Create page screenshots and then easily compare them.

Installation

npm install --save oll-visual-tester

Afterwards you can import it like this:

const { screenshot, generateImages, compareImages } = require('oll-visual-tester')

Features

Screenshot tool

Screenshot function is using Playwright to browse to required page, perform clicks and then create screenshots from either full page or desired element.

Function accepts a configuration object, where we are setting how each screenshot will be created.

To create screenshot, first import the function:

const { screenshot } = require('oll-visual-tester')

Then prepare a configuration object which may look like this:

const config = {
  goto: 'http://duckduckgo.com', // Web page that we are visiting
  engine: 'firefox', // Browser engine: 'firefox', 'chromium' or 'webkit'
  width: 800, // Page width
  height: 600, // Page height
  path: './temp/baseline/', // Directory where screenshot will be saved
  name: 'screenshot1.jpg', // Name of the screenshot (`png` or `jpg` format)
  fullPage: true, // Setting for full page screenshot
  clicks: [ // Array of clicks
    {
      selector: '.js-side-menu-open', // Selector to click on
      waitAfter: 300, // optional - Wait after click
      button: 'left', // optional - Button 'left' or 'right'
    },
  ],
  el: null, // Element CSS selector that we want to make screenshot of
  debug: true, // Display additional messages
}

Lastly start creating a screenshot:

screenshot(config)
  .then(result => { console.log(result) })
  .catch(error => { console.error(error) })

Generate multiple images tool

This tool is used to create multiple screenshots. Instead of passing one configuration object, we are passing an array of objects.

const { generateImages } = require('oll-visual-tester')

const configurationArray = [
  {
    goto: 'http://duckduckgo.com', // Web page that we are visiting
    engine: 'firefox', // Browser engine: 'firefox', 'chromium', 'webkit'
    width: 800, // Page width
    height: 600, // Page height
    path: './temp/baseline/', // Directory where screenshot will be saved
    name: 'screenshot1.jpg', // Name of the screenshot (`png` or `jpg`)
    fullPage: true, // Setting for full page screenshot
    clicks: [ // Array of clicks
      {
        selector: '.js-side-menu-open', // Selector to click on
        waitAfter: 300, // optional - Wait after click
        button: 'left', // optional - Button 'left' or 'right'
      },
    ],
    el: null, // Element CSS selector that we want to make screenshot of
    debug: true, // Displays additional messages
  },
    {
    goto: 'http://duckduckgo.com',
    engine: 'webkit',
    width: 800,
    height: 600,
    path: './temp/baseline/',
    name: 'screenshot2.jpg',
    fullPage: true,
    clicks: [],
    el: null,
    debug: true,
  },
]

generateImages(configurationArray)
  .then(result => { console.log(result) })
  .catch(error => { console.error(error) })

Compare images tool

This tool is used to compare images from two directories. When run, it will find the files with the same name and will compare those files.

For files where there is a difference, a new PNG image will be created. It will contain a baseline image, diff image and a new image, positioned side by side.

const { compareImages } = require('oll-visual-tester')

compareImages({
  dirBaseline: './temp/baseline/', // Baseline directory
  dirNew: './temp/new/', // Directory where new images are stored
  dirDiff: './temp/diff/', // Optional - directory where diff images will be stored
  debug: true // Displays additional messages
})
  .then((result) => { console.log(result) })
  .catch((error) => { console.error(error) })

As a result, we will an get an object with 4 arrays:

  • passed - Images that passed the test
  • failed - Images that failed the test
  • missing - Images that are missing in baseline directory, but are present in new.
  • outdated - Images that are missing in new directory, but are present in baseline.
[16:18:03] Started to compare 2 screenshots
createDiffResult Diff image temp\diff\screenshot2.temp.png has been created
{
  passed: [
    {
      testedImage: 'screenshot1.jpg',
      dirBaseline: 'temp\\baseline\\',
      dirNew: 'temp\\new\\',
      diffImagePath: null,
      width: 800,
      height: 3665,
      imagesAreSame: true,
      diffCount: 0,
      diffPercentage: 0
    }
  ],
  failed: [
    {
      testedImageName: 'screenshot2.jpg',
      dirBaseline: 'temp\\baseline\\',
      dirNew: 'temp\\new\\',
      diffImagePath: 'temp\\diff\\screenshot2.png',
      width: 800,
      height: 3665,
      imagesAreSame: false,
      diffCount: 207717,
      diffPercentage: 7.084481582537518
    }
  ],
  missing: [ 'screenshot-new.png' ],
  outdated: [ 'screenshot-old.png' ]
}

Diff image may look like this:

Diff

Maintainer

Vladimir Jovanović