You can use assertion statements to determine that your script is receiving the expected results. You use the session status to determine session status whether your jobs have failed because of an uncaught exception or an assertion statement failed.

This page provides an assertion example that shows how to use the session status to determine which scripts have issues.

Use Assertions to Verify Expected Results

Assert statements use a simple syntax to verify an expected result. You can also provide a message to display if the assertion fails. In the example below, the message "Title should contain AppDynamics" will be displayed if the assertion fails.

# Get page and check the title
assert "E-Commerce Shopping Cart" in driver.title, "Title should contain E-Commerce Shopping Cart"
# Click link and confirm URL is correct
driver.find_element_by_link_text("Place your order").click()
assert "ThankYouCart" in driver.current_url

You can also verify that a string is not in the result or the truth of a mathematical expression. Assert statements that are false will result in a session status of FAILED.

 # Confirm the page doesn't gives a 500 error.
assert "500 Internal Server Error" not in driver.page_source
# Confirm the footer is on the page.
footer = driver.find_elements_by_class_name('footer-body')
assert len(footer) > 0, "Footer couldn't be found."

Use the Session Status to Find Script Issues

The two-session statuses BROKEN and FAILED indicate that the script had an issue. If the session status is BROKEN, it means that your script threw an uncaught exception. You'll most likely need to review your code and look for errors. See Exceptions for a list of common exceptions.

If the session state is FAILED, an assert statement failed or if you checked "Fail on page load error" and the page failed to load. You'll need to determine why your assertion statement failed or why the page couldn't be loaded. 

You can view the results of assertion statements in the session status detail and script output. From the Session Details page, you can view failed assert statements in a red exception box at the top and from the Waterfall tab:

Session Details

Failed assert statements will also appear in the Script Output dialog:

Script Output