SoapUI利用Groovy把外部数据加载到request中

默认已经用Groovy把外部数据给读取出来了,关键是读取出来后,如何加载到request中去?这里提供了两种方法:
1.该Groovy脚本的名称是"setUp"

1
2
3
4
5
6
7
8
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"

1
2
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>
复制代码

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值