SoapUI 循环测试用例并记录测试用例自定义 属性
SoapUI Loop through TestCases and log test case custom property
我有一个 groovy 脚本,它循环遍历项目中每个测试用例、每个测试套件中的每个测试步骤。项目中的每个测试用例都分配了两个自定义属性,Test_Case_Response_Time
和 Test_Case_Response_Size
。我试图得到它,以便当它循环遍历每个测试用例时,它 log.info 每个测试用例的那两个自定义 属性 。
Groovy 脚本:
//Loop thru the suites, followed by cases in each suite
suites.each
{ suite ->
//For each test SUITE perform the following action
//------------------------------------------------
def tSuite = project.getTestSuiteByName(suite)
tSuite.testCaseList.each
{ kase ->
//For each test CASE perform the following action
//-----------------------------------------------
kase.testStepList.each
{
//For each test step perform the following action
//-----------------------------------------------
if(it.metaClass.hasProperty(it,'assertionStatus')){
def assertions = it.getAssertionList()
assertions.each
{ assertion ->
if(it.assertionStatus == AssertionStatus.VALID)
{
PassedTestCase += 1
}
else if(it.assertionStatus == AssertionStatus.FAILED)
{
FailedTestCase += 1
}
}
}
//-----------------------------------------------
}
log.info testRunner.testCase["Test_Case_00: Setup"].getPropertyValue("Test_Case_Response_Time")
log.info testRunner.testCase.testSuite.getTestCaseByName("Test_Case_00: Setup").getPropertyValue("Test_Case_Response_Time")
//-----------------------------------------------
}
//-----------------------------------------------
}
我尝试了以下但没有成功:
log.info testRunner.testCase[kase.name].getPropertyValue("Test_Case_Response_Time")
log.info testRunner.testCase.testSuite.getTestCaseByName(kase.name).getPropertyValue("Test_Case_Response_Time")
第一行给我以下内容
groovy.lang.MissingPropertyException: No such property: Test_Case_00:
Setup for class: com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase
error at line: 37
第二行出现以下错误:
java.lang.NullPointerException: Cannot invoke method
getPropertyValue() on null object error at line:37
下面的陈述是不正确的,因为 testCase[kase.name] 给你 属性 个测试用例而不是测试用例本身
系统正在尝试搜索名称为 "Test_Case_00: Setup" 的 属性,因此出现错误 "No such property: Test_Case_00: Setup"
log.info testRunner.testCase[kase.name].getPropertyValue("Test_Case_Response_Time")
我能够 运行 下面的代码
log.info testRunner.testCase.testSuite.getTestCaseByName(kase.name).getPropertyValue("Test_Case_Response_Time")
在您的实际代码中,您使用了以下行而不是 kase.name
getTestCaseByName("**Test_Case_00: Setup**")
貌似,testcase名称有误,请复制准确的名称并粘贴即可。
下面的代码对我有用。它只是您的代码。
def tSuite = testRunner.testCase.testSuite.project.getTestSuiteByName("TestSuite") // modified to run
tSuite.testCaseList.each
{ kase ->
//For each test CASE perform the following action
//-----------------------------------------------
kase.testStepList.each
{
//For each test step perform the following action
//-----------------------------------------------
}
//-----------------------------------------------
// log.info kase.name
// log.info testRunner.testCase[kase.name].getPropertyValue("Test_Case_Response_Time") <-- wrong syntax
log.info testRunner.testCase.testSuite.getTestCaseByName(kase.name).getPropertyValue("Test_Case_Response_Time")
}
我相信我找错了测试套件。使用以下我能够找到正确的属性:
testRunner.testCase.testSuite.project.getTestSuiteByName(suite).getTestCaseByName(kase.name).getPropertyValue("Test_Case_Response_Time")
我有一个 groovy 脚本,它循环遍历项目中每个测试用例、每个测试套件中的每个测试步骤。项目中的每个测试用例都分配了两个自定义属性,Test_Case_Response_Time
和 Test_Case_Response_Size
。我试图得到它,以便当它循环遍历每个测试用例时,它 log.info 每个测试用例的那两个自定义 属性 。
Groovy 脚本:
//Loop thru the suites, followed by cases in each suite
suites.each
{ suite ->
//For each test SUITE perform the following action
//------------------------------------------------
def tSuite = project.getTestSuiteByName(suite)
tSuite.testCaseList.each
{ kase ->
//For each test CASE perform the following action
//-----------------------------------------------
kase.testStepList.each
{
//For each test step perform the following action
//-----------------------------------------------
if(it.metaClass.hasProperty(it,'assertionStatus')){
def assertions = it.getAssertionList()
assertions.each
{ assertion ->
if(it.assertionStatus == AssertionStatus.VALID)
{
PassedTestCase += 1
}
else if(it.assertionStatus == AssertionStatus.FAILED)
{
FailedTestCase += 1
}
}
}
//-----------------------------------------------
}
log.info testRunner.testCase["Test_Case_00: Setup"].getPropertyValue("Test_Case_Response_Time")
log.info testRunner.testCase.testSuite.getTestCaseByName("Test_Case_00: Setup").getPropertyValue("Test_Case_Response_Time")
//-----------------------------------------------
}
//-----------------------------------------------
}
我尝试了以下但没有成功:
log.info testRunner.testCase[kase.name].getPropertyValue("Test_Case_Response_Time")
log.info testRunner.testCase.testSuite.getTestCaseByName(kase.name).getPropertyValue("Test_Case_Response_Time")
第一行给我以下内容
groovy.lang.MissingPropertyException: No such property: Test_Case_00: Setup for class: com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase error at line: 37
第二行出现以下错误:
java.lang.NullPointerException: Cannot invoke method getPropertyValue() on null object error at line:37
下面的陈述是不正确的,因为 testCase[kase.name] 给你 属性 个测试用例而不是测试用例本身
系统正在尝试搜索名称为 "Test_Case_00: Setup" 的 属性,因此出现错误 "No such property: Test_Case_00: Setup"
log.info testRunner.testCase[kase.name].getPropertyValue("Test_Case_Response_Time")
我能够 运行 下面的代码
log.info testRunner.testCase.testSuite.getTestCaseByName(kase.name).getPropertyValue("Test_Case_Response_Time")
在您的实际代码中,您使用了以下行而不是 kase.name
getTestCaseByName("**Test_Case_00: Setup**")
貌似,testcase名称有误,请复制准确的名称并粘贴即可。
下面的代码对我有用。它只是您的代码。
def tSuite = testRunner.testCase.testSuite.project.getTestSuiteByName("TestSuite") // modified to run
tSuite.testCaseList.each
{ kase ->
//For each test CASE perform the following action
//-----------------------------------------------
kase.testStepList.each
{
//For each test step perform the following action
//-----------------------------------------------
}
//-----------------------------------------------
// log.info kase.name
// log.info testRunner.testCase[kase.name].getPropertyValue("Test_Case_Response_Time") <-- wrong syntax
log.info testRunner.testCase.testSuite.getTestCaseByName(kase.name).getPropertyValue("Test_Case_Response_Time")
}
我相信我找错了测试套件。使用以下我能够找到正确的属性:
testRunner.testCase.testSuite.project.getTestSuiteByName(suite).getTestCaseByName(kase.name).getPropertyValue("Test_Case_Response_Time")