18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
Data Driven Testing - How to randomly select a row in data file?
I have a function called enterInformation(); with parameters that I want pulled in from a CSV file. The way I have my CSV file is it has about 12 columns and the first row is the TITLE/HEADER for what each column is. The way I have my script right now is it is always pulling the first line in the CSV file and I do not want that because it is the title/headers and I also want it to pick a random row when inputting text fields.
How would I go about having Sahi enter field information by randomly picking a value from the data set I created (also ignoring the first line if that's possible)?
for (var $i=0; $i<$data.length; $i++){
var $row = $data[$i];
try {
enterInformation($row[0], $row[1], $row[2], $row[3]);
} catch (e) {
_logException(e);
}
break;
}
How would I go about having Sahi enter field information by randomly picking a value from the data set I created (also ignoring the first line if that's possible)?
for (var $i=0; $i<$data.length; $i++){
var $row = $data[$i];
try {
enterInformation($row[0], $row[1], $row[2], $row[3]);
} catch (e) {
_logException(e);
}
break;
}
Answers
And for random number to pick from the set you created is, u can use a function something like this-
var $len=$data.length-1 ( number of records in your csv file)
function randomnum($len)
{
return Math.floor((Math.random() * $len) + 1);
}
this function will return a random number from the set of records in csv
Regards,
Bhavitha