Forum Discussion

LauraLaura's avatar
New Member
7 years ago

Skip row of excel datadriver in groovy script

I'm running testcases based on an .xls datadriver file, which loops until the last row is found. However my excel file has headers, how can I make my data driver skip the first row of headers, since this is not testdata. 




def myTestCase = context.testCase //myTestCase contains the test case
def counter,next,previous,size//Variables used to handle the loop and to move inside the file

// Change file directory
Workbook workbook1 = Workbook.getWorkbook(new File("C:/driver.xls")) //file containing the data (CHANGE THIS) "C:/driver.xls"

Sheet sheet1 = workbook1.getSheet("ins2_all_opt_out") //save the first sheet in sheet1
size= sheet1.getRows().toInteger() //get the number of rows, each row is a data set size
propTestStep = myTestCase.getTestStepByName("Property - Looper") // get the Property TestStep object
propTestStep.setPropertyValue("Total", size.toString())

counter = propTestStep.getPropertyValue("Count").toString() //counter variable contains iteration number
counter = counter.toInteger() // counter

next = (counter > size-2? 0: counter+1) //set the next line value next

Cell a = sheet1.getCell(0,counter) // getCell(column,row) //obtains cardnumber cell A, stores into C 


workbook1.close() //close the file a.getContents()
propTestStep.setPropertyValue("MemberNumber", a.getContents()) //value saved into property, for the appropriate test step

propTestStep.setPropertyValue("Count", next.toString())

next++ //increase next value

propTestStep.setPropertyValue("Next", next.toString()) //set Next value on the properties step

//Decide if the test has to be run again or not "info: counter: " + counter + "next: " + next + "size: " + size;

if (counter == size-1)

propTestStep.setPropertyValue("StopLoop", "T") "Setting the stoploop property now..."

else if (counter==0)
def runner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testRunner.testCase, null)
propTestStep.setPropertyValue("StopLoop", "F")


propTestStep.setPropertyValue("StopLoop", "F")
} propTestStep.getPropertyValue("StopLoop"); propTestStep.getPropertyValue("XML");// IMPORT THE LIBRARIES WE NEED

No RepliesBe the first to reply