Series review: This series mainly introduces the use of Uiautomator from the perspective of development, including three articles in total:
Basics: The Uiautomator of Android automated Testing (i)
Tip: Android Automated test Uiautomator (ii) (not completed)
Comparison tool: Android automated test Uiautomator (iii)---comparison test
This is the third article.
Reprint Please specify source: http://blog.csdn.net/xzy2046/
The following is the text:
1. Introduction:
This article is suitable for all automated development tools that take pictures as output (not limited to Android).
When we carry out a set of automated tests, in addition to the assertion, often will also use a comparison of the way to analyze the test results, in this case, manpower once again become the bottleneck of efficiency, can be a certain way to pre-processing the picture, the diff area is marked, convenient for developers to analyze it?
The method of this article is to get the picture different from a bash script and generate a visual HTML file. To help dev/testers quickly analyze test results.
2. Installation of the environment:
Applicable environment: Ubuntu, other platforms not tested.
Dependent Program: ImageMagick
Installation method: sudo apt-get install ImageMagick
3. Text
first introduce ImageMagick, this is an image processing tool, today we will only use its two functions: 1, picture comparison 2, generate thumbnails.
In the first step, we prepare a set of benchmark images to be used for testing the comparison criteria after completion. Here we put the picture in the/tmp/base directory. For our example Picture:
In the second step, we put the automated tests in the/tmp/new directory. For the pictures we obtained after testing:
Next we execute ImageMagick's compare command:
Compare-metric Ae/tmp/base/test.png/tmp/new/test.png/tmp/result/test.png
After executing the command we will get a diff image, as follows:
with this command, we highlight two images in different places, and we only need to focus on the highlighted ones when we see them visually.
The second step: Generate the HTML file, all the files in the directory and the diff out of the image into a thumbnail, and displayed in the form of a list:
First, traverse the directory through the shell:
<pre name= "code" class= "HTML" >function Compare_png () {for file ' ls $BASEPATH ' do if [-D $BASEPATH $ File] then compare_png $BASEPATH $file Else fi fidone
Next, add a comparison statement to the Else statement:
Diff_count= ' compare-metric AE $BASEPATH $file $NEWPATH $file $EXPORTPATH $file 2>&1 '
The number of diff pixels to be compared is passed into the Diff_count variable.
A thumbnail with a width of 160 pixels is then obtained through the ImageMagick convert command, which will be used for the display of the HTML file
Convert-thumbnail $BASEPATH $file $File 1convert-thumbnail $NEWPATH $file $File 2convert-thumbnail $EXPORTPATH $file $File 3
Finally generate HTML:
echo <br><tr> >> $result _html echo "<td><font style=\" color:red;\ "> $file </ Font></td> ">> $result _html echo" <td><font style=\ "color:red;\" > $diff _count</ Font></td> ">> $result _html echo" <td><font style=\ "color:red;\" > "Failed" </font ></td> ">> $result _html echo" <td><a target=_blank href= $BASEPATH $file></a></td> ">> $result _html echo" <td><a target=_blank href= $NEWPATH $file ></a></td> ">> $result _html echo" <td><a Target=_blank href= $EXPORTPATH $file></a></td> ">> $result _html echo </tr> > > $result _html
The following results are processed:
The first column is the picture name, and the second column is the difference pixel number. Three pictures are the benchmark picture, the test, and the generated diff picture.
Shell script:
http://download.csdn.net/detail/xzy2046/8167831
Android Automated Test Uiautomator (iii)---comparison test