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

发表于:2014-10-13 13:22

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:张飞_    来源:51Testing软件测试网采编

  默认已经用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>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号