groovy - 通过 Groovy 脚本在 SoapUI 中进行自动数据驱动测试
问题描述
正如在soapUI免费版本中讨论的那样,我试图称这个WS:
<soap:Body>
<RequestParameters>
<Parameter name="key" value="SomeorderId"/>
</RequestParameters>
</soap:Body>
我想从我桌面上的本地 data.txt 文件中获取“key”的值。该文件的内容:
9999999991
9999999992
9999999993
为此,我创建了一个包含以下三个测试步骤的测试套件:
1.第一步:一个groovy脚本:
def data = new File('C:/Users/Polarick/Desktop/data.txt')
data.eachLine { orderId ->
context.orderId = orderId
//Get the step2, index of the step is 1
def step = context.testCase.getTestStepAt(1)
//Run the step2
step.run(testRunner, context)
}
//all the orders got executed,jump to step2, index is 2
testRunner.gotoStep(2)
2.第二步:修改请求:
<Parameter name="MSISDN" value="${orderId}"/>
并向其声明此脚本:
//Check if there is response
assert context.request, "Request is empty or null"
//Save the contents to a file
def saveToFile(file, content) {
if (!file.parentFile.exists()) {
file.parentFile.mkdirs()
log.info "Directory did not exist, created"
}
file.write(content)
assert file.exists(), "${file.name} not created"
}
def response = context.expand( '${Step2#Response}' )
def f = new File("C:/Users/Polarick/Desktop/${context.orderId}_Response.xml")
f.write(response, "UTF-8")
saveToFile(f, context.response)
3.第三步:一个groovy脚本:
log.info "Test completed."
一切正常,并按顺序为 data.txt 文件中存在的所有行调用 WS,但我希望每次执行都能找到一个响应 .xml 文件,例如:
C:/Users/Polarick/Desktop/9999999991_Response.xml
C:/Users/Polarick/Desktop/9999999992_Response.xml
C:/Users/Polarick/Desktop/9999999993_Response.xml
但是没有生成响应文件,你能帮忙吗?
解决方案
推荐阅读
- html - 带有包装 Flexbox 和滚动子对象的奇怪行为
- apache-spark - 我可以触发 Zeppelin 在命令中运行特定块吗?
- nativescript - 为什么 <TabContentItem> 中的 <Frame> 在 <Page> 中不起作用?实现 Tab 时使用 Frame 的问题
- c# - 如何在 WebView 中使用自定义字体(外部字体)作为 Xamarin Forms 中的嵌入式资源?
- mysql - 如何将具有多个值的对象添加到表中?
- python-3.x - pandas to_dict() 丢失时区信息
- python - 如何从 dlib 68 x-y 坐标测量面部地标中 2 个点之间的距离
- python - 如何知道深度学习模型中的过滤器数量并查看每个过滤器的输出?
- android - Firebase 身份验证使用自定义身份验证系统错误,“自定义令牌对应于不同的受众。”
- regex - 除了匹配的第一个字母之外,在正则表达式中捕获重复的字母