SOAPUI - 如何一次将多个响应从一个请求传递到另一个请求

SOAPUI - How can I Pass Multiple Responses from one request into another request one at a time

我对 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 中完成此操作的最佳流程是什么?

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

说:

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

方法如下:

  • 禁用Step2
  • <tem:ReferenceNumber>204237800</tem:ReferenceNumber> 更改为 <tem:ReferenceNumber>${#TestCase#REF_ID}</tem:ReferenceNumber>。因此,每当 step2 为 运行 时,它都会从测试用例级别自定义 属性 中获取值,并且该值在执行 Step2 之前由用户存储在脚本断言中。
  • 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)
}

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

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)
    }