By utilizing the 'Data Patterns' feature, you can conduct what is known as 'Data-driven testing,' where a single test script is executed repeatedly with varying input data patterns.
Table of contents
- Set up data patterns
- Run the test and check results
- Set data patterns via CSV format
- Use conditional branching commands
- Use variable-based locators
- References
Set up data patterns
From the edit test menu on the edit test case screen, select Set Up Data Pattern (Figure 1).
Figure 1: Set up data pattern
In the dialog that appears, define the variable names and data patterns. For example, in Figure 2, two data patterns are defined for the variables UNAME and GENDER. After defining the patterns, click the OK button to save the changes.
Figure 2: Define data patterns
Next, create the script to be executed. In the script, data pattern variables can be referenced using the format ${UNAME} or ${GENDER} (Figure 3).
Figure 3: Script referencing data pattern variables
Run the test and check results
When you run the test you created, you will see that the test is run repeatedly for each data pattern. In the test results list screen, as shown in Figure 4, you can view a breakdown of the success and failure counts of all data patterns. And in the test results detail screen, as shown in Figure 5, you can check the test result for each data pattern.
Figure 4: Test results list screen
Figure 5: Test results detail screen.
If you want to execute a specific data pattern in a batch run, specify it as "3[2], 3[3]".
For example, "3[2]" specifies the second data pattern of the test case whose test case number is "3".
Set data patterns via CSV format
When there are many data patterns, it's easier to set them up using a CSV file.
To set up, click the ︙ button in the upper right corner, then select Upload CSV.
Figure 6: Set up data pattern screen
In this case, the CSV file will look as follows, with ',' separating each piece of data.
Figure 7: Sample CSV file.
Use conditional branching commands
You can create tests that change which options to check for each data set. For example, you have the following checkbox and want to vary whether it is checked or not depending on the provided data.
Figure 8: Checkbox
In this case, set a variable 'BreakfastOption' and implement conditional branching based on the value of this variable. For more information on conditional branching commands, refer to Utilize Conditional Branching.
Figure 9: Set up data pattern
Figure 10: Example step to check the checkbox using the 'If variable value equals' command
Figure 11: Example step to uncheck the checkbox using the 'If variable value equals' command
Use variable-based locators
You can create tests that change the element’s locator depending on the variables in the data pattern. For example, suppose you have the following three checkboxes and want to change the one being checked in each data set, you would set an ‘id’ attribute to each checkbox in the source code.
Figure 12: Checkboxes
For this, set a variable ‘option_id’ and input the id name for each data.
Figure 13: Set up data pattern
Then, add a variable-based locator, and apply a click command to the element identified by this locator. This method allows you to change the click target for each data set. For more information on adding variable-based locators, refer to Add a locator.
Figure 14: Variable-based locator
Figure 15: Example step