
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
puppeteer-screenshot-tester
Advanced tools
Small library that allows us to compare screenshots generated by puppeteer in our tests
Small library that allows us to compare screenshots generated by puppeteer in our tests.
To use Puppeteer Screenshot Tester in your project, run:
yarn add --dev puppeteer-screenshot-tester
or
npm install --save-dev puppeteer-screenshot-tester
Require the puppeteer-screenshot-tester
library:
const ScreenshotTester = require('puppeteer-screenshot-tester')
const tester = await ScreenshotTester()
const tester = await ScreenshotTester(
[threshold = 0][, includeAA = false[, ignoreColors = false[, ignoreRectangles = [] [, errorSettings = Object]]]]
)
threshold
<[number]> A threshold value <0,1> default set to 0, max ratio of difference between imagesincludeAA
<[boolean]> Should include anti aliasing?ignoreColors
<[boolean]> Should ignore colors?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.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
}
const result = await tester(page)
page
<[BrowserPage]> BrowserPage returned by puppeteer when calling puppeteer.launch().newPage()
const result = await tester(page[, name = 'test'[, screenshotOptions = {}]])
name
<[string]> name of created screenshot 'test' by defaultscreenshotOptions
<[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 / changeconst 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
})
// 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)
})
})
const tester = await ScreenshotTester(
0.1, // threshold
false, // anti-aliasing
false, // ignore colors
[[650, 300, 700, 200]], // rectangles
{
transparency: 0.5
}
)
Thanks goes to these wonderful people :sunglasses: :
Kemal Erdem 💻 📖 👀 | Max Harris 🐛 💻 | Andi Smith 📖 ⚠️ | JacobJust 💻 📖 |
This project follows the all-contributors specification. Contributions of any kind welcome!
FAQs
Small library that allows us to compare screenshots generated by puppeteer in our tests
The npm package puppeteer-screenshot-tester receives a total of 5,290 weekly downloads. As such, puppeteer-screenshot-tester popularity was classified as popular.
We found that puppeteer-screenshot-tester demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.