When writing Web Automation test Cases, how to write assertions is confusing to the novice, strictly speaking, no assertion of the automation script can not be called test cases. Just like a functional test, when a tester does something, it is inevitable that the actual result is equal to the expected result, but that the process is done by the tester's eyes. An automated test script must use this information to determine the success of the use case.
The three types of information commonly used are:
Title : The page is different or does not appear at the same time often the title will also vary.
URL : similar to title, when the page changes, the URL will change as well.
Text: It is more widely used than the former, because it allows you to get any identifying text on the page for "proving" the execution of the use case is successful. For example, after landing the user name, query results and so on.
However, in some cases, this information cannot be obtained to prove that the use case is successful. Of course, the worst thing is not to write assertions, scripts run without error to prove that use case execution success, this is of course a helpless move. In addition, you can also choose to assert two pictures, in the case of the correct use case to do the current page, in the case of the use of the execution of the process again. Determine if the use case is successful by comparing the two images.
Pillow Download:https://pypi.python.org/pypi/Pillow/3.0.0
Choose download based on your operating system and Python version.
Installation:
python3-m pip Install pillow-3.0.0-cp35-none- WIN_AMD64.WHLprocessing c:\selenium\pillow-3.0.0-cp35-none-win_amd64.whlinstalling Collected packages:pillowsuccessfully installed Pillow-3.0.0
Note that because I installed the machine at the same time Python2.7 and the Python3.5 , so it is specifically specified here to install the Python3 the following.
fromPILImportImageImportMathImportoperator fromFunctoolsImportReducedefimage_contrast (IMG1, Img2): Image1=Image.open (IMG1) image2=Image.open (IMG2) H1=Image1.histogram () H2=Image2.histogram () result= Math.sqrt (Reduce (Operator.add, list (map) (LambdaB: (a) **2, H1, H2))/Len (H1))returnresultif __name__=='__main__': Img1="./img1.jpg" #Specify picture PathImg2 ="./img2.jpg"result=image_contrast (IMG1,IMG2)Print(Result)
If the two pictures are exactly equal, the returned result is the floating-point type "0.0", and if it is not the same, the larger the result value is returned.
This allows you to invoke the method in an automated test case to assert the result of the execution.
=====================
Detailed documentation on the Pillow library:
Http://pillow.readthedocs.org/en/latest/index.html
Pillow to achieve picture comparison