我有一个普通的脚本,可以遍历项目中每个测试套件中每个测试案例中的每个测试步骤。项目中的每个测试用例都有两个自定义属性,分别是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:无此类属性:Test_Case_00: 类的设置:com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase 第37行出现错误
第二行给我以下错误:
java.lang.NullPointerException:无法调用方法 空对象错误的getPropertyValue()在第37行
答案 0 :(得分:0)
下面的陈述是不正确的,因为 testCase [kase.name] 为您提供了测试用例的属性,而不是测试用例本身
系统正在尝试搜索名称为“ Test_Case_00:安装程序”的属性,因此给出错误消息“无此类属性:Test_Case_00:安装程序”
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**")
测试用例名称错误,请复制确切的名称并粘贴即可。
以下代码对我有用。它仅是您的代码。
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")
}
答案 1 :(得分:0)
我相信我在寻找错误的测试套件。使用以下代码,我能够找到正确的属性:
testRunner.testCase.testSuite.project.getTestSuiteByName(suite).getTestCaseByName(kase.name).getPropertyValue("Test_Case_Response_Time")