无法使用 XPATH 断言包含正则表达式来获得正确的预期响应
Unable to get the correct Expected expected response using XPATH Assertions contains regular expression
我正在使用以下货币转换器开源 WSDL:
http://www.webservicex.com/currencyconvertor.asmx
我在下面添加了 Xpath 断言以验证浮动 ConversationRateResult 响应值
declare namespace soap='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace ns1='http://www.webserviceX.NET/';
matches(//ns1:ConversationRateResult/text(),'[0-9][0-9].[0-9][0-9]*')
但是当我通过在 XPath 匹配配置 window 中的当前按钮单击 Select 来验证它时,我得到的预期值为 "False" 而不是 "True"
能否请您在这方面提出建议。
我尝试了该服务并得到了以下结果:
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ConversionRateResponse
xmlns="http://www.webserviceX.NET/">
<ConversionRateResult>0.0079</ConversionRateResult>
</ConversionRateResponse>
</soap:Body>
</soap:Envelope>
因此,请注意您的 XPath
不正确,节点名称是 ConversionRateResult
而不是 ConversationRateResult
。
另请注意,您的正则表达式未按预期工作...在正则表达式 .
运算符中匹配任何字符,要专门匹配 .
您必须使用 \.
所以最后我认为适合你的情况的正确正则表达式是:
[0-9]+\.?[0-9]*
解释:
[0-9]+
位重复 1 次或多次。
\.?
用于 .
字符,但可选(0 或 1)...这是因为速率可能为 1。
[0-9]*
数字 0 次或多次重复。
希望对您有所帮助,
我正在使用以下货币转换器开源 WSDL:
http://www.webservicex.com/currencyconvertor.asmx
我在下面添加了 Xpath 断言以验证浮动 ConversationRateResult 响应值
declare namespace soap='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace ns1='http://www.webserviceX.NET/';
matches(//ns1:ConversationRateResult/text(),'[0-9][0-9].[0-9][0-9]*')
但是当我通过在 XPath 匹配配置 window 中的当前按钮单击 Select 来验证它时,我得到的预期值为 "False" 而不是 "True"
能否请您在这方面提出建议。
我尝试了该服务并得到了以下结果:
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ConversionRateResponse
xmlns="http://www.webserviceX.NET/">
<ConversionRateResult>0.0079</ConversionRateResult>
</ConversionRateResponse>
</soap:Body>
</soap:Envelope>
因此,请注意您的 XPath
不正确,节点名称是 ConversionRateResult
而不是 ConversationRateResult
。
另请注意,您的正则表达式未按预期工作...在正则表达式 .
运算符中匹配任何字符,要专门匹配 .
您必须使用 \.
所以最后我认为适合你的情况的正确正则表达式是:
[0-9]+\.?[0-9]*
解释:
[0-9]+
位重复 1 次或多次。
\.?
用于 .
字符,但可选(0 或 1)...这是因为速率可能为 1。
[0-9]*
数字 0 次或多次重复。
希望对您有所帮助,