All Projects → burnpiro → puppeteer-screenshot-tester

burnpiro / puppeteer-screenshot-tester

Licence: MIT License
Small library that allows us to compare screenshots generated by puppeteer in our tests.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to puppeteer-screenshot-tester

Gest
👨‍💻 A sensible GraphQL testing tool - test your GraphQL schema locally and in the cloud
Stars: ✭ 109 (+118%)
Mutual labels:  jest, test, testing-tools
energy-use-case-trading-client
Energy Use Case Web UI for Lition Trading Platform
Stars: ✭ 23 (-54%)
Mutual labels:  jest, puppeteer
xstate-marionettist
Model based testing with Jest, XState and Puppeteer or Playwright made easy
Stars: ✭ 23 (-54%)
Mutual labels:  jest, puppeteer
kotest-gradle-plugin
A gradle plugin for Kotest
Stars: ✭ 18 (-64%)
Mutual labels:  test, testing-tools
pappet
A command-line tool to crawl websites using puppeteer.
Stars: ✭ 95 (+90%)
Mutual labels:  screenshot, puppeteer
Wasmite
Now WebAssembly has proper testing, unit-testing and debugging 🤗
Stars: ✭ 20 (-60%)
Mutual labels:  test, testing-tools
jest-dashboard
Command Line Dashboard for Jest
Stars: ✭ 61 (+22%)
Mutual labels:  jest, testing-tools
xv
❌ ✔️ zero-config test runner for simple projects
Stars: ✭ 588 (+1076%)
Mutual labels:  jest, test
gmock-xcode
Xcode integration for GoogleMock through XCTest
Stars: ✭ 18 (-64%)
Mutual labels:  test, testing-tools
page-modeller
⚙️ Browser DevTools extension for modelling web pages for automation.
Stars: ✭ 66 (+32%)
Mutual labels:  testing-tools, puppeteer
match-screenshot
A simple Jest or Chai matcher to compare screenshots, using Applitools Eyes
Stars: ✭ 14 (-72%)
Mutual labels:  jest, puppeteer
qiniutest
Qiniu httptest tool: qiniutest
Stars: ✭ 36 (-28%)
Mutual labels:  test, testing-tools
screenie-server
A Node server with a pool of Puppeteer (Chrome headless) instances for scalable screenshot generation.
Stars: ✭ 19 (-62%)
Mutual labels:  screenshot, puppeteer
carina-demo
Carina demo project.
Stars: ✭ 40 (-20%)
Mutual labels:  test, testing-tools
xray-action
... a GitHub action to import test results into "Xray" - A complete Test Management tool for Jira.
Stars: ✭ 16 (-68%)
Mutual labels:  test, testing-tools
jest-launchdarkly-mock
Easily unit test LaunchDarkly feature flagged components with jest
Stars: ✭ 14 (-72%)
Mutual labels:  jest, test
jest-wrap
Fluent pluggable interface for easily wrapping `describe` and `it` blocks in Jest tests.
Stars: ✭ 35 (-30%)
Mutual labels:  jest, testing-tools
screenshot
A screenshot API to convert web to image or PDF. Supports desktop and mobile views.
Stars: ✭ 108 (+116%)
Mutual labels:  screenshot, puppeteer
BaseUrlManager
⛵ BaseUrlManager的设计初衷主要用于开发时,有多个环境需要打包APK的场景,通过BaseUrlManager提供的BaseUrl动态设置入口,只需打一次包,即可轻松随意的切换不同的开发环境或测试环境。在打生产环境包时,关闭BaseUrl动态设置入口即可。
Stars: ✭ 43 (-14%)
Mutual labels:  test, testing-tools
vrt-react
Take a screenshot 📸 of React component. Push it and compare images in pull request.
Stars: ✭ 19 (-62%)
Mutual labels:  screenshot, puppeteer

puppeteer-screenshot-tester

Small library that allows us to compare screenshots generated by puppeteer in our tests.

Installation

To use Puppeteer Screenshot Tester in your project, run:

yarn add --dev puppeteer-screenshot-tester

or

npm install --save-dev puppeteer-screenshot-tester

Usage

Require the puppeteer-screenshot-tester library:

const ScreenshotTester = require('puppeteer-screenshot-tester')

Initialize Screenshot Tester

