SoapUI中使用Groovy修改请求消息&校验返回消息
来源:互联网 发布:手机片头制作软件 编辑:程序博客网 时间:2024/05/24 22:42
SoapUI在测试WebService消息时,在构造用例过程中部分请求参数可能需要通过查询数据库或者通过随机数获取,此时可以借助Groovy脚本完成此功能,具体步骤如下: (1)从TestCase中获取请求消息 def request = testRunner.testCase.getTestStepByName( "TestStep名称" ); def property = request.getProperty( "request" ); log.info(property.value) (2)将请求消息转换为String,并通过XmlParser对其进行修改 def balanceQueryParser = new groovy.util.XmlParser(false,false).parseText(property.value); //获取需要修改的Node节点,每个节点都需要指定前缀限定,通过此种方式获取的节点为NodeList,所以需要加上[0] //通过Node.setValue方法可以对请求参数进行修改 (3)将请求消息写回到TestStep中 在构造用例过程中可能需要对返回结果进行校验,此时可以借助Groovy脚本完成此功能,具体步骤如下: (1)通过SoapUI提供的GroovyUtils获取返回的xml消息的操作XmlHolder def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) def holder = groovyUtils.getXmlHolder( "balanceQuery#Response" ) (2)在XmlHolder中使用Xpath获取返回字段内容 def messageBody = holder.getDomNode("//uvs:balanceQuery/uvs:BalanceQueryRequest/uvs:RequestMessage/uvs:MessageBody") //获得节点对象的xml (3)如需通过xmlHolder获取其余信息参考如下: GroovyUtils 与 XmlHolder 参考: GroovyUtils currently includes the following (few) methods: XmlHolder object has the following methods: PS: http://blog.csdn.net/shuaihonggao/archive/2010/09/06/5866845.aspx
def transactionid = balanceQueryParser["soapenv:Body"]["uvs:balanceQuery"]["uvs:BalanceQueryRequest"]["uvs:RequestMessage"]["uvs:MessageHeader"]["uvs:TransactionId"][0];
transactionid.setValue(System.currentTimeMillis())
def writer = new java.io.StringWriter();
def printer = new groovy.util.XmlNodePrinter( new PrintWriter( writer ));
printer.print( balanceQueryParser );
property.setValue( writer.toString() )
log.info(property.value)
log.info(holder.getNodeValue("//uvs:balanceQuery/uvs:BalanceQueryRequest/uvs:RequestMessage/uvs:MessageBody/uvs:SubscriberNo"));
log.info(messageBody.getNodeValue())
def subscriberNo = messageBody.getElementsByTagName("SubscriberNo");
log.info(subscriberNo)
//log.info(holder.xml)projectPath
: a property holding the path to the containing project, useful for accessing data files in same foldersetPropertyValue( String testStepName, String propertyName, String value )
: sets the specified property valueexpand( string )
- expands the specified Property Expansion stringgetXmlHolder( String xmlPropertyOrString )
: Creates an XmlHolder
object (see below) for easily accessing/modifying contents of an XML document using XPath expressions. The argument must either be a TestStep property in the TestStepName#PropertyName
format or a valid XML stringgetNodeValue( String xpath )
: returns the value of the first node pointed to by the specified XPath expression (can be replaced by holder[xpath] expression, see below )getNodeValues( String xpath )
: returns a String array containing the values of all nodes pointed to by the specified XPath expression.getDomNode( String xpath )
: returns the DOM Node of the first node pointed to by the specified XPath expression.getDomNodes( String xpath )
: returns a DOM Node array containing all nodes pointed to by the specified XPath expression.setNodeValue( String xpath, String value )
: sets the content of the first node pointed to by the specified XPath expression to the specified value (can be replaced by holder[xpath] = value expression, see below )declareNamespace( String prefix, String namespaceURI )
: declares a namespace that will be used in a following get/set operation, can also be set with holder.namespaces[prefix] = namespaceUri (see example below)getNamespaces()
- returns a Map of prefixes to namespace URI:s that will be used in XPath expressionsremoveDomNodes( xpath )
- removes all DOM nodes matching the specified XPath expressionxml
: property containing the updated xml stringxmlObject
: property containing the parsed XMLBeans XmlObject for the xml stringprettyXml
: property containing the pretty-printed updated xml stringupdateProperty()
: if the XmlHolder was created from a TestStep property, that property will be updated with the currently held xml (see example below)updateProperty( boolean prettyPrint )
: same as previous, with option to pretty print the updated xml. Defaults to false when not specified.
- SoapUI中使用Groovy修改请求消息&校验返回消息
- SoapUI中使用Groovy修改请求消息&校验返回消息
- SoapUI中使用GroovyUtil & XmlHolder 修改请求消息
- SoapUI中使用Groovy脚本操作数据库 .
- SoapUI中使用Groovy脚本操作数据库
- SoapUI中使用Groovy脚本操作数据库
- 【SoapUI】在soapui中使用Groovy脚本常用方法
- SOAPUI 使用groovy发送http请求 自动化测试
- SoapUI+Groovy获取返回值并作为参数传递给另一个用例-基于Post请求
- android http请求 状态消息返回
- 使用aspectj模拟返回消息
- fix协议中消息尾校验方法
- 请求消息
- 请求消息
- soapUI+groovy 接口测试之部分groovy使用记录
- ASTM校验和计算与消息返回--根据消息类型切割
- ASTM校验和计算与消息返回--固定长度切割消息
- 报文消息校验
- PostgreSQL函数用法
- 数据窗口事件中DWO的解释说明
- 整合wordpress的插件!!
- 笔记本的输入设备
- 鼠标不点在对话框上 对话框关闭程序演示
- SoapUI中使用Groovy修改请求消息&校验返回消息
- TDD相关测试框架
- 装饰器模式
- 自动交叉产品
- GridView的主从表编辑和新增
- C++字符统计
- MySQL拾遗
- Android培训班(56)Dalvik虚拟机的入口点
- 昨天和今天工作了2天,利用以前写好的宏,把boost::tuple 作了一个扩展。