Search code examples
automated-testsrobotframework

In Robot Framework, how to perform data-driven testing by creating a separate test case for each line of data in a text file?


In Robot Framework, we can use Test Template to perform data-driven testing. However, in this method, the number of test cases are fixed. We are not able to add new test cases on-the-fly.

Let's say I have a CSV text file, data.txt:

data-1a, data-1b, data-1c
data-2a, data-2b, data-2c
....
data-Na, data-Nb, data-Nc

The number of lines in the CSV file will change from time to time.

In my Robot Framework test case file, I will read this CSV file. Let's say there are N lines of data in that file, I would like to create N test cases, each using 1 line of data from that file as argument.

Is it possible to do this in Robot Framework?


Solution

  • There is no way to directly do what you want. What you could do instead is write a script that reads your data file and auto-generates a robot test suite based on that data. The script that you use to run your tests could first run this other script to create the test file before running it.

    You could also create the test suite via a suite setup, though I don't think I recommend doing it that way, as I don't think there's anything to gain and it makes your suite more complex.