2015-07-10 115 views
0

我想寫一個groovy腳本,它將包含SoapUI測試套件常用的函數。具體而言,我想編寫一個腳本,其中包含從測試套件輸出的所有日誌。groovy/SoapUi從另一個腳本調用一個靜態函數

GroovyScript1將調用GroovyScripts.groovy文件中的函數。所有這些都存在於SoapUI測試套件中。

我還沒有找到任何有關如何執行此任務的建議。

要再次指定,我想調用另一個Groovy腳本中包含的函數。

+0

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

回答

1

是的,你可以通過以下步驟做到這一點,

在你的「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你的目標。

相關問題