如何使用SOAP UI Xquery Matches获得某些期望值 [英] How to get certain expected values using SOAP UI Xquery Matches

查看:124
本文介绍了如何使用SOAP UI Xquery Matches获得某些期望值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回某些值的webService.我知道这些价值是什么.我想从XML中选择它们,如果这些值是true,那么我希望声明通过.想象一下,如果我得到这个结果,我的测试就通过了……我怎么能断定是这种情况?

I have a webService that returns certain values. I know what those values will be. I want to pick them out of the XML and if those values are true I want the assertion to pass. Imagine that my test passes if I get this result... How can I assert that that is the case?

     <BasicPersons>
           <id>4</id>
           <firstName>Patricia</firstName>
           <middleName>A</middleName>
           <lastName>Cluss</lastName>
        </BasicPersons>
        <BasicPersons>
           <id>5</id>
           <firstName>Benjamin</firstName>
           <middleName>L</middleName>
           <lastName>Handen</lastName>
        </BasicPersons>
        <BasicPersons>
           <id>6</id>
           <firstName>Ellen</firstName>
           <lastName>Frank</lastName>
        </BasicPersons>
        <BasicPersons>

推荐答案

SoapUI为测试步骤提供了XPath断言,该步骤从响应中提取XML元素并将其与预期数据进行比较.

SoapUI provides XPath assertion for test steps that extracts XML element from the response and compare it with expected data.

让我们以您的XML片段为例(我添加了root元素使其结构良好).首先在SoapUI中创建新的Test Request步骤,并在其中填充请求XML.然后,让我们检查响应是否包含id = 4的BasicPersons元素以及所有其他指定的字段.从Property Content组添加新的断言XPath Match.然后键入用于检查的表达式.这是我得到的:

Let's take you XML fragment as an example (I added root element to make it well-formed). First create in SoapUI new Test Request step and fill it with request XML. Let's then check whether response contains BasicPersons element with id=4 and all other specified fields. Add new assertion XPath Match from Property Content group. Then type in the expression for the check. Here is what I get:

boolean(/root/BasicPersons[id=4 and firstName="Patricia" and middleName="A" and lastName="Cluss"])

如果XPath与XML响应匹配,则

Expected Result应为true.否则断言将失败.

Expected Result shall be true if XPath matches XML response. The assertion fails otherwise.

您可以创建多个断言来测试您的回复中的多个人.

You may create several assertion for testing several persons from your response.

这篇关于如何使用SOAP UI Xquery Matches获得某些期望值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