How to use common assertions for automated testing (python)
Find elements in automated tests and operate them, and if the elements are easy to use, I believe everyone can be more adept at writing a case script, but it may not be enough to manipulate the light, and sometimes the expected results need to be judged.
The use of several commonly used assertions is introduced here to help you judge the expected results to a certain extent.
Here are some of the following assertion methods:
Assertequal
Assertnotequal
Asserttrue
Assertfalse
Assertisnone
Assertisnotnone
(i) assertequal and assertnotequal
Assertequal: If two values are equal, pass
Assertnotequal: If two values are not equal, pass
Below see the specific use method
Self.driver.find_element_by_xpath ("//android.widget.linearlayout[1]/android.support.v7.app.actionbar.e[2]"). Click () #切到超模25tab sleep
(3)
self.assertequal (self.driver.find_element_by_id) (' Com.boohee.secret:id/tv_ Title '). Text,u ' Supermodel 25 ', ' Cut to supermodel 25tab failed '
(1) This is through the ID (com.boohee.secret:id/tv_title) to get its text value, and the expected "supermodel 25" contrast, if equal to pass; not equal is fail.
(2) After the "cut to the supermodel 25tab failure" is fail need to print information, can not write.
The assertion that assertnotequal is in reverse use is OK.
(ii) asserttrue and Assertfalse
Asserttrue: Judge the bool value to be true, then pass
Assertfalse: Judge bool value is false, then pass
Below see the specific use method
Self.driver.find_element_by_xpath ("//android.widget.linearlayout[1]/android.widget.textview[1]"). Click () # Click the login entry Sleep
(2)
Self.driver.find_element_by_xpath ("//android.widget.linearlayout[1]/ ANDROID.WIDGET.EDITTEXT[1] "). Send_keys (" testq1 ") #输入用户名 sleep
(2)
self.asserttrue (self.find_element_by_ ID (' Com.boohee.secret:id/btn_login '). is_enabled (), ' The Not-lost Password login button is not a point state, Fail ')
(1) This is through the ID (com.boohee.secret:id/btn_login) to obtain its activation state, such as the pass if true, and vice versa fail.
(2) After the "No Lost Password login button is not a point of State" is fail when the need to print information, can not write.
The assertion that Assertfalse is in reverse use is OK.
(iii) Assertisnone and Assertisnotnone
Assertisnone: Does not exist, then pass
Assertisnotnone: exists, then pass
Below see the specific use method
Self.driver.find_element_by_xpath ("//android.widget.linearlayout[1]/android.widget.textview[1]"). Click () # Click the login entry Sleep
(2)
Self.driver.find_element_by_xpath ("//android.widget.linearlayout[1]/ ANDROID.WIDGET.EDITTEXT[1] "). Send_keys (" testq1 ") #输入用户名 sleep
(2)
Self.driver.find_element_by_xpath ("// ANDROID.WIDGET.LINEARLAYOUT[2]/ANDROID.WIDGET.EDITTEXT[1] "). Send_keys (" Boohee ") #输入密码 sleep
(2)
Self.driver.find_element_by_xpath ("//android.widget.linearlayout[1]/android.widget.button[1]"). Click () #点击登录按钮 Sleep
(self.assertisnotnone) (
self.driver.find_element_by_id (' Com.boohee.secret:id/tv_edit_profile ') , ' no edit Data button, Login failed, Fail ']
(1) This side is by looking for the element of ID (com.boohee.secret:id/tv_edit_profile) exists, if exist then pass; fail.
(2) After the "No Edit Data button, Login failed, Fail" is Fail when the need to print information, can not write.
The assertion that Assertisnone is in reverse use is OK.
Summary: This side of the assertion, although not as accurate as the artificial judgment of the expected results, but the use of reasonable and flexible, for the important node plus the assertion also has a certain expected effect.