如何使用 java 从 SOAPUI 测试用例中删除自定义属性?
How to remove custome properties from SOAPUI test case using java?
我为 SoapUI 中的所有测试用例设置了一些自定义属性。
我可以使用 Groovy 脚本步骤删除,如下面的问题所述:
How to remove Custom Properties from a SoapUI TestCase using Groovy?
testRunner.testCase.removeProperty( "Testcase_Property" );
但我想从 JAVA 中删除这些属性。下面是我写的代码:
String soapuiProjectPath = "ProjectLocation";
WsdlProject project = new WsdlProject(soapuiProjectPath);
StringToObjectMap context = new StringToObjectMap();
TestSuite testSuite = project.getTestSuiteByName("TestSuiteName");
WsdlTestSuite wsdlSuite = (WsdlTestSuite) testSuite;
List<TestCase> allTestCaseList = wsdlSuite.getTestCaseList();
for (TestCase testCase : allTestCaseList) {
WsdlTestCaseRunner testCaseRunner = new WsdlTestCaseRunner((WsdlTestCase) testCase, context);
List<TestProperty> testCasePropertyList = testCase.getPropertyList();
for (TestProperty testProperty : testCasePropertyList) {
WsdlTestRunContext runContext = testCaseRunner.getRunContext();
runContext.removeProperty(testProperty.getName());
}
}
System.out.println("Completed execution.");
project.save();
它没有抛出任何异常。但实际上并没有删除自定义属性。
因为您必须在 WsdlTestCase
而不是 WsdlTestRunContext
中应用 removeProperty
。您可以将 testCase 循环代码更改为:
for(TestCase testCase : allTestCaseList) {
List<TestProperty> testCasePropertyList = testCase.getPropertyList();
for (TestProperty testProperty : testCasePropertyList) {
((WsdlTestCase) testCase).removeProperty(testProperty.getName());
}
}
希望对您有所帮助,
我为 SoapUI 中的所有测试用例设置了一些自定义属性。
我可以使用 Groovy 脚本步骤删除,如下面的问题所述:
How to remove Custom Properties from a SoapUI TestCase using Groovy?
testRunner.testCase.removeProperty( "Testcase_Property" );
但我想从 JAVA 中删除这些属性。下面是我写的代码:
String soapuiProjectPath = "ProjectLocation";
WsdlProject project = new WsdlProject(soapuiProjectPath);
StringToObjectMap context = new StringToObjectMap();
TestSuite testSuite = project.getTestSuiteByName("TestSuiteName");
WsdlTestSuite wsdlSuite = (WsdlTestSuite) testSuite;
List<TestCase> allTestCaseList = wsdlSuite.getTestCaseList();
for (TestCase testCase : allTestCaseList) {
WsdlTestCaseRunner testCaseRunner = new WsdlTestCaseRunner((WsdlTestCase) testCase, context);
List<TestProperty> testCasePropertyList = testCase.getPropertyList();
for (TestProperty testProperty : testCasePropertyList) {
WsdlTestRunContext runContext = testCaseRunner.getRunContext();
runContext.removeProperty(testProperty.getName());
}
}
System.out.println("Completed execution.");
project.save();
它没有抛出任何异常。但实际上并没有删除自定义属性。
因为您必须在 WsdlTestCase
而不是 WsdlTestRunContext
中应用 removeProperty
。您可以将 testCase 循环代码更改为:
for(TestCase testCase : allTestCaseList) {
List<TestProperty> testCasePropertyList = testCase.getPropertyList();
for (TestProperty testProperty : testCasePropertyList) {
((WsdlTestCase) testCase).removeProperty(testProperty.getName());
}
}
希望对您有所帮助,