Forum Discussion

lcordy's avatar
Occasional Contributor
7 years ago

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();


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;

class SetBaseVariables {

void setBaseVariables() {
Workbook workbook = Workbook.getWorkbook(new File("C:\\Config.xls"));
Sheet configBaseVariables = workbook.getSheet("Config_BaseVariables");"***************************************************************** 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())

//"***************************************************************** Setting TestCase base variables complete.")



  • Thank you for posting to our Community Forum. 



    Here is our documentation on the groovy script library that includes an example external script. In this example they use a static method and import the log object from a groovy script TestStep. In that case you don't need to know the library with the log object.



    I do not know where the log object is stored. In a groovy TestStep, I ran the script log.class and it returned "org.apache.log4j.Logger". Maybe that can help you.


    Here is also our site with all available methods:


    Have a great day! 


4 Replies