Selenium assertions and exception type Parsing
Selenium assertions and exception type parsing.
Assertion:
Verify that the application status is the same as expected.
Common assertions include verifying the page content, such as whether the title is X or the current position is correct, or verifying whether the check box is checked.
Selenium provides three modes of assert, verify, waitfor
If the Assert fails, the test is terminated.
If Verify fails, the test continues and the error is recorded on the daily display. That is to say, this individual authentication is allowed. Make sure the application is on the correct page
Waitfor is used to wait for certain conditions to become true. It can be used to test AJAX applications.
If this condition is true, it will be executed successfully immediately. If this condition is not true, the test will fail and be paused. Until the time limit is exceeded. Generally used together with the setTimeout time
Assertions commonly used include:
AssertLocation(Determine whether the current page is correct ),
AssertTitle(Check whether the title of the current page is correct ),
AssertValue(Check the input value, checkbox or radio, with a value of "on" Inaction "off "),
AssertSelected(Check whether the select drop-down menu is correct ),
AssertSelectedOptions(Check whether the options in the drop-down menu are correct ),
AssertText(Check the text of the specified element ),
AssertTextPresent(Check whether the specified text is displayed on the page currently displayed to the user ),
AssertTextNotPresent(Check whether the specified text is not displayed on the page currently displayed to the user ),
AssertAttribute(Check the attribute value of the currently specified element ),
AssertTable(Check the value of a cell in the table ),
AssertEditable(Check whether the specified input can be edited ),
AssertNotEditable(Check whether the specified input cannot be edited ),
AssertAlert(Check whether any alert dialog box with specified message is generated ),
VerifyTitle? (Check the expected page title)
VerifyTextPresent? (Verify whether the expected text is on a certain position on the page)
VerifyElementPresent(Verify the expected UI element, its HTML Tag definition, whether it is on the current webpage)
VerifyText(Check whether the expected text and corresponding HTML tags exist on the page)
VerifyTable(Verify the expected content of the table)
WaitForPageToLoad(Pause execution until the expected new page is loaded)
WaitForElementPresent? (Wait to test the existence of an element. If it is true, it is executed .)
Difference between verification and assertion: If the verification fails, the execution of the script will not be affected. If the assertion fails, the execution of the script will be stopped.
Exception type
AssertionError:Assert statement failed
AttributeError: Attempts to access a property that an object does not have
IOError: The input and output are abnormal. the file cannot be opened.
ImportError: The module or package cannot be introduced, which is basically a path problem.
IndentationError: Syntax error. The code is not correctly aligned.
IndexError: The subscript index exceeds the sequence boundary.
KeyError: Attempts to access keys that do not exist in the dictionary
KeyboadrInterrupt: Ctrl + c pressed
NameError: Use a variable that has not been assigned an object
SyntaxError: The logic Syntax of python code is incorrect and cannot be executed.
TypeError: The input object type does not meet the requirements
UnboundLocalError:An attempt to access a unconfigured global variable is basically caused by another global variable with the same name.
ValueError: Input an unexpected value, even if the type is correct
Example: python2.7 + selenium3.11.0:
# Coding = utf-8import timefrom selenium import webdriverdriver = webdriver. firefox () driver. maximize_window () driver. get ('https: // www.baidu.com ') try: assert u "Baidu" in driver. title print ('assertion test pass') failed t Exception as e: print ('assertion test fail ', format (e) print driver. title
As follows: