Data-Driven Testing
In Rapi, users can prepare a dataset to run in a test case. For example, if you want to test a login website, you can import several login credentials into Rapi, and let Rapi test the login website with different sets of login data. This article is going to introduce how to perform a data-driven testing, to import data into Rapi and start testing!
Step 1: Prepare a data file
- Your data file must be in json or csv format. Please convert your file if it's not in these two formats.
- Example:
- This is a json file that has two keys, four values. A total of 8 records of data:
- This is a csv file with 2 keys, 4 values. A total of 8 records of data:
Step 2: Import you data file into Rapi
-
Select the "Data Driven" tab, and press the "Import from file" button:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
-
After selecting the imported data file, if the filename shows up u
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
β Warning
If you're uploading a file that has the same name as an existing file, the upload process will fail. Please remove the existing file before uploading a new one.
Step 3: Add the data-driven command
- To use data-driven testing, use a pair of
FOR_EACH_RECORD
and END
commands.
- Right-click on the workarea and select "Add cmd", type in
FOR_EACH_RECORD
as the command nameοΌand type the filename of your dataset as the "Target" of the command. For example:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
- Use
${YOUR_KEY}
to reference your data. For exampleοΌ
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
- Lastly, add an
END
command at the end of the process:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
Step 4: Play the test case
-
During playback, the FOR_EACH_RECORD
command will turn all the data from your file into global variables, and execute every command within FOR_EACH_RECORD
and END
with each set of data provided.
-
Your imported data can be seen in the "Global Var" tab:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
-
From the execution logs, we can see that each record of data has been executed once:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
Extended Case: One-to-Many Data-Driven Testing
If you want to perform one-to-many test, you can prepare 2 datasets and use nested FOR_EACH_RECORD
command to implement. Below shows an example:
- Prepare your datasets:
- CSV Example Dataset 1οΌ
- CSV Example Dataset 2οΌ
- Add the commands in Rapi:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
- The above commands will result in the following combinations: