user1420688 user1420688 - 1 year ago 290
Groovy Question

groovy/SoapUi Call a static function from another script

I am trying to write a groovy script which will contain functions that are common to the SoapUI test Suite. Specifically I want to write a script that will contain all the logs that are output from the test suite.

GroovyScript1 will call a function in the GroovyScripts.groovy file. All is present in a SoapUI test suite.

I have not found any helpful advice on how to perform this task.

To specify again, I want to call a function contained in another Groovy Script.

Answer Source

Yes You can do this by following steps,

In your "GroovyScripts.groovy" file add below code,

class GLF

    def log
    def context
    def testRunner

    def GLF(logIn, contextIn, testRunnerIn)
        this.log = logIn
        this.context = contextIn
        this.testRunner = testRunnerIn

    //Till abobe line you must keep same code except class name 

    public String returnVal()
        return 'Himanshu'

context.setProperty("Rt", new GLF(log, context, testRunner))
============================ END GroovyScripts.groovy ==========

Now in your "GroovyScript1" file you should use below code,

lib = testRunner.testCase.testSuite.project.testSuites["GroovyLibraryFunction"].testCases["TestCase 1"].testSteps["EndpointVerification"], context)

def RT = context.Rt

def PT = RT.returnVal() PT

This way you can achive your target.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download