如何使用Groovy在所有测试用例中启用/禁用特定断言?
我有一套在soapui中运行回归测试用例的套件。它有一个断言如何使用Groovy在所有测试用例中启用/禁用特定断言?,groovy,soapui,Groovy,Soapui,我有一套在soapui中运行回归测试用例的套件。它有一个断言Capture Response,用于测量每个请求的时间。这是需要的 如果需要度量,那么我需要启用捕获响应时间断言,如果不需要,那么我不需要捕获响应时间 我写了下面的代码来检查它是否被禁用。如果它被禁用,那么确定,否则我需要禁用它 下面的代码返回 java.lang.NullPointerException:无法获取null对象上的属性“disabled” 有人能帮忙吗 def project = testRunner.getTestC
Capture Response
,用于测量每个请求的时间。这是需要的
如果需要度量,那么我需要启用捕获响应时间断言,如果不需要,那么我不需要捕获响应时间
我写了下面的代码来检查它是否被禁用。如果它被禁用,那么确定,否则我需要禁用它
下面的代码返回
java.lang.NullPointerException:无法获取null对象上的属性“disabled”
有人能帮忙吗
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
另一项输入:
要获取项目
,请不要使用工作区
而是使用:
def project = context.testCase.testSuite.project
下面的语句导致
NullPointerException
:
log.info(testStep.getAssertionByName("CaptureResponseTime").disabled)
为了避免NPE,请将其更改为:
log.info(testStep.getAssertionByName("CaptureResponseTime").isDisabled)
如果需要禁用断言,请使用以下语句:
testStep.getAssertionByName("CaptureResponseTime")?.disabled = true
另一项输入:
要获取项目
,请不要使用工作区
而是使用:
def project = context.testCase.testSuite.project
长安,你有机会试试这个解决方案吗?试过了,效果很好长安,你有机会试试这个解决方案吗?试过了,效果很好。。