Ask a Question

how i give iteration into my script to read from excel sheet multiple times

SOLVED
Urmikhan
Occasional Contributor

how i give iteration into my script to read from excel sheet multiple times

I used this syntax for to read data but i try to do multiple set of data to run my scripts(rather than keywords) multiple times.so What syntax I should use in to my scripts  to read different data and run my scripts multiple times. 

 

function testdata(){
var Driver = DDT.ExcelDriver("D:\\MyFile2.xlsx", "Sheet1");

// Iterates through records
while (! Driver.EOF())
{
//Gets a value from the storage and posts it to the log
var test =(Driver.Value('Customer name)');
DDT.CurrentDriver.Next();

}

// Closes the driver
DDT.CloseDriver(Driver.Name);
return test;
}

function testone(){
Log.Message("This is : " +testdata())
}

Urmi

2 REPLIES 2
Marsha_R
Community Hero

Run your test inside the DDT loop (your While loop) so it executes once for each time through the loop.   Here are the details:

https://support.smartbear.com/testcomplete/docs/testing-with/data-driven/using-scripts.html


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
RUDOLF_BOTHMA
Community Hero

var test =(Driver.Value('Customer name)');
DDT.CurrentDriver.Next();

 

This always re-initiates the varable test.  That means it will only ever contain the last single value you were looking for.  Try something like this instead:

var returnValue;
while (! Driver.EOF()) 
{ 
//Gets a value from the storage and posts it to the log
returnValue += "; " + (Driver.Value('Customer name')); 
DDT.CurrentDriver.Next(); 

}
...
return returnValue;

This should return a list of all the values for a given field in a single string seperated by ";"

 

That may not be what you are looking for, but it looks like the intent is to bring back ALL the records, rather than just the last record.  Consider making your function more generic:

 

function testdata(filename,sheetname,fieldname){
var Driver = DDT.ExcelDriver(filename, sheetname);
var returnValue while(!Driver.EOF()){
...
returnValue += "; " + Driver.Value(fieldname);
...
}
... } function testone(){ var functionReturn = testdata("D:\\MyFile2.xlsx","Sheet1","Customer Name"); Log.Message(functionReturn); }

That way it means you can re-use the function

 

 


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
cancel
Showing results for 
Search instead for 
Did you mean: