[E2E] Visual Differing Tests with Puppeteer and PixelMatch
Take your end to end tests to the next level by comparing your current application's view with an already accepted screenshot. With the combination of running a live chromium browser, taking a screenshot and running a pixelmatch test, we are able to make sure our UI matches exactly as intended. We will make the test pass and then have it fail by adding an extra p tag to our App.js
const puppeteer = require('puppeteer')
const devices = require('puppeteer/DeviceDescriptors')
const iPhone = devices['iPhone 6']
const pixelTest = require('./diffImages.js')
/* Setting up testing env, which is not important*/
let browser
let page
beforeAll(async () => {
browser = await puppeteer.launch({ headless: false })
page = await browser.newPage()
await page.goto('http://localhost:3000/')
await page.emulate(iPhone)
})
afterAll(() => {
browser.close()
})
/* Finish Setting up testing env */
/*Start testing*/
describe('screenshots are correct', () => {
it('/index', async () => {
const file = 'screenshot.png'
await page.screenshot({ path: file })
return pixelTest.compareScreenshots(file)
})
})
const pixelmatch = require('pixelmatch')
const fs = require('fs')
const PNG = require('pngjs').PNG
exports.compareScreenshots = fileName => {
return new Promise((resolve, reject) => {
const doneReading = () => {
expect(img1.width).toBe(img2.width)
expect(img1.height).toBe(img2.height)
const numDiffPixels = pixelmatch(
img1.data,
img2.data,
null,
img1.width,
img1.height,
{ threshold: 0.1 }
)
expect(numDiffPixels).toBe(0)
resolve()
}
const img1 = fs.createReadStream('testScreenShot.png').pipe(new PNG())
const img2 = fs.createReadStream(fileName).pipe(new PNG()).on('parsed', doneReading)
})
}
https://www.npmjs.com/package/pixelmatch
[E2E] Visual Differing Tests with Puppeteer and PixelMatch的更多相关文章
- ant design pro (十二)advanced UI 测试
一.概述 原文地址:https://pro.ant.design/docs/ui-test-cn UI 测试是项目研发流程中的重要一环,有效的测试用例可以梳理业务需求,保证研发的质量和进度,让工程师可 ...
- Vue Study [1]: Vue Setup
Description The article for vue.js Setup. Original post link:https://www.cnblogs.com/markjiang7m2/p/ ...
- vue-cli 第一章
一.安装 Node.Python.Git.Ruby 这些都不讲解了 二.安装 Vue-Cli # 最新稳定版本 # 全局安装 npm install --global vue-cli # 创 ...
- vue单页面模板说明文档(1)
Introduction This boilerplate is targeted towards large, serious projects and assumes you are somewh ...
- Vue 系列之 基础入门
背景叙述 渐进式 JavaScript 框架 易用:已经会了 HTML.CSS.JavaScript?即刻阅读指南开始构建应用! 灵活:不断繁荣的生态系统,可以在一个库和一套完整框架之间自如伸缩. 高 ...
- 搭建VueMint-ui框架
搭建VueMint-ui框架 2018年01月07日 22:29:58 阅读数:2660 vueweb vue project 检查项目环境 一.检查是否安装node.js # 检查node版本 $ ...
- Vue 全家桶 + Electron 开发的一个跨三端的应用
代码地址如下:http://www.demodashi.com/demo/11738.html GitHub Repo:vue-objccn Follow: halfrost · GitHub 利用 ...
- Vue Study [2]: Vue Router
Description The article for vue router. Original post link:https://www.cnblogs.com/markjiang7m2/p/10 ...
- vue - 前置工作 - 目录功能介绍
一个DEMOS的完整目录(由于GWF问题,我就不一一打开网站一个个去搜索并且解释了)可以去关注:https://www.cnblogs.com/ye-hcj build build.js(本文来自ht ...
随机推荐
- 2CSS层叠规则(即引入CSS的三种不同方式的优先级)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- 鼠标单击到 img行的时候图片隐藏方案
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- C#入门经典 Chapter5 变量的更多内容
5.1类型转换 1.类型转换 1.1隐式转换:所有情况下可进行,编译器执行转换. 1.2显示转换 强制转换:强迫数据从一种类型转换为另一种类型. (<destinationType>)&l ...
- html5——盒子模式
box-sizing属性 box-sizing: border-box;/*内减模式*/ box-sizing: content-box;/*外加模式(默认值)*/ box-sizing: paddi ...
- windows phone 8 使用页面传对象的方式 实现页面间的多值传递
在做windows phone 开发的时候,会经常碰到页面间之间的跳转和传递数据,如果传递的值不多,只有两三个,我们通常使用NavigationService.Navigate(new Uri(&qu ...
- Python语言之数据结构2(字典,引用)
1.字典 键值对. dict={ "key1" : "value1", "key2" : "value2" } #add ...
- STL_优先队列_(转载)
转自:http://www.cnblogs.com/summerRQ/articles/2470130.html STL容器之优先队列 优先级队列,以前刷题的时候用的比较熟,现在竟然我只能记得它的关键 ...
- Springboot启动工程后,浏览器出现输入用户名和密码
在使用spring boot的时候发现启动项目时,浏览器需要输入用户名和密码. baidu后发现是因为pom中引用了Spring Security,但是项目中没有使用,在pom中注释掉即可.
- 用 ilasm 反编译、修改.net dll文件
有些.net dll我们没有源码,如果要修改某些东西,可以用ilasm.exe反编译为il代码,修改后再编译回dll ilasm通常放在以下路径 C:\Windows\Microsoft.NET\Fr ...
- Swift 3到5.1新特性整理
本文转载自:https://hicc.me/whats-new-in-swift-3-to-5-1/,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有. Hipo 2.0 重写从 Swif ...