cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy script library

SOLVED
lcordy
Occasional Contributor

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!

1 ACCEPTED SOLUTION

Accepted Solutions
StevenColon
Staff

Re: Groovy script library

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.

 

https://support.smartbear.com/readyapi/docs/testing/scripts/library.html

 

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: http://www.soapui.org/apidocs/overview-summary.

 

Have a great day! 

 

Best,
Steven
Atlassian Ecosystem Manager

View solution in original post

4 REPLIES 4
StevenColon
Staff

Re: Groovy script library

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.

 

https://support.smartbear.com/readyapi/docs/testing/scripts/library.html

 

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: http://www.soapui.org/apidocs/overview-summary.

 

Have a great day! 

 

Best,
Steven
Atlassian Ecosystem Manager

View solution in original post

JustinM89
Contributor

Re: Groovy script library

Checkout this documentation (could be out of date): https://www.soapui.org/apidocs/allclasses-noframe.html

 

If you need access to testRunner within your class, make it as a property of your class and set it as part of your constructor:

package com.foo.bar

import com.eviware.soapui.model.testsuite.TestRunner

public class MyClass {
   TestRunner testRunner

   public MyClass(TestRunner testRunner) {
      this.testRunner = testRunner
   }
}

Now you can access the testRunner from within your external libraries.

 

jweiler
Regular Visitor

Re: Groovy script library

TanyaYatskovska
Community Manager

Re: Groovy script library

Hi @jweiler,

 

Please use this link:

https://www.soapui.org/apidocs/overview-summary.html

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors