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

groovy/SoapUi Call a static function from another script

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

GroovyScript1 将调用 GroovyScripts.groovy 文件中的函数。所有都存在于 SoapUI 测试套件中。

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

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

是的,您可以按照以下步骤进行操作,

在您的 "GroovyScripts.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 ==========

现在在你的 "GroovyScript1" 文件中你应该使用下面的代码,

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

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