To perform image comparison in GUI Testing we need to install protractor-image-comparison module it can be installed using below command.
Open command prompt and run below command.
1 |
npm install protractor-image-comparison |
Add below code in onPrepare function of configuration file
1 2 3 4 5 6 7 8 9 10 11 |
const protractorImageComparison =require('protractor-image-comparison'); browser.protractorImageComparison = new protractorImageComparison({ baselineFolder: 'path/baseline/', screenshotPath: 'path/actualscreenshots/', autoSaveBaseline: true } |
Code to do image comparison
1 |
expect(browser.protractorImageComparison.checkElement(element(Element), “ImageName”)).toEqual(0); |
ImageName is image file name exist in baseline folder. If image is not there in baseline folder then it will create file with name “ImageName” as autoSaveBaseline: true.
Example:
1 |
expect(browser.protractorImageComparison.checkElement(element(By.id('ftwItemTextViewer_c')), "image1")).toEqual(0); |