To create more logic in test cases and more difficult test situations ATS has the possibility to add preconditions. These preconditions are added to test steps in your test cases. Maybe you have an application that sometimes shows a dialog after you log in with your open or new orders. If you do not know in advance whether you see the dialog after you log in, that makes it difficult to prepare test cases that always work. You sometimes need the Close Dialog action but not always. To make sure your test cases do not fail due to the presence (or absence) of the Dialog, you add a precondition to the Find/Assert Dialog action. If a dialog is present then the precondition is successful and ATS executes the underlying test step Close Dialog. In case no dialog is found the precondition fails and ATS does not execute the underlying test step Close Dialog. Not executed means that ATS continues with the next step.
This how-to uses the Mendix Company Expenses app as an example. In this how-to, you create a test case that clicks on a specific expense to view the details. Unfortunately, we do not know on which page of the data grid that expense is present. So, the test case searches for that expense on the first page of the data grid. If the expense is present ATS clicks on it. If the expense is not present ATS clicks on the next button to go to the next page of the data grid. On the next page, ATS checks again if the expense is present and, if so, clicks on it.
In the Company Expenses app I want to click on the following expense to view the details:
This how-to will teach you how to do the following: * How to use preconditions in test cases * Analyzing the results of a test case with preconditions
Before starting with this how-to, make sure you have completed the following prerequisites:
3 How to use preconditions in test cases
The following steps explain how to create a test case with preconditions:
- Open ATS and go to your project.
- Click the Test Cases menu item to go to the Repository tab.
- Create a new test case and record the following steps:
- Open the Company Expenses app
- Log in as employee
- Log out
- Add the Find/Assert DataGrid Row action. Give it a description and enter an output value name.
You must add the Find/Assert DataGrid Row action instead of the Click DataGrid Row action, since it has an output parameter which you need in the next steps.
grid7in Widget Name,
column9in Column 1 Name and “Some office supplies” in Column 1 Value. You can make the search for this data grid row more specific by entering more column names with values. The different values are found by using the ATS Helper. For more information on how to find these values, see How to Create a Test Case.
- Check the Precondition checkbox.
- Click Setup precondition.
Clicking Setup precondition opens the Select funtion or action dialog:
- Add the Find/Assert DataGrid Row action as precondition.
You add the same action as a precondition because you do not want the test case to fail at this step if the expense is not present on that page.
- Enter the same values in the input parameter fields:
Now you want to double-click on the expense, but only if the expense is present on that page.
- Add the Click/Doubleclick action and enter a description.
- Use the output of the previous step in the Element input parameter and set Doubleclick to true.
- Add the Assert not equalTo action as precondition.
- Use the output of the previous step in the Object 1 input parameter of the precondition and Leave Object 2 empty:
By adding the Assert not equalTo action as precondition the underlying action is only executed if the expense is found in the previous step. If step 3 is not executed then the output of step 3 is empty. The Assert not equalTo action then asserts empty with empty, which are equal to each other, so the precondition fails and the actual test step is not executed.
These two steps are enough to only double-click on the expense in case the expense is present on the page. But if the expense is not present on the page ATS does not execute the double-click. The next step is to make ATS search the next page in the data grid for the expense and click on it if found.
- Record your click on the Next page button and add the step:
- Add the Assert equalTo action as precondition.
- Use the output of step 3 in the Object 1 input parameter of the precondition and leave Object 2 empty:
ATS only executes the underlying action if the expense is not found in step 3 because you added the Assert equalTo action as precondition. If step 3 is not executed the output of step 3 is empty. The Assert equalTo action then asserts empty with empty, which are equal to each other, so the precondition is successful and the test step is executed.
- Add the Find/Assert DataGrid Row action to be able to find the expense on this page. Use the same values as in the previous Find/Assert DataGrid Row action.
- Add the Assert equalTo action as a precondition and use the outcome of step 3 in the Object 1 input parameter:
- Add the Click/Doubleclick action and give the action a description.
- Add the Assert equalTo action as a precondition and use the outcome of step 6 in the Object 1 input parameter:
- The last step that you must add is the Close Dialog step, as double-clicking on an expense opens the New Expense dialog:
Before you run the test case you must define the setup and teardown steps, depending on your test situation.
The final test case looks like this:
4. Analyzing the results of a test case using preconditions
Running the test case can give two different results. If the expense is present on the first page the test run results look like:
If the expense is present on the second page the test run results look like:
If the expense is present on the first page ATS does not click on the next button and does not search for the expense on the second page. So, ATS skips the steps 5, 6 and 7. If the expense is present on the second page ATS skips step 3 and 4. As ATS cannot find the expense in step 3, ATS will not click on the expense in step 4.
Congratulations, you created a test case using preconditions. This is an example of what you can do with preconditions. It is a relatively difficult example, as it shows the different possibilities in ATS. There are many more options like a negative test case, which is the next advised read.