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

Asked by keyu ruan on 2012-03-26

There is statement in URL : http://testutils.org/sst :

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

Language:
English Edit question
Status:
Solved
For:
selenium-simple-test Edit question
Assignee:
No assignee Edit question
Solved by:
keyu ruan
Solved:
2012-04-11
Last query:
2012-04-11
Last reply:
2012-04-10
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 "mytest.py", 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 (mytest.py) 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:
--------------------------------
url^title
www.ubuntu.com^Ubuntu
www.google.com^Google
www.amazon.com^Amazon
--------------------------------

test script - mytest.py:
--------------------------------
from sst.actions import *
go_to(url)
assert_title_contains(title)
--------------------------------

hope that helps..

-Corey

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.