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>

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM