如何使用 Groovy 在所有测试用例中 Enable/Disable 特定断言?
How to Enable/Disable Particular Assertion in all Test Case using Groovy?
我有套件 运行 Soap 中的回归测试用例 UI。它有一个 Assertion Capture Response
来测量每个请求的时间。这是按需需要的。
如果需要指标,那么我需要启用捕获响应时间断言,如果不需要,那么我不需要捕获响应时间。
我写了下面的代码来检查它是否被禁用。如果它被禁用那么好的,否则我需要禁用它。
下面的代码returns
java.lang.NullPointerException: Cannot get property 'disabled' on null object.
有人可以帮忙吗?
def project = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName("Regression");
//Loop through each Test Suite in the project
for(suite in project.getTestSuiteList())
{
//log.info(suite.name)
//Loop through each Test Case
if(suite.name == "ReusableComponent")
{
for(tcase in suite.getTestCaseList())
{
log.info(tcase.name)
for(tstep in tcase.getTestStepList())
{
stepName = tstep.name
suiteName=suite.name
caseName=tcase.name
def testStep = testRunner.testCase.testSuite.project.testSuites["$suiteName"].testCases["$caseName"].getTestStepByName("$stepName")
log.info(testStep.getAssertionByName("CaptureResponseTime").disabled)
}
}
}
}
以下语句导致 NullPointerException
:
log.info(testStep.getAssertionByName("CaptureResponseTime").disabled)
为了避免NPE,则改为:
log.info(testStep.getAssertionByName("CaptureResponseTime").isDisabled)
如果您需要禁用断言,请使用以下语句:
testStep.getAssertionByName("CaptureResponseTime")?.disabled = true
另一个输入:
为了得到project
,不要使用workspace
。
改为使用:
def project = context.testCase.testSuite.project
我有套件 运行 Soap 中的回归测试用例 UI。它有一个 Assertion Capture Response
来测量每个请求的时间。这是按需需要的。
如果需要指标,那么我需要启用捕获响应时间断言,如果不需要,那么我不需要捕获响应时间。
我写了下面的代码来检查它是否被禁用。如果它被禁用那么好的,否则我需要禁用它。
下面的代码returns
java.lang.NullPointerException: Cannot get property 'disabled' on null object.
有人可以帮忙吗?
def project = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName("Regression");
//Loop through each Test Suite in the project
for(suite in project.getTestSuiteList())
{
//log.info(suite.name)
//Loop through each Test Case
if(suite.name == "ReusableComponent")
{
for(tcase in suite.getTestCaseList())
{
log.info(tcase.name)
for(tstep in tcase.getTestStepList())
{
stepName = tstep.name
suiteName=suite.name
caseName=tcase.name
def testStep = testRunner.testCase.testSuite.project.testSuites["$suiteName"].testCases["$caseName"].getTestStepByName("$stepName")
log.info(testStep.getAssertionByName("CaptureResponseTime").disabled)
}
}
}
}
以下语句导致 NullPointerException
:
log.info(testStep.getAssertionByName("CaptureResponseTime").disabled)
为了避免NPE,则改为:
log.info(testStep.getAssertionByName("CaptureResponseTime").isDisabled)
如果您需要禁用断言,请使用以下语句:
testStep.getAssertionByName("CaptureResponseTime")?.disabled = true
另一个输入:
为了得到project
,不要使用workspace
。
改为使用:
def project = context.testCase.testSuite.project