Using Conditional Logic
This section discusses how to use conditional logic.
Some test scenarios call for conditional logic—special handling based on information gathered from the application during the test. Conditional logic uses a Conditional.If_Then step with a Conditional.End_If step. The If_Then step evaluates a statement. If the expression evaluates to True, the system executes the lines between the If_Then step and the End_If step or the Else step, if it exists. If the expression evaluates to False, the system jumps to the Else step, if it exists, or to the End_If step if there is no Else, and continues execution.
What appears to be simple test instruction, such as the following, may require conditional logic to automate successfully:
12. In the Modify a Person page, click the Brazil flag if necessary to expand the Brazil region of the page.
When you record the click on the Brazil flag, PTF creates the following step, which looks deceptively simple:
The problem is that pages like the Modify a Person page typically use the same image to collapse and expand a section. The page may remember which regions are expanded and which are collapsed, so that the next time you run the test, the Brazil section might be expanded when you enter the page, in which case the Image.Click action in the previous example would collapse the Brazil section and potentially cause the test to fail.
The solution is to click the flag image only if the section is collapsed, which requires putting the click action within a conditional If-Then construct.
For example, suppose that you use the Message tool to determine that when the region is already collapsed, the alt property of the flag image is equal to “Expand section Brazil.” Alternatively, when the region is already expanded, the alt property of the same image is equal to “Collapse section Brazil.” You would construct your test such that the click would only occur if the alt property is equal to “Expand section Brazil.” You could do that with the following steps:
Note: The same rules apply for text strings used in the recognition field as described in the Using Text Strings as Parameters in Functions section.