SoapUI中多個TestCase之間傳遞參數

 在SoapUI中可以定義一個個的測試用例TestCase,但是有些用例是依賴於之前的用例的,如果純拷貝的話可能會導致用例比較臃腫而且不好維護,比如說存在如下兩個TestCase:

1)CreateUserTestCase:測試創建用戶,通過發送Soap報文方式創建用戶同時需要校驗數據庫中值是否正確

2)ChangUserInfoTestCase:測試修改用戶信息,通過發送Soap報文方式修改用戶信息,需要校驗修改前和修改後的用戶信息

 

ChangUserInfo之前必須得創建一個用戶,純拷貝肯定是不可取的,因爲後續如果創建用戶的接口稍有變動,則需要同時在ChangUserInfoTestCase和CreateUserTestCase修改請求報文。

 

SoapUI在TestCase中提供Run TestCase的Step,可以直接調用指定的TestCase,但是需要前一個TestCase中將屬性傳遞出來,步驟如下:

1)在被調用TestCase中設置返回屬性

    testRunner.testCase.setPropertyValue("屬性名稱",“屬性值”)

2)在調用TestCase中增加Run TestCase指向被調用TestCase

3)在調用TestCase中的其它Test Step中獲取屬性 

 

例如:在CreateUserTestCase中將創建好的用戶ID傳給ChangUserInfoTestCase,則步驟如下:

1)在CreateUserTestCase中通過Groovy Script 設置返回屬性:

     testRunner.testCase.setPropertyValue("UserID",context.getProperty("UserID"))

2) 在ChangUserInfoTestCase中增加Run TestCase:RunNewUserTestCase指向CreateUserTestCase並指定UserID屬性爲輸入值

3)在ChangUserInfoTestCase中獲取執行CreateUserTestCase得到的用戶ID

def NewUserProperties = testRunner.testCase.getTestStepByName( "RunNewUserTestCase" );
log.info(NewUserProperties .getPropertyValue( "UserID" ))

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章