Variations - TestlumFramework/Testlum GitHub Wiki

πŸ“Š Variations in Testlum

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.


πŸ“ What Are Variations?

  • 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.

πŸ§ͺ Why Use Variations?

  • 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.

πŸ› οΈ How to Implement Variations

1. Define Variations in <settings>

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 designated data 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.


2. Use Variations in Test Steps

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.

3. Utilize Variations in <repeat> Blocks

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.

4. Usage variables from 'variations' in the field of expected files

With it we can add flexibility to the script and use different expected files for different runs with variations.

  1. 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
  1. 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
  1. Enter the name of the variable from the variations file in the field for the expected 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> 

πŸ“Œ Best Practices

  • 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.

⚠️ **GitHub.com Fallback** ⚠️