SoapUI利用Groovy把外部數據加載到request中
默認已經用Groovy把外部數據給讀取出來了,關鍵是讀取出來后,如何加載到request中去?這里提供了兩種方法:
1.該Groovy腳本的名稱是"setUp"
def num = Integer.parseInt(testRunner.testCase.getPropertyValue( "count" )) log.info num num = (++num) % 2 testRunner.testCase.setPropertyValue( "count", num + "") String[] acList = ["Loginn"+String.valueOf(Math.random()).substring( 0, 5 ),"Loginn"+String.valueOf(Math.random()).substring( 0, 6 )] log.info num log.info acList[num] acList[num] |
上面的例子是把數據放到了一個數組中去了,在request中這樣寫,然后再加一個dataloop,就可以循環的來把值賦給request中,然后運行request.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sam="http://www.soapui.org/sample/"> <soapenv:Header/> <soapenv:Body> <sam:login> <username>${setUp#result}</username> </sam:login> </soapenv:Body> </soapenv:Envelope> |
2.該Groovy腳本的名稱是"demo"
testRunner.testCase.testSuite.getTestCaseByName("TestCaseDemo").setPropertyValue("username","Loginn"+String.valueOf(Math.random()).substring( 0, 5 ))
testRunner.testCase.testSuite.getTestCaseByName("TestCaseDemo").setPropertyValue("password","Loginn123")
上面的例子中,TestCaseDemo是指testcase的名稱,在request中這樣寫:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sam="http://www.soapui.org/sample/"> <soapenv:Header/> <soapenv:Body> <sam:login> <username>${#TestCase#username}</username> <password>${#TestCase#password}</password> </sam:login> </soapenv:Body> </soapenv:Envelope> |
posted on 2014-10-14 09:36 順其自然EVO 閱讀(253) 評論(0) 編輯 收藏 所屬分類: 測試學習專欄