Visual Regression Testing Service
wdio-image-comparison-service is a 3rd party package, for more information please see GitHub | npm
NOTE for Windows users!!
Please check the FAQ
#
IMPORTANT!- This module will execute a pixel-by-pixel comparison for you. There are some things you can change during comparison, see here but it stays a baisc pixel-by-pixel comparison.
This means that if for example Chrome updates to a newer version, you might need to change your baseline due to fontrendering differences. - Secondly you can only execute visual comparison on screenshots that have been taken with the same platform. For example, the screenshot on a Mac with Chrome can't be used to compare the same page on a Ubuntu or Windows with Chrome.
You need to compare Apples with Apples, not Apples with Windows - Try to prevent accepting a
missmatch percentage
. You never know what you accept and especially with large screenshots you might accept a button not being rendered and or shown on a page. - DONT' TRY TO MIMIC MOBILE SCREENSIZES BY RESIZING YOUR BROWSER AND SAY IT'S A CHROME OR SAFARI MOBILE BROWSER!!!! This module is there to compare visuals of what you're user would see. A resized Chrome or Safari is not equal to what your enduser is using on his mobile phone. Web-pages and so on a desktop browser CAN'T be compared with mobile browsers due to different font, html and JS-rendering.
- In my humble opinion it's useless to use this module with headless browsers and I will also NOT support any issues as a result of headless browsers. Reason is that an enduser is not using a headless browser 😉
#
What can it do?wdio-image-comparison-service is a lightweight WebdriverIO service for browsers / mobile browsers / hybrid apps to do image comparison on screens, elements or full page screens.
You can:
- save or compare screens / elements / full page screens against a baseline
- automatically create a baseline when no baseline is there
- blockout custom regions and even automatically exclude a status and or tool bars (mobile only) during a comparison
- increase the element dimensions screenshots
- use different comparison methods
- NEW: We now support Puppeteer with WebdriverIO
- NEW: You can now verify how your website will support tabbing with your keyboard, see also here
- and much more, see the options here
The module is now based on the power of the new webdriver-image-comparison
module. This is a lightweight module to retrieve the needed data and screenshots for all browsers / devices.
The comparison power comes from ResembleJS. If you want to compare images online you can check the online tool
It can be used for:
- desktop browsers (Chrome / Firefox / Safari / Internet Explorer 11 / Microsoft Edge)
- mobile / tablet browsers (Chrome / Safari on emulators / real devices) via Appium
- Hybrid apps via Appium
NOTE for Hybrid!!
Please use the propertyisHybridApp:true
in your service settings
#
InstallationInstall this module locally with the following command to be used as a (dev-)dependency:
Instructions on how to install WebdriverIO
can be found here.
#
Usagewdio-image-comparison-service supports NodeJS 8 or higher
#
Configurationwdio-image-comparison-service
is a service so it can be used as a normal service. You can set it up in your wdio.conf.js
file with the following
More plugin options can be found here.
#
Writing testswdio-image-comparison-service is framework agnostic, meaning that you can use it with all the frameworks WebdriverIO supports like Jasmine|Mocha
.
You can use it like this:
If you run for the first time without having a baseline the check
-methods will reject the promise with the following warning:
This means that the current screenshot is saved in the actual folder and you manually need to copy it to your baseline.
If you instantiate wdio-image-comparison-service
with autoSaveBaseline: true
the image will automatically be saved into the baseline folder.
#
Running ProgrammaticallyHere is a minimal example usage of getting wdio-image-comparison-service
to work via remote
options
#
Test result outputsThe save(Screen/Element/FullPageScreen)
methods will provide the following information after the method has been executed:
See the Save output section in the output docs for the images.
By default the check(Screen/Element/FullPageScreen)
methods will only provide a mismatch percentage like 1.23
, but when the plugin has the options returnAllCompareData: true
the following information is provided after the method has been executed:
See the Check output on failure section in the output docs for the images.
#
Tabbing through a websiteWe now support checking if a website is accessible through using the keyboards TAB
-key. Testing this part of accessibility has always been a time consuming (manual) job and pretty hard to do through automation.
With the methods saveTabbablePage
and checkTabbablePage
you can now draw lines and dots on your website to verify the tabbing order.
Be aware of the fact that this is only useful for desktop browser and NOT for mobile devices. All desktop browsers are supporting this feature, see the browser matrix on the top of this page to check which desktop browsers and versions are supported.
NOTE:
The work is inspired by Viv Richards his blog post about "AUTOMATING PAGE TABABILITY (IS THAT A WORD?) WITH VISUAL TESTING".
The way tabbable elements are selected are based on the module tabbable. If there are any issues regarding the tabbing please check the README.md and especially the More details-section.
#
How does it workBoth methods will create a canvas
element on your website and draw lines and dots to show you where your TAB would go if an end-user would use it. After that it will create a full page screenshot to give you a good overview of the flow.
Use the
saveTabbablePage
only when you need to create a screenshot and DON'T want to compare it with a base line image.
When you want to compare the tabbing flow with a baseline, then you can use the checkTabbablePage
-method. You DON'T need to use the two methods together. If there is already a baseline image created, which can automatically be done by providing autoSaveBaseline: true
when you instantiate the service,
the checkTabbablePage
will first create the actual image and then compare it against the baseline.
#
OptionsBoth methods use the same options as the saveFullPageScreen
or the
compareFullPageScreen
.
#
ExampleThis is an example of how the tabbing works on the website of our amazing sponsor Sauce Labs:
#
DEV-TOOLS supportYou can also use the Chrome DevTools as automation protocol in combination with this module. You don't need to do anything,
just change automationProtocol: 'devtools'
in your config.
More information about how to use the DEV-TOOLS can be found in this blog post.
#
Typescript supportWe now also support typescript types. Add the following to the types
in your tsconfig.json
:
#
FAQsave(Screen/Element/FullPageScreen)
methods when I want to run check(Screen/Element/FullPageScreen)
?#
Do I need to use a No, you don't need to do this. The check(Screen/Element/FullPageScreen)
will do this automatically for you
#
Width and height cannot be negativeIt could be that the error Width and height cannot be negative
is thrown. 9 out of 10 times this is related to creating an image of an element that is not in the view. Please be sure you always make sure the element in is in the view before you try to make an image of the element.
#
Installation of Canvas on Windows failed with Node-Gyp logsCanvas uses Node-Gyp and might cause some issues on Windows that are not fully set up. Please check this post for Fixing Node-Gyp Issues on Windows. (Thanks to IgorSasovets)
#
ContributionSee CONTRIBUTING.md.
#
TODO:- fix the scroll-bar for Android, sometimes it shows
- create a new website
#
Creditswdio-image-comparison-service
uses an open source licence from Sauce Labs.
You can request your open source licence here