Forum Discussion

rcmcdonough's avatar
rcmcdonough
New Contributor
13 years ago

context class from external groovy script

Hi,

I was able to get/set variables using the context class and a test step groovy script thanks to MMcDonald's help. I would like to do the same thing using an external groovy script so all of our projects will have access to the class methods. We are using soapUI-Pro-4.5.1. When I do a simple call to the script:
def splitUrl = new commonScripts.SplitRestURL()

I get the following error:
Tue Nov 20 12:50:02 EST 2012:ERROR:An error occured [No such property: context for class: commonScripts.SplitRestURL], see error log for details


Below is the what I have in my external groovy class file:
package bullhorn

import com.eviware.soapui.impl.wadl.inference.schema.Context

// split the restUrl returned by a rest-services login call to extract corpId and
// rebuild restUrl string without the trailing
// saving each token on the url and they can be used as a soapui global property
// at a later date if needed.
// sets restURL and CorpId global properties

class SplitRestURL
{
def ip
def Port
def restServices
def corpId
def restURL
def responseURL
def httpProtocol

SplitRestURL()
{
def rest = context.expand('${#Global#rest}')
def restArray = rest.split("/")

httpProtocol = restArray[0]
ip = restArray[2].split(":")[0]
port = restArray[2].split(":")[1]
restServices = restArray[3]
corpId = restArray[4]
}

void setProps()
{
log.info(" mod restURL: " + restURL)
restURL = httpProtocol + "://" + ip + ":" + Port + "/" + restServices + "/" + corpId
responseURL = httpProtocol + "://" + ip + "/" + restServices + "/" + corpId
testRunner.testCase.testSuite.project.setPropertyValue("restURL", restURL)
testRunner.testCase.testSuite.project.setPropertyValue("corpId", corpId)
}
}


I'm pretty sure my next question will be...where are the log and testRunner classes defined :-)

Thanks...Rhonda
No RepliesBe the first to reply