我遇到了相當奇怪的行為。首先是一些背景:我正在使用批處理檔案在一組專案上運行 SoapUI 測驗運行器,像這樣呼叫它們(引數是被測驗的 Web 服務的名稱、測驗環境的名稱、soapui 運行器的型別、端點基 URL 和輸出目錄結果):
for /D %%a in ("\TestRequests\soap\*") do (
call ..\..\Run\runSoapUITest.bat %%~nxa environ test http://test.endpoint.com ../outputDir/
)
for /D %%a in ("\TestRequests\rest\*") do (
call ..\..\Run\runSoapUITest.bat %%~nxa environ test http://test.endpoint.com ../outputDir/
)
“\TestRequests\soap”包含子目錄(每個測驗的 Web 服務一個),每個子目錄都包含帶有測驗請求的 xml。被呼叫的 runSoapUITest.bat 看起來像這樣:
set WSname=%1
set environementName=%2
set runner=%3
set endpoint=%4%
set output=%5%
...
"%SOAPUI_FOR_TEST_DIR%\bin\%runner%runner.bat" -sAutoTest -r -a -j -I -Pendpoint=%endpoint% -Penvironement=%environementName% -PoutputDir=%output% "%current_dir%\..\resources\TestProjects-Auto\%WSname%-soapui-project.xml"
如您所見,共有三個專案級自定義屬性,稱為endpoint、environment和outputDir。每個被呼叫的專案都包含一個名為 AutoTest 的測驗套件和一個名為 Test 的測驗用例,其中包含三個測驗步驟:
Groovy 腳本從我的庫中呼叫腳本,該腳本遍歷 \TestRequests\soap[WSname] 目錄中的 xml 檔案并將它們提供給第 2 步。此腳本還加載專案屬性以了解在哪里可以找到測驗請求 xml 以及在哪里輸出結果。這個腳本在所有的soap web 服務專案中都是通用的,并且非常相似的腳本用于我使用的one rest 服務專案。主要區別在于其余版本顯式填充它從 json 檔案讀取的查詢引數。這是使用外部庫完成的,因此此步驟如下所示:
匯入 wstests.RunTests
def RT = new RunTests(背景關系:背景關系,日志:日志)
RT.Cycle()
testRunner.gotoStep(2)
對于soap專案,對于rest專案是這樣的:
import wstests.RunTests
def RT = new RunTests(context: context, log: log)
RT.CycleRest()
testRunner.gotoStep(2)
- 請求測驗步驟 - 基本上是空外殼,由步驟 1 中的腳本填充。
- 結尾。
所以,問題是,當運行soap web 服務版本時,一切正常。但是當我運行其余的 Web 服務版本時,我遇到了例外:java.lang.NullPointerException:Cannot get property 'testCase' on null object at line 下面突出顯示:
def CycleRest() {
--> def environement = testRunner.testCase.testSuite.project.getPropertyValue( "environement" )
def endP = testRunner.testCase.testSuite.project.getPropertyValue( "endpoint" )
def outRoot = testRunner.testCase.testSuite.project.getPropertyValue( "outputDir" )
def projectName= testRunner.testCase.testSuite.project.getName();
context.projectName = projectName
...
奇怪的是,這個腳本的開頭部分與soap專案完全一樣,作業正常:
def Cycle() {
def projectDir = context.expand('${projectDir}');
def environement = context.testCase.testSuite.project.getPropertyValue( "environement" )
def endP = context.testCase.testSuite.project.getPropertyValue( "endpoint" )
def outRoot = context.testCase.testSuite.project.getPropertyValue( "outputDir" )
def projectName= context.testCase.testSuite.project.getName();
context.projectName = projectName
...
有什么理由說明soap專案(基于WSDL)的行為應該與rest專案(基于WADL)不同嗎?
一些備注:這僅在我使用我的庫運行腳本時發生。如果我將腳本直接粘貼到 Groovy 測驗步驟中,它會起作用。在批處理檔案runSoapUITest.bat中設定專案引數似乎有問題,但是呼叫與使用soap的其余部分相同。我一定是忽略了什么,我就是找不到什么。
提前致謝。
uj5u.com熱心網友回復:
好的,經過仔細檢查,我發現了關鍵區別-盡管您可以運行
def environement = testRunner.testCase.testSuite.project.getPropertyValue( "environement" )
從 SoapUI 客戶端內部,當單獨由 testrunner 運行時,缺少testRunner。你必須把它換成背景關系——這甚至可以從我的作業代碼片段中看出。
當我用“背景關系”替換“testRunner”的所有實體時,它按預期作業。我猜你每天都在學習。甚至你顯然已經知道但忘記了的事情。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/374051.html
