Methods groovy/SoapUi从另一个脚本调用静态函数

Methods groovy/SoapUi从另一个脚本调用静态函数,methods,groovy,soapui,Methods,Groovy,Soapui,我正在尝试编写一个groovy脚本,它将包含SoapUI测试套件所共有的函数。具体来说,我想编写一个脚本,其中包含测试套件输出的所有日志 GroovyScript 1将调用groovyScript.groovy文件中的函数。所有这些都存在于SoapUI测试套件中 我没有找到任何关于如何执行此任务的有用建议 要再次指定,我想调用另一个Groovy脚本中包含的函数。是的,您可以通过以下步骤执行此操作 在“groovyScript.groovy”文件中添加以下代码 class GLF { d

我正在尝试编写一个groovy脚本,它将包含SoapUI测试套件所共有的函数。具体来说,我想编写一个脚本,其中包含测试套件输出的所有日志

GroovyScript 1将调用groovyScript.groovy文件中的函数。所有这些都存在于SoapUI测试套件中

我没有找到任何关于如何执行此任务的有用建议


要再次指定,我想调用另一个Groovy脚本中包含的函数。

是的,您可以通过以下步骤执行此操作

在“groovyScript.groovy”文件中添加以下代码

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 ==========
lib = testRunner.testCase.testSuite.project.testSuites["GroovyLibraryFunction"].testCases["TestCase 1"].testSteps["EndpointVerification"]

lib.run(testRunner, context)

def RT = context.Rt

def PT = RT.returnVal()

log.info PT
现在,在“GroovyScript1”文件中,您应该使用以下代码

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 ==========
lib = testRunner.testCase.testSuite.project.testSuites["GroovyLibraryFunction"].testCases["TestCase 1"].testSteps["EndpointVerification"]

lib.run(testRunner, context)

def RT = context.Rt

def PT = RT.returnVal()

log.info PT

这样你就可以实现你的目标。

是的,你可以通过以下步骤来实现

在“groovyScript.groovy”文件中添加以下代码

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 ==========
lib = testRunner.testCase.testSuite.project.testSuites["GroovyLibraryFunction"].testCases["TestCase 1"].testSteps["EndpointVerification"]

lib.run(testRunner, context)

def RT = context.Rt

def PT = RT.returnVal()

log.info PT
现在,在“GroovyScript1”文件中,您应该使用以下代码

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 ==========
lib = testRunner.testCase.testSuite.project.testSuites["GroovyLibraryFunction"].testCases["TestCase 1"].testSteps["EndpointVerification"]

lib.run(testRunner, context)

def RT = context.Rt

def PT = RT.returnVal()

log.info PT

这样你就可以实现你的目标。

不完全是这样。但是这样做可以将所有可重用方法放在一个groovy类中,比如
类GroovyScript{//所有可重用方法都放在这里}
。编译这个类并创建一个jar文件,并将这个文件放在SOAPUI_HOME/bin/ext目录下。现在,不管需要什么,只要在任何项目中的Groovy脚本测试步骤中从上面的类调用methods即可。希望这有帮助。不完全是。但是这样做可以将所有可重用方法放在一个groovy类中,比如
类GroovyScript{//所有可重用方法都放在这里}
。编译这个类并创建一个jar文件,并将这个文件放在SOAPUI_HOME/bin/ext目录下。现在,不管需要什么,只要在任何项目中的Groovy脚本测试步骤中从上面的类调用methods即可。希望这有帮助。