const tester = await ScreenshotTester()

Optional arguments:

const tester = await ScreenshotTester(
  [threshold = 0][, includeAA = false[, ignoreColors = false[, matchingBox = { ignoreRectangles = [], includeRectangle = [] } [, errorSettings = Object [, outputSettings = Object]]]]]
)
  • threshold <[number]> A threshold value <0,1> default set to 0, max ratio of difference between images
  • includeAA <[boolean]> Should include anti aliasing?
  • ignoreColors <[boolean]> Should ignore colors?
  • matchingBox <[Object]> Restrict what should be compared
  • matchingBox.ignoreRectangles <[Array<Array[x, y, width, height]>]> Should ignore rectangles? example: [[325,170,100,40], [10,10,200,200]], X and Y should be the coordinates of the top-left corner
  • matchingBox.includeRectangle <[Array<Array[x, y, width, height]>]> Compare only part of screen? example: [[325,170,100,40], [10,10,200,200]], X and Y should be the coordinates of the top-left corner
  • errorSettings <[Object]> change how to display errors (errorType: flat | movement | flatDifferenceIntensity | movementDifferenceIntensity | diffOnly):
    {
      errorColor: {
        red: 255,
        green: 0,
        blue: 255
      },
      errorType: 'flat',
      transparency: 0.7
    }
    
  • outputSettings <[Object]> change the output image settings:
    {
      forceExt: 'jpeg' | 'png' | 'webp' | null,
      compressionLevel: 8 // 0-9 for .png, 0-100 otherwise
    }
    
  • returns: <[function]> resolves to function

Run the test

const result = await tester(page)

Required arguments:

  • page <[BrowserPage]> BrowserPage returned by puppeteer when calling puppeteer.launch().newPage()

Optional arguments:

const result = await tester(page[, name = 'test'[, screenshotOptions = {}]])
  • name <[string]> name of created screenshot 'test' by default
  • screenshotOptions <[Object]> options passed to Puppeteer's screenshot method See the Puppeteer documentation for more info, plus the following keys:
    • saveNewImageOnError: <[boolean]> saves the undiffed new image on error as ${saveFolder}/${name}-new${ext}
    • overwriteImageOnChange: <[boolean]> overwrites the reference image (${saveFolder}/${name}${ext}) on error / change

Returns

  • <[boolean]> true if images are the same or there is no image to compare (first run)

Examples

const puppeteer = require('puppeteer')
const ScreenshotTester = require('puppeteer-screenshot-tester')

describe('google test', () => {
  let originalTimeout

  // extend default interval to 10s because some image processing might take some time
  // we can do it beforeEach or once per test suite it's up to you
  // if you're running that on fast computer/server probably won't need to do that
  beforeEach(function() {
    originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000
  })

  // set default interval timeout for jasmine
  afterEach(function() {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
  })

  it(`check if google exists`, async () => {
    // create ScreenshotTester with optional config
    const tester = await ScreenshotTester(0.8, false, false, [], {
      transparency: 0.5
    }, { compressionLevel: 8 })

    // setting up puppeteer
    const browser = await puppeteer.launch()
    const page = await browser.newPage()
    await page.setViewport({width: 1920, height: 1080})
    await page.goto('https://www.google.com', { waitUntil: 'networkidle0' })
    await page.type('input[title="Search"]', 'Hello', { delay: 100 })

    // call our tester with browser page returned by puppeteer browser
    // second parameter is optional it's just a test name if provide that's filename
    const result = await tester(page, 'test2', {
      fullPage: true,
    })
    await browser.close()

    // make assertion result is always boolean
    expect(result).toBe(true)
  })
})

Ignoring Rectangles and Including rectangles

const tester = await ScreenshotTester(
    0.1, // threshold
    false, // anti-aliasing
    false, // ignore colors
    { 
      ignoreRectangles: [[650, 300, 700, 200]], 
      includeRectangles: [[300, 200, 1100, 1100]]
    }, // rectangles 
    {
       transparency: 0.5
    }
)

./test2-diff.png

Contributors

Thanks goes to these wonderful people 😎 :


Kemal Erdem

💻 📖 👀

Max Harris

🐛 💻

Andi Smith

📖 ⚠️

JacobJust

💻 📖

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].