【发布时间】:2016-11-03 19:09:18
【问题描述】:
我正在 SoapUI 中创建一个测试项目,需要执行以下操作:
- 我有一个带有 1 个测试用例的“令牌”测试套件,其中包含:为 3 种不同类型的用户(查看者、管理员、编辑器)生成令牌的 3 个步骤,然后是一个采用令牌标头的 Groovy 脚本测试步骤和将其添加到套件的所有测试用例中。
- 对于某些测试,我想在测试步骤中添加额外的标头,但我不想删除已分配的令牌标头。
我创建了这个脚本:
import groovy.json.JsonSlurper;
import com.eviware.soapui.support.types.StringToStringMap;
//Get through all the test steps in the project
testRunner.testCase.testSuite.project.testSuites.each {
suite ->
suite.getValue().testCases.each {
q1 ->
q1.getValue().testSteps.each {
it ->
if (it.getValue().config.type.equals("restrequest")) {
//Get the headers of the current teststep
def headers = it.getValue().getHttpRequest().getRequestHeaders()
//Append the new header to the existing list
headers.put("Header A", "Value A");
headers.put("Header B", "Value B");
headers.put("Header C", "Value C");
//Set the updated header list
it.getValue().getHttpRequest().setRequestHeaders(headers)
}
}
}
}
此脚本将标头更新为我想要的所有测试用例,但还将标头添加到“令牌”测试套件并破坏它。
我想添加一个“IF”语句来检查:如果测试套件名称不包含“令牌”,则向其添加额外的标头。如果它包含“令牌”,请保持原样。我在项目中首先拥有令牌测试套件,因此当自动调用它时(通过 Bamboo),它会生成令牌,从而生成其余测试用例的标题。
我尝试了一些方法,但我的 Groovy 技能很业余,总是会出错。您能提出解决方案吗?
感谢您的宝贵时间。
【问题讨论】:
标签: groovy http-headers soapui