Android automation test-UIAutomator (3)-Comparison Test
Series Review: this series mainly introduces the use of UiAutomator from the perspective of development, including three in total:
Basic Introduction: Android automated testing-UiAutomator (1)
Tip: UiAutomator for Android automated testing (2) (unfinished)
Comparison tools: uiautomation test for Android (iii) --- comparison test
This is the third article.
The following is the text:
1. Introduction:
This article is applicable to all automated development tools (not limited to Android) that use images as outputs ).
After a set of automated tests, in addition to assertions, we often analyze the test results in a comparative manner. In this case, manpower becomes the bottleneck of efficiency again, can we pre-process the image in a certain way and mark the Diff area for developers to analyze it easily?
This document uses a bash script to obtain the differences between images and generate a visual html file. To help developers/testers quickly analyze test results.
2. Environment installation:
Applicable environment: ubuntu, not tested on other platforms.
Dependency program: imagemagick
Installation Method: sudo apt-get install imagemagick
3. Text
First, let's introduce ImageMagick. This is an image processing tool. Today we only use its two functions: 1. Compare images 2. Generate thumbnails.
Step 1: Prepare a set of benchmark images for the comparison criteria after testing. Put the image in the/tmp/base directory. For our example image:
Step 2: place the automated test results in the/tmp/new directory. For the image we obtained after the test:
Next we will execute the compare command of imagemagick:
Compare-metric AE/tmp/base/test.png/tmp/new/test.png/tmp/result/test.png
After executing this command, we will get a Diff image, as shown below:
With this command, we highlight the two images in different places. When you confirm with the naked eye, you only need to pay attention to the highlighted part.
Step 2: generate an HTML file, make all the files in the Directory and the images from Diff into thumbnails, and display them as a list:
First, traverse the directory through Shell:
function compare_png(){ for file in ` ls $BASEPATH ` do if [ -d http://blog.csdn.net/xzy2046/article/details/$BASEPATH$file ] then compare_png http://blog.csdn.net/xzy2046/article/details/$BASEPATH$file else fi fi done
Next, add the comparison statement to the else statement:
diff_count=`compare -metric AE http://blog.csdn.net/xzy2046/article/details/$BASEPATH$file http://blog.csdn.net/xzy2046/article/details/$NEWPATH$file http://blog.csdn.net/xzy2046/article/details/$EXPORTPATH$file 2>&1`
Pass the number of Diff partitions to the diff_count variable.
Then, use the convert command of imagemagick to obtain a thumbnail with a width of 160 pixels. These thumbnails will be used for HTML file display.
convert -thumbnail 160 http://blog.csdn.net/xzy2046/article/details/$BASEPATH$file http://blog.csdn.net/xzy2046/article/details/$File1convert -thumbnail 160 http://blog.csdn.net/xzy2046/article/details/$NEWPATH$file http://blog.csdn.net/xzy2046/article/details/$File2convert -thumbnail 160 http://blog.csdn.net/xzy2046/article/details/$EXPORTPATH$file http://blog.csdn.net/xzy2046/article/details/$File3
Finally generate HTML:
echo >>$result_html echo $file>>$result_html echo $diff_count>>$result_html echo Failed>>$result_html echo
>>$ Result_html echo >>$ result_html
The processing result is as follows:
The first column is the image name, and the second column is the number of differences. The three images are the benchmark images, tests, and generated Diff images respectively.
Shell script:
Http://download.csdn.net/detail/xzy2046/8167831