我使用 SOAPUI 免费版本。
我有 txt 文件,例如
1
2
3
我有测试步骤,第一次应该运行 1,第二次运行 2 等等...
问题:我可以以某种方式将 1、然后 2、然后 3 设置为属性文件的属性吗?
对于 xls 也有同样的问题,如果文本不合适......
最佳答案
我想您有一个名为“myRequest”的 SOAP 测试步骤,其中包含类似以下内容的内容:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<yourRequest>
<someValue>${#TestCase#myProperty}</someValue>
</yourRequest>
</soapenv:Body>
</soapenv:Envelope>
并且您希望从 groovy 运行此测试步骤的次数与文件中的行数一样多,并将其内容用作请求中的属性。
因此,在 groovy 脚本中,您可以使用类似以下内容的内容:
// define your file
def file = new File("C:/temp/yourFile.txt")
// for each line
file.eachLine { line ->
// put the property for your request
testRunner.testCase.setPropertyValue("myProperty",line)
// execute your request
testRunner.runTestStepByName( "myRequest")
log.info "execute request for line: " + line
}
您可以执行相同的操作,指定与 TestCase
不同的其他级别的属性(TestSuite
级别、Project
级别...)这只是一种可能的方法:)
。
您也可以从 .xls
执行此操作,但是您可能需要添加一些库来处理 .xls
(如 apache-poi)到 SOAPUI\bin
并更改一些常规代码的读取方式。我认为使用 .txt
您的目标很容易实现。
希望这有帮助,
关于groovy - SOAPUI:使用 txt 文件中的属性运行测试步骤,将属性设置为 txt 中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29164838/