Forum Discussion

kamahade's avatar
kamahade
Regular Contributor
15 years ago

Script problem...

Pro support team ...

I have a script
def compareFunction(String testResponseName, String xpathQuery ) {
def MATCHES="False";

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);

def functionholder = groovyUtils.getXmlHolder("getAsset#Response");
functionholder.namespaces["se"] = "http://"

for ( value in functionholder.getNodeValues(xpathQuery))
{
//log.info "from response:"+value
for(prp in testRunner.testCase.getPropertyNames())
{
if(value == testRunner.testCase.getPropertyValue(prp)){
log.info "Property matches " + value +"=="+testRunner.testCase.getPropertyValue(prp);
// log.info "Testproperty:" + testRunner.testCase.getPropertyValue(prp)
MATCHES = "True";
break;
}
}
}
assert MATCHES == "True"
}




Which is running fine if I call within my script step by

compareFunction("getAsset#Response" , "//se:getAssetResponse/getAssetResponse/AssetInfo/text/*");


However, if I place the same function within a class and place it in /bin/script folder, when I compile, its throwing many errors.

What one should do take care while placing scripts in script library folder ?

Can't I use "Context" with that script ?

my Groovy class looking like this ..

package soapui.em3.releb;

import com.eviware.soapui.support.*;
import com.eviware.soapui.model.testsuite.*;
import com.eviware.soapui.support.XmlHolder;
import com.eviware.soapui.impl.wsdl.teststeps.*;
import com.eviware.soapui.model.testsuite.TestRunContext;
import com.eviware.soapui.impl.wsdl.testcase.*;


public class getOperation {


def compareFunction(String testResponseName, String xpathQuery ) {
def MATCHES="False";

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);

def functionholder = groovyUtils.getXmlHolder("getAsset#Response");
functionholder.namespaces["se"] = "http://"

for ( value in functionholder.getNodeValues(xpathQuery))
{
//log.info "from response:"+value
for(prp in testRunner.testCase.getPropertyNames())
{
if(value == testRunner.testCase.getPropertyValue(prp)){
log.info "Property matches " + value +"=="+testRunner.testCase.getPropertyValue(prp);
// log.info "Testproperty:" + testRunner.testCase.getPropertyValue(prp)
MATCHES = "True";
break;
}
}
}
assert MATCHES == "True"
}
}

2 Replies

  • Hello,

    the "context" variable is accessible to your script, but not to the external class. You can still use it, but you will have to manually pass it to the function you wish to call:


    def compareFunction( String testResponseName, String xpathQuery, context ) {
    //Code goes here
    }


    And call it using:

    compareFunction("getAsset#Response" , "//se:getAssetResponse/getAssetResponse/AssetInfo/text/*", context)


    If you wish to use other variables available to the script (the log object for example) you will have to do the same for them.

    Regards,
    Dain
    eviware.com
  • kamahade's avatar
    kamahade
    Regular Contributor
    Thanks, I got this working now.. Basically,one should do the following..

    import soapui.em3.releb.propUpdate;

    def gp = new soapui.em3.releb.propUpdate();

    gp.propUpdateFunction(testRunner,groovyUtils,log,"TestCaseName","DataSourceStep");


    one shuld place the script in $SOAPUI_HOME_DIR$ \bin\scripts\soapui\em3\releb

    Class file name is propUpdate and method name is propUpdateFunction