Giter VIP home page Giter VIP logo

codeceptjs-pixelmatchhelper's People

Contributors

kobenguyent avatar stracker-phil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

codeceptjs-pixelmatchhelper's Issues

Question: What's the proper way to create a base screenshot from element?

Suppose I have no base screenshot created yet. I'm trying this:

Feature('My');

Scenario('test something',  ({ I }) => {
    I.amOnPage("https://codecept.io");
    I.wait(5);
    I.saveElementScreenshot(".sub-bar", "Bar.png");
    I.checkVisualDifferences("Bar.png");
});

But when I run the test, a base screenshot of whole page is created instead of the element .sub-bar only.

In codeceptjs-resemblehelper I do it this way:

Feature('My');

Scenario('test something',  ({ I }) => {
    I.amOnPage("https://codecept.io");
    I.wait(5);
    I.saveElementScreenshot(".sub-bar", "Bar.png");
    I.seeVisualDiff("Bar.png", { prepareBaseImage: true, tolerance: 0 });
});

and you get a base screenshot of the element only as expected.

[FEATURE] better error handling for getVisualDifference

Currently getVisualDifference just throws generic errors. Thus, a client cannot implement their own error handling. My suggestion would be to implement specific exceptions in order for them to be handled individually.

This would especially allow to still diff images which have different dimensions (e.g. by all expected images to match the actual image).
Of course an option would need to be introduced to fallback to current behaviour, too.

Motivation:
If due to some change an element gets added to a website, or some elements have different sizes, the dimensions won't be the same, however a diff can help identify the problem easily.

Will come back to this with a PR as soon as time comes by.

[DOCS] add wiki entry on how to compare different sized images

For my visual regression tests I like to have diff images and diff calculation even if the dimensions of the images mismatch. This could e.g. occur between two website screenshots if an additional line of text was added.

While this could be incorporated directly in pixelmatch as well as codeceptjs-pixelmatchhelper I more or less agree with mapbox/pixelmatch#25 (comment) in it being easy to do outside and adding another dependency like sharp just for edge cases should in general be avoided.

Nevertheless I think documenting the solution would help. So perhaps this could be added to the wiki/FAQ:

I created a custom function for my steps-file.js which is just called before a this.getVisualDifferences() and increases the smaller screenshot with black pixels. Yes this overrides both files, but is the most versatile solution.

const fs = require('fs');
const sharp = require('sharp');
...
async adaptImageCanvasForCompareIfNecessary(fileExpected, fileActual) {
	const expectedImage = sharp(fs.readFileSync(fileExpected));
	const actualImage = sharp(fs.readFileSync(fileActual));
	const expectedImageMetadata = await expectedImage.metadata();
	const actualImageMetadata = await actualImage.metadata();
	const maximumWidth = Math.max(expectedImageMetadata.width, actualImageMetadata.width);
	const maximumHeight = Math.max(expectedImageMetadata.height, actualImageMetadata.height);

	if (expectedImageMetadata.width !== actualImageMetadata.width
	|| expectedImageMetadata.height !== actualImageMetadata.height) {
		this.say(`Screenshots have different dimensions; increasing canvas to ${maximumWidth}x${maximumHeight}`);
		const newExpectedImage = await expectedImage
			.resize({
				width: maximumWidth,
				height: maximumHeight,
				fit: 'contain',
				position: 'left top'
			})
			.png()
			.toFile(fileExpected);
		const newActualImage = await actualImage
			.resize({
				width: maximumWidth,
				height: maximumHeight,
				fit: 'contain',
				position: 'left top'
			})
			.png()
			.toFile(fileActual);
	}
},
...

'EXDEV: cross-device link not permitted' error in docker

Hi!
There is issue when run tests in docker:
fs.renameSync(); (480 line) throws an exception:
Error: EXDEV: cross-device link not permitted, rename '/codecept/output/~60mi4.temp' -> '/codecept/tests/output/debug.png' at Object.renameSync (node:fs:993:3) at PixelmatchHelper._takeScreenshot (node_modules/codeceptjs-pixelmatchhelper/index.js:479:6) at async PixelmatchHelper._maybeCaptureImage (node_modules/codeceptjs-pixelmatchhelper/index.js:639:3) at async PixelmatchHelper.getVisualDifferences (node_modules/codeceptjs-pixelmatchhelper/index.js:280:3) at async /codecept/node_modules/codeceptjs-pixelmatchhelper/index.js:241:5
It could be fixed by changing method to fs.copyFileSync();

Webdriverio saveScreenshot doesn't accept .temp file

Hi, I just started with this helper and immediately run into a problem using WebDriver.
The saveScreenshot function doesn't accept files with .temp file type.

image

It throws an error when running the test:
image

Is there a chance to fix this? Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.