how to create and use CSV file for data-driven testing

Asked by keyu ruan on 2012-03-26

There is statement in URL : :

You may optionally create a data file for data-driven testing. Create a ‘^’ delimited txt data file with the same name as the test, plus the ‘.csv’ extension. This will run a test using each row in the data file (1st row of data file is variable name mapping)

Could you list the detail steps regarding how to use this feature? Cause I did add the file and runner is able to recogonized it. But I do not know how to use the data in the file from code perspective. Could you give a example? Thanks!

But the way, Is there a best practical regarding how to orginize test data like: object id or xpath, test case relate data?

Best Regards,
Keyu Ruan

Question information

English Edit question
selenium-simple-test Edit question
No assignee Edit question
Solved by:
keyu ruan
Last query:
Last reply:
Launchpad Janitor (janitor) said : #1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Corey Goldberg (coreygoldberg) said : #2

Say you have a test script named "", and would like to read data values from a text file.

You would create a file named "mytest.csv". This file contains a header row, and rows of data values. Values in each row are separated by a "^". The associated test script will run once for *each* row in the file, using the supplied data values.

Here is an example.

Below I define 2 columns (url, title) and supply 3 rows of data (containing a url and title each). The test script ( would run 3 times. Each time through, it would load another row of values (from mytest.csv) that will be available inside your test script.

data file - mytest.csv:

test script -
from sst.actions import *

hope that helps..


Corey Goldberg (coreygoldberg) said : #3

posted an answer

keyu ruan (keyu-ruan) said : #4

It did help, I am able to use this feature in the framework now. Thanks a lot.