Validating Test Results
How do we tell whether the test passed or failed? It is good practice to use a verification point in your test case.To create a valid test case, we need to use some sort of validation. It isn't enough to have a sequence of events without validation in a test script. Watir can check the state of objects in the Internet Explorer DOM, and can check to see if a page contains the objects that are expected for the test to pass.
Object Exists
A simple verification point is to use the Watir method contains_text.In our test, imagine we have gone through a sequence of steps to reach the desired point. This is a web page that contains the following text:
Reached test verification point.
Watir code to check that the text exists on the web page is contains_text method:
ie.contains_text("Reached test verification point.")
if ie.contains_text("Reached test verification point.") puts: "Test passed. Page contains the text: Reached test verification point." else puts: "Test failed! Page didn't contain text: Reached test verification point." end
- checks if there is text Reached test verification point.
- if true, print our passing message to the screen
- if false, print our failure message to the screen
- end our if block
No comments:
Post a Comment