【问题标题】:SOAPUI - How can I Pass Multiple Responses from one request into another request one at a timeSOAPUI - 如何一次将多个响应从一个请求传递到另一个请求
【发布时间】:2017-09-04 17:18:37
【问题描述】:

我对 SOAPUI 和自动化测试比较陌生:

我基本上是在尝试从一个 SOAPUI 响应中获取结果并将它们解析到另一个,这本身就很简单,但是我在第一个请求中有多个响应,需要解析并一个一个地运行它们到第二个。

请求一的响应:

 <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"      xmlns:a="http://www.w3.org/2005/08/addressing">
   <s:Header>
      <a:Action s:mustUnderstand="1">http://tempuri.org/IWebServices/GetListOfChangedCommunicationsResponse</a:Action>
   </s:Header>
   <s:Body>
      <GetListOfChangedCommunicationsResponse xmlns="http://tempuri.org/">
         <GetListOfChangedCommunicationsResult xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <b:long>8888633</b:long>
            <b:long>8888635</b:long>
            <b:long>8888637</b:long>
            <b:long>8888641</b:long>
         </GetListOfChangedCommunicationsResult>
         <CommunicationsIssue xmlns:b="http://schemas.datacontract.org/2004/07/International.CD.Entity" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <b:DigiCommErrors i:nil="true"/>
            <b:Errors/>
            <b:Warnings i:nil="true"/>
         </CommunicationsIssue>
      </GetListOfChangedCommunicationsResponse>
   </s:Body>
</s:Envelope>



I need to take those 4 responses <b:long> and pass them into this 2nd method 1 at a time replacing <tem:ReferenceNumber> each time as this method only allows individual requests

请求二:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
   <soap:Header/>
   <soap:Body>
      <tem:GetCommunicationItem>
         <!--Optional:-->
         <tem:ReferenceNumber>${#TestCase#REF_ID}</tem:ReferenceNumber>
         <!--Optional:-->
         <!--tem:BarCode>?</tem:BarCode-->
      </tem:GetCommunicationItem>
   </soap:Body>
</soap:Envelope>

在 SOAPUI 中完成此任务的最佳过程是什么?

【问题讨论】:

  • 您是否需要在以下请求中包含所有 4 个项目以及 4 个 ReferenceNumber 元素?
  • 第一种方法中的 4 个 响应将用作第二种方法中 的输入。第二种方法只允许单个条目,所以我需要使用每个不同的响应运行/循环第二种方法 4 次。但并不总是 4 次迭代,第一次响应可能会产生或多或少的结果
  • 在单个请求调用中(不是 4 次),对吧?
  • 抱歉,我更新了最初的回复!
  • 嗯,很抱歉,但回答您的问题 - 第二个请求需要运行 4 次(或有多少个响应),每次输入与第一个响应不同跨度>

标签: soapui


【解决方案1】:

假设 SoapUI 测试用例有两个步骤。

说:

  • Step1 :此响应有多个值,对于每个值运行 Step2
  • Step2 :请求需要来自先前响应的值

方法如下:

  • 禁用Step2
  • &lt;tem:ReferenceNumber&gt;204237800&lt;/tem:ReferenceNumber&gt; 更改为&lt;tem:ReferenceNumber&gt;${#TestCase#REF_ID}&lt;/tem:ReferenceNumber&gt;。因此,无论何时运行 step2,它都会从测试用例级别的自定义属性中获取值,并且该值由用户在执行 Step2 之前存储在 Script Assertion 中。
  • Script Assertion 添加到Step1
  • 脚本需要读取响应,解析它,提取值long 元素。
  • 对于每个 long 元素值,将其设置为测试用例级别的自定义属性,例如 REF_ID 并从此脚本本身执行 Step2
  • Script Assertion 完成时,Step2 得到了多次执行Step1 的响应值。因此,不需要再次执行Step2,因此一开始就要求禁用。

这是第 1 步的脚本断言:

//Provide / change the name of the test step of Step2
def nextStep = 'Step2'

assert context.response, 'Response is null or empty'
def ids = new XmlSlurper().parseText(context.response).​'**'.findAll{it.name() == 'long'}*.text()
log.info ids

assert ids, 'Did not get any values from this response'

def stepToRun = context.testCase.testSteps[nextStep]
ids.each { id ->
   log.info "Running $nextStep step for value $id"
   context.testCase.setPropertyValue('REF_ID', id.toString())
   def runner = stepToRun.run(context.testRunner, context)
}

【讨论】:

  • 尝试测试脚本断言我收到以下错误 - 启动失败:Script31.groovy: 15: expecting nothing but ''\n'';无论如何@第 15 行第 62 列. ... : ${runner.hasResponse()" ^
  • @PhilH,感谢您尝试并让我知道错误,刚刚在上面的答案中修复了它。
  • 谢谢,是的,这解决了最初的问题,但现在我得到以下内容......没有方法签名:java.lang.String .name() 适用于参数类型:() 值:[] 可能的解决方案:take(int)、any()、any(groovy.lang.Closure)、wait()、next()、dump().. ......我知道问题出在...... it.name()......我尝试了几个建议的解决方案,但我不相信我的行动是正确的因为我得到了非常相似的结果
  • step1的响应有变化吗?即,与问题中出现的不一样?
  • 取决于您的意思 - 响应的数量有所不同,例如88886338888635 但我还删除了一些标题和其他信息,只显示我想从中找到结果的部分 -您需要完整回复吗?
【解决方案2】:

通过将线路分成单独的部分来尝试调试出错的地方,设法使其工作:

def ids = new XmlSlurper().parseText(context.response).​'**'.findAll{it.name() == 'long'}*.text

以下是我目前使用的基于@Rau 答案的脚本。如果我的更改一定是最好的方法,则不使用,但它对我有用

def nextStep = 'CommItem'
assert context.response, 'Response is null or empty'
def content = context.expand('${ChangedComms#Response}')
def xml = new XmlSlurper().parseText(content)
def ids =xml.depthFirst().findAll{it.name() == 'long'}*.text()
ids.each {
    log.info ids
    }
assert ids, 'Did not get any values from this response'

def stepToRun = context.testCase.testSteps[nextStep]
ids.each { id ->
    log.info "Running $nextStep step for value $id"
    context.testCase.setPropertyValue('REF_ID', id.toString())
    def runner = stepToRun.run(context.testRunner, context)
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-18
    • 2016-05-12
    • 1970-01-01
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    相关资源
    最近更新 更多