gpt4 book ai didi

SoapUI 模拟服务/模拟操作中的 XPATH 调度

转载 作者:行者123 更新时间:2023-12-03 16:01:46 24 4
gpt4 key购买 nike

我是 SoapUI 的新手,正在尝试了解 XPATH 分派(dispatch)在模拟服务中用于模拟操作的用法。

这是我到目前为止所做的

  1. 为计算器创建模拟服务
  2. 添加了模拟操作减法

以下是操作请求示例

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://www.parasoft.com/wsdl/calculator/">
<soapenv:Header/>
<soapenv:Body>
<cal:subtract>
<cal:x>1</cal:x>
<cal:y>1</cal:y>
</cal:subtract>
</soapenv:Body>
</soapenv:Envelope>

以下是相同的示例响应

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://www.parasoft.com/wsdl/calculator/">
<soapenv:Header/>
<soapenv:Body>
<cal:subtractResponse>
<cal:Result>?</cal:Result>
</cal:subtractResponse>
</soapenv:Body>
</soapenv:Envelope>

我能够理解其他调度,但不能理解 XPATH,因为以下是我在 XPATH 调度中输入的内容

declare namespace cal='http://www.parasoft.com/wsdl/calculator/';
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
//cal:subtract/cal:x

还观察到,如果我已经使用 SCRIPT 调度并从下拉列表切换到 XPATH,则脚本在声明/脚本框/区域中可见

问题如下:

  1. XPATH 和 SCRIPT 调度是否相同
  2. 如果不是,那么 XPATH 调度实际上如何工作以识别从所有形式的 MockResponses 列表中调度什么响应

请帮我解决这个问题。

PS:我已经通过了 http://www.soapui.org/soap-mocking/reference/mockoperation.html http://www.soapui.org/soap-mocking/mockoperations-and-responses.html

最佳答案

您在问题中提到的 soapUI 文档是获取信息的正确位置。但是,可用的信息并不完整。

经过一段时间的查找,找到了详细信息。

最初,对 XpathScript Dispatch 方法感到困惑。

这里是您正在寻找的额外信息:

Is XPATH and SCRIPT dispatch same

答案是。两者不同

If not, how does the XPATH dispatch actually work to identify what response to dispatch out of all form MockResponses list

following在文档中找到的信息:

XQUERY - This is similar to the QUERY_MATCH but not quite as powerful; an XPath expression is applied to the incoming request and the resulting value is used for selecting which MockResponse to be returned. In our previous example of search results, we could set the XPath expression to select a search term and then create MockResponses named after each expected value. The advantage being that we don’t need to add new XPath statements for new search criteria, just another MockResponse.

假设您为减法操作创建了多个响应,例如PositiveResponseNegativeResponseZeroResponse模拟服务

以下是您可能希望在请求中应用并发送适当的响应 的示例条件。当然,您可以根据需要拥有任意数量。

  1. PositiveResponse - 如果 x、y 值分别为 10、5。
  2. NegativeResponse - 如果 x、y 值分别为 5、10。
  3. ZeroResponse - 否则(如果以上都不满足,则这是强制性的)。

这里是你需要如何在为 XPATH Dispatch mode 提供的编辑器中编写

declare namespace cal='http://www.parasoft.com/wsdl/calculator/';
if (//cal:subtract/cal:x[. = '10'] and //cal:subtract/cal:y[. = '5']) then
'PositiveResponse'
else
if (//cal:subtract/cal:x[. = '5'] and //cal:subtract/cal:y[. = '10']) then
'NegativeResponse'
else
'ZeroResponse'

希望您现在了解并区分SCRIPT 调度模式。

I think the confusion created because both SCRIPT and XPATH shows an editor of same type. But the content inside of it will be entirely different. Also you can easily see a message on top of the editor that log, context, mockRequest availability of variables if you select SCRIPT Dispatch mode and it vanishes when XPATH is choosen.

只是给出SCIRPT的例子,如果你对它感兴趣的话:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
def x = holder.getNodeValue("//*:x") as int
def y = holder.getNodeValue("//*:y") as int
context.result = x - y

A simple test can be (to differentiate between the two), copy the above script for xpath and try testing and soap fault is received saying does not know groovyUtils. This test will confirm that xpath and script are different.

这里您可能不需要创建多个响应,因为上面的代码可以处理动态输入值并在响应中设置结果subtract 操作的 MockReponse 可能如下所示,place holder${result}

脚本的 MOCKRESPONSE:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://www.parasoft.com/wsdl/calculator/">
<soapenv:Header/>
<soapenv:Body>
<cal:subtractResponse>
<cal:Result>${result}</cal:Result>
</cal:subtractResponse>
</soapenv:Body>
</soapenv:Envelope>

希望这能澄清。

关于SoapUI 模拟服务/模拟操作中的 XPATH 调度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34657539/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com