Forum Discussion

EkremMese1's avatar
EkremMese1
Contributor
26 days ago
Solved

Passing test data randomly to script tests from Excel file

Hello everyone, 

Have a productive week. I just started playing around with TestComplete so I will around for some time. Thanks in advance for any comments. 

My question is: 

I created  data by using TestComplete's data generator to an external file. 

How can I pass this data to my code that I record in script testing? I could not find much things to read in official documentation. 

Regards

  • You already have an example in your previous post Item cannot be found in the collection corresponding to the requested name or ordinal and I've already provided documentation links.

    You will have to read the file contents, and store the data into an array. You can then access the array index via a random number, see  Generate a random number within a range | SmartBear Community you can the pass the returned value to your function.

     

3 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    You already have an example in your previous post Item cannot be found in the collection corresponding to the requested name or ordinal and I've already provided documentation links.

    You will have to read the file contents, and store the data into an array. You can then access the array index via a random number, see  Generate a random number within a range | SmartBear Community you can the pass the returned value to your function.

     

  • Thank you for you advice. 
    I wrote a function for that. 
    I will put it here, it may help someone for some day:

    var randomIndexNumber;
    var myArray;
    
    function randomValue(path, sheetName, columnName){
      
    
    var Driver = DDT.ExcelDriver(path , sheetName);
    
    
    // Initialize an empty array  
    myArray = [];  
    
    var recordCount = 0;
    
    while (! Driver.EOF()){
      recordCount++;
      myArray.push(DDT.CurrentDriver.Value(columnName));
      Driver.Next();
    }
    
    var min = 0;
    var max = recordCount; 
    
    randomIndexNumber = Math.floor(Math.random() * (max - min + 1) ) + min;
    
    return myArray[randomIndexNumber];
    
    }
    
    
    
    function foo3 (){
      
    
    var name = foo("Z:\\AAAA\\Faker.xlsx" , "LastName" , "Column1");
    
    Log.Message(name);
    
    }
    
    
    
    module.exports.randomValue = randomValue;