qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          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)  編輯  收藏 所屬分類: 測試學習專欄

          <2014年10月>
          2829301234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 边坝县| 遂昌县| 泾川县| 四子王旗| 巴青县| 百色市| 乌苏市| 滨州市| 夏河县| 锡林浩特市| 新沂市| 安徽省| 上高县| 南陵县| 西青区| 乌审旗| 高雄市| 灌阳县| 上蔡县| 栾川县| 桐庐县| 华亭县| 临湘市| 抚松县| 弥渡县| 周口市| 洛南县| 莱芜市| 水富县| 廊坊市| 丹江口市| 定兴县| 弋阳县| 泾川县| 台安县| 长垣县| 云南省| 加查县| 大理市| 高雄县| 阳曲县|