【问题标题】:SoapUI to read request parameters from a file ( free version)SoapUI 从文件中读取请求参数(免费版)
【发布时间】:2023-03-20 18:20:02
【问题描述】:

我有一个包含以下内容的文件

987656   
987534

我有一个 Groovy 脚本,作为测试前的测试步骤:

def myTestCase = context.testCase
new File("filepath/data1.txt").eachLine { line ->
  myTestCase.setPropertyValue("inputValue", line)
  inputValue = context.expand( '${#TestCase#inputValue}' )
  log.info inputValue
}

脚本的日志输出为我提供了文件中的两个值:

987656
987534

我有一个 Testcase 自定义属性设置为“inputValue”,在我的测试中我将参数称为

 <enr:Id>${#TestCase#inputValue}</enr:Id>

在执行期间,测试始终针对最后一个值“987534”运行,而不是针对两个输入。

我应该怎么做才能对文本文件中存在的所有值执行测试?

谢谢

【问题讨论】:

  • 这是意料之中的。因为,在脚本中它读取所有内容,最后一行值作为自定义属性。因此,您看到的结果。您必须改为为每个运行测试。

标签: groovy soapui


【解决方案1】:

像这样循环遍历值的方法是,在eachLine 循环中,调用 SOAP 步骤,如下所示:

def myTestCase = context.testCase
new File("filepath/data1.txt").eachLine { line ->
    myTestCase.setPropertyValue("inputValue", line)
    inputValue = context.expand( "${#TestCase#inputValue}" )
    log.info inputValue

    //define the step
    def soapTestStep = testRunner.testCase.getTestStepByName("YourSOAPRequestName").name
    
    //call the step
    testRunner.runTestStepByName(soapTestStep)

    //if you want to do something with the response XML
    def responseSOAP = context.expand("${YourSOAPRequestName#Response}")

    //if you want to check a value in the response XML
    def responseSection = responseSOAP =~ /someNode>(.*)<\/someNode/   
    def responseValue = responseSection[0][1]
    log.info "response: ${responseValue}"
}

【讨论】:

  • 谢谢@ou_ryperd。当我尝试上述方法时,对数据文件 987656、987534 中的两个值都执行了测试。但是测试运行了 3 个步骤,重复了最后一个值两次。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多