Here Initially we will take one ScreenShot and store into the file and then at any time again we can take one more ScreenShot and compares both to know is there any changes happened.
To run the project, clone the repo, and simply run.
Go to the EatinProgramUITests.swift file
- First take the screen shot and store into file by giving filename , So you can run following methods- testWriteSelectedBurger() and testWriteSelectedBurgerDetailPage() These above methods are taking screenshot and storing into file.
- Make sure that give correct file name which you want to read from file. Now you can run the following testcases - testReadSelectedBurger() and testReadSelectedBurgerDetailPage()
- The above testCases are taking one screenShot currently and one which you have stored into file and then simply comparing whether both are equal or not.
There is a compare method written in EatinProgramUITests.swift which takes tolerance and
two image data and checks whether two images are equal or not.
- Convert from data into images .
- Convert into cgImages because we need bitmaps .
- Find out expected number of pixels .
- It allocates memory for the specified number of pixels for type unsigned 32-bit integer .
- Then compares pixel by pixel and based on the tolerance it returns true or false indicating whether images are equal or not.
Make Sure if you are setting tolerance == 0.0 , means images should exactly be equal.
See on the top, time should also be same.
if you don't want full screen shot then you can define frame for which you want to take screen shot.
tolerance == 0.1 means if two images are not matching 10% then also compare method will say that both images are equal.
Amar Prakash Mishra - Initial work - UIScreenShot-Testing
Created by Amar Prakash Mishra, on 23/05/19.
Share feedback if you feel anything needs to be improved, I would be happy to hear.