Forum Discussion

lcordy's avatar
lcordy
Occasional Contributor
8 years ago
Solved

Groovy script library

Hi, I am creating a central library of Groovy Classes, however I run into errors when trying to invoke the classes. The reason is because when we run a normal Groovy Script step from within ReadyAPI, it is already invoked with log, context and testRunner. I guess I need to import these in my groovy class to achieve the same.

 

What do I need to import in my groovy classes though? Where are log, testRunner, context etc imported from?

 

When I try to run the class below from a groovy script step with:

 

package soapui.mygroovystuff;;

c = new SetBaseVariables();
c.setBaseVariables();

 

I get "An error occurred [No such property: log for class...". If I comment out the log lines I then get a similar error for testRunner.

 

The class:

 

package soapui.mygroovystuff;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

class SetBaseVariables {

void setBaseVariables() {
Workbook workbook = Workbook.getWorkbook(new File("C:\\Config.xls"));
Sheet configBaseVariables = workbook.getSheet("Config_BaseVariables");

log.info("***************************************************************** Setting TestCase base variables.")

for (int row = 1 ; row < configBaseVariables.getRows(); row ++ )
{
for (int column = 0 ; column < configBaseVariables.getColumns(); column ++)
{
testRunner.testCase.setPropertyValue(configBaseVariables.getCell(column, 0).getContents(), configBaseVariables.getCell(column, row).getContents())
}
}

//log.info("***************************************************************** Setting TestCase base variables complete.")
workbook.close();
}
}

 

Thanks!