SOAPUI中文教程---转移属性
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SOAPUI中文教程---转移属性相关的知识,希望对你有一定的参考价值。
Property Transfer TestSteps用于在TestSteps和它们包含的TestCase,TestSuite和Project之间传递属性。它们在许多情况下非常有用,特别是当涉及包含XML的属性时,例如- 从XML消息中提取值,例如来自SOAP Response的sessionID
- 将值写入XML消息,例如保存的sessionID或认证数据
- 在属性之间传输复杂的XML内容
1. The Property-Transfer Window
- 顶部的源区域指定源属性和可选的XPath用于传输
- 目标区域指定目标属性和可选的XPath进行传输
- 下面的区域将不同的配置选项设置在传输级别上。
- Fail transfer on error - 尝试执行转移时发生任何错误时,转移步骤将失败
- Transfer text content - 只会传送文字内容。不会保留结构元素
- Transfer to all - 匹配的值将被转移到所有的目标位置,以防多个匹配
- Entitize transferred values - 这些值将具有某些字符,例如&符号(“&”)替换为相应的字符实体值(“&”)
- Set null on missing source - 如果源资源丢失,目标将设置为null。这意味着如果目标已经有一个值,它将丢失
- Ignore empty/missing values - 这意味着如果源的匹配值为空或丢失,则它将被忽略,并且目标值保持不变
- Use XQuery - 当尝试提取源值时SoapUI将假定源是XQuery而不是默认的XPath
- Transfer child nodes - SoapUI不会尝试从匹配的源节点进行任何文本提取,而是选择匹配节点的子节点,从而保留子树XML结构
2. 转移执行
When the PropertyTransfer TestStep is executed during a TestCase run, each transfer in the Property Transfer is performed by selecting the property specified by the transfers source step, property and optional XPath expression and copying their value(s) to the destination steps specified property using an optional XPath expression. If XPath expressions are specified, soapUI will try to replace the target node with the source node if they are of the same type. If not (for example when assigning text() to an @attribute), soapUI will do its best to copy the value as possible.
Source and target XPath expressions must both point to existing nodes in their respective properties, the source property obviously requires the node so it can be selected, the target property requires the node so it can be found and overwritten.
If any of the transfers fail due to missing matches of any of the XPath expression, an error is printed and the step will either fail or go on, depending on of the "fail on error" option has been selected for that transfer. TestCase execution is only aborted if the TestCases‘ "Fail on error" option has been set as described for under TestCase Options.
3. An example: transferring a session ID from a response to a following request
- 添加并执行登录请求到一个空的TestCase,所以你需要有一个有效的响应来处理;
- 请求后创建Property-Transfer TestStep,并向其中添加属性传输;
- 将源属性配置为“Response”,然后在源属性工具栏右侧选择“向导”按钮。这将打开一个方便的向导,用于选择要传输的所需源节点(在标准soapUI中,您将必须手动创建生成的XPath语句)。
- 选择节点,然后按OK; soapUI为您生成相应的XPath语句;
- 将其写入可以由需要使用sessionID的所有后续测试步骤引用的临时属性。如果我们要在几个地方使用sessionID或者TestSteps,这是最好的解决方案
- 将其直接传输到应该使用该值的目标TestStep。如果您只想在一个地方使用该值,这将更容易
3.1. 写入临时属性
<logout>
<sessionID>${#TestCase#SessionID}</sessionID>
</logout>
3.2. 直接写入所需的目标TestStep
以上是关于SOAPUI中文教程---转移属性的主要内容,如果未能解决你的问题,请参考以下文章