Overview The following examples demonstrate reading test data for data-driven testing, etc.
Test data file The test data file used by the following examples:
col1,col2
row1col1,row1col2
row2col1,row2col2
testdata.csv JavaScript function main ()
{
// Read generated output:
// VARIANT #1:
//
// Looks for the file in Test Case Resources,
// then Test Suite Resources:
dataset = testData . dataset ( "testdata.csv" );
// VARIANT #2:
//
// Looks for the file in Test Case Resources,
// then Test Suite Resources:
//dataset = testData.dataset(findFile("testdata", "testdata.csv"));
// VARIANT #3:
//
// Looks for the file in Test Suite Resources:
//dataset = testData.dataset(squishinfo.testCase + "/../shared/testdata/testdata.csv");
for ( var row = 0 ; row < dataset . length ; row ++ ) {
value_col1 = testData . field ( dataset [ row ], "col1" );
value_col2 = testData . field ( dataset [ row ], "col2" );
test . log ( "Next row:" );
test . log ( " " + value_col1 );
test . log ( " " + value_col2 );
}
}
test.js Python def main ():
# Read generated output:
# VARIANT #1:
#
# Looks for the file in Test Case Resources,
# then Test Suite Resources:
dataset = testData . dataset ( "testdata.csv" )
# VARIANT #2:
#
# Looks for the file in Test Case Resources,
# then Test Suite Resources:
#dataset = testData.dataset(findFile("testdata", "testdata.csv"))
# VARIANT #3:
#
# Looks for the file in Test Suite Resources:
#dataset = testData.dataset(squishinfo.testCase + "/../shared/testdata/testdata.csv")
for index , row in enumerate ( dataset ):
value_col1 = testData . field ( row , "col1" )
value_col2 = testData . field ( row , "col2" )
test . log ( "Next row ( %s ):" % index )
test . log ( " %s " % value_col1 )
test . log ( " %s " % value_col2 )
test.py A More Complex Example This example (partially consisting of pseudo code, so it cannot be executed actually) demonstrates a more complex case - reading some login information from the test data file and using it:
Test script:
import names
def main ():
# Read generated output:
dataset = testData . dataset ( findFile ( "testdata" , "testdata.csv" ))
for row in dataset :
username = testData . field ( row , "username" )
password = testData . field ( row , "password" )
login ( username , password )
do_something_else ()
def login ( username , password ):
# This will give an error because the object names
# used here do not exist; this is just an example:
test . log ( "Logging in with user '" + username + "' and password '" + password + "'" )
type ( names . Username_LineEdit , username )
type ( names . Password_LineEdit , password )
clickButton ( names . Login_Button )
def do_something_else ():
test . log ( "Doing something else..." )
test.py Test data file:
username,password
user1,password1
user2,password2
user3,password3
testdata.csv Copyright © 2024 The Qt Company Ltd. All rights reserved.
Privacy Policy Usage Data Processing by Google We would like to use Google Analytics to get a better understanding of how
you use the website.
By agreeing to this, your usage data will be stored in the USA and processed
by Google LLC. Both Google as well as federal US agencies can access this data
and combine it with any other data about you, such as your search history,
personal accounts or any other data known to Google.
See our privacy
policy to toggle this feature and to learn more, or contact
us .