我本周开始使用Soapui,我做了一些测试,例如发送请求POST并将响应保存为文件夹中的txt文件。 我要做的是读取此txt文件,复制特定数据并将其存储在自定义属性中。 因为我想在嵌套请求POST中使用此对象,这取决于第一个请求。
我想在Groovy中做到这一点。 我只有开源SOAPUI版本5.0.0
谢谢
答案 0 :(得分:1)
您必须在测试用例中添加groovy
测试步骤,并像在java中一样,检查groovy documentation。
仅作为引用,SOAPUI 5.2.0具有groovy
2.1.7版本(check the dependency in pom.xml),因此在{000}运行在SOAPUI上的脚本中,您可以使用{标准包含在groovy
中{1}},SOAPUI类,其他一些groovy
2.1.7 API,另外您可以在jre
中包含其他jar,以便在SOAPUI\bin\ext
脚本中使用它们。
最后,您要求从文件中读取一些数据并将其写入自定义属性,例如,您可以按照以下方式执行此操作:
groovy
由于您的问题不明确,我向您展示了一个可能的示例,展示了如何读取文件以查找特定内容并将此内容保存在testCase中的自定义属性中。
请注意,在// read the file from path
def file = new File('/path/yourFile')
// for example read line by line
def yourData = file.eachLine { line ->
// check if the line contains your data
if(line.contains('mySpecifiyData=')){
return line
}
}
// put the line in a custom property in the testCase
testRunner.testCase.setPropertyValue('yourProp',yourData)
脚本中,您可以使用全局对象:groovy
,testRunner
和context
,在此示例中我使用log
要访问testRunner
及其属性,就像您可以认为testCase
访问testRunner
,testSuites
,project
等一样...查看文档: