是的,你可以通過以下步驟做到這一點,
在你的「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
這樣你就可以achive你的目標。
不完全。但是這樣做會提供所有可重用方法,像GroovyScripts {//所有可重用的方法都在這裏}這樣的常規類。編譯這個類並創建一個jar文件,並將這個文件放在SOAPUI_HOME/bin/ext目錄下。現在,只需要在任何項目的Groovy腳本測試步驟中從上級調用方法。希望這可以幫助。 – Rao