18 January 2026:


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?

mreyesmreyes Members
edited August 2014 in Sahi Pro
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;
}

Answers

  • Its simple that you do not want to get the headers is use the Loop from $i=1 instead of $i=0
    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
Sign In or Register to comment.