Variations - TestlumFramework/Testlum GitHub Wiki
Variations in Testlum allow you to perform data-driven testing by supplying different sets of input data to your test scenarios using CSV files.
This approach is particularly effective for testing various input combinations, both positive and negative, without duplicating test steps.
- Variations are CSV files containing structured test data.
- Each row in the CSV represents a unique test case with specific values for each input field.
- Commonly used for testing forms, APIs, and other inputs where multiple data combinations are necessary.
- Efficiency: Quickly test multiple data sets without rewriting test steps.
- Coverage: Ensure comprehensive testing by covering various input scenarios.
- Maintainability: Centralize test data, making it easier to update and manage.
Include the <variations>
tag in your scenario's <settings>
block to link a CSV file:
<settings>
<variations>test_data.csv</variations>
</settings>
-
test_data.csv
should be located in the designateddata
folder. - Each column header in the CSV corresponds to a variable used in the scenario.
When we link our CSV file to the scenario, it will run as many times as the number of rows in the submitted file with different data inside. Each run of the scenario will iterate through all the values in this file.
To test the functionality and validation of each field manually, it would take a lot of time to write test documentation and conduct manual testing, however, the usage of 'variations' will take much less time, and the efficiency will increase too.
Creation of such a CSV file with data for testing is quite simple because the CSV file consists of rows of data and delimiters that mark the boundaries of the columns. In one such positive or negative file, QA specialists will be able to sort through all possible sets of values that will help to test this functionality more effectively.
Reference CSV data in your test steps using double curly braces {{}}
:
CSV:
firstName,email Bohdan,[email protected] Anna,[email protected]
Scenario:
<input comment="Enter First Name" locator="form.firstName" value="{{firstName}}"/> <input comment="Enter Email" locator="form.email" value="{{email}}"/>
-
{{firstName}}
and{{email}}
will be replaced with values from the CSV during execution.
To iterate over multiple data sets within a single scenario, use the variations
attribute in a <repeat>
block:
<repeat comment="Iterate over test data" variations="test_data.csv">
<web comment="Fill out registration form">
<input comment="Enter Username" locator="form.username" value="{{username}}"/>
<input comment="Enter Password" locator="form.password" value="{{password}}"/>
<click comment="Submit Form" locator="form.submit"/>
</web>
</repeat>
- This setup will execute the enclosed steps once for each row in
test_data.csv
.
With it we can add flexibility to the script and use different expected files for different runs with variations.
- It is necessary to create a variations file with data, where the names of the expected files corresponding to one step are written:
firstName,expected_1 Bohdan,expected_1_1.json Anna,expected_1_2.json
- Next to the scenario, expected files are created according to the name specified in the variations file:
main-test-resources-folder/ βββdata/ βββββ variations/ β βββ test-variation.csv βββscenarios/ βββββ user-profile/ β βββ expected_1_1.json β βββ expected_1_2.json β βββ scenario.xml
- Enter the name of the variable from the
variations
file in the field for theexpected
file and, if necessary, in another field for the variable:<settings> <variations>test-variation.csv</variations> <tags>testlum</tags> </settings> <http comment="Get user details" alias="MY_API"> <get endpoint="/users/{{firstName}}"> <response code="200" file="{{expected_1}}.json"/> </get> </http>
-
Organize CSV Files: Store all variation files in a dedicated
variations/
directory for clarity. - Consistent Naming: Use clear and descriptive names for both CSV files and their columns.
- Data Validation: Ensure all required fields are present and correctly formatted in the CSV.
By leveraging variations, you can enhance your test coverage and maintain cleaner, more manageable test scenarios.