java - 如何使用 java 从 SOAPUI 测试用例中删除自定义属性?

标签 java soapui

我为 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 中应用 removeProperty,而不是在 WsdlTestRunContext 中。您可以将 testCase 循环代码更改为:

for(TestCase testCase : allTestCaseList) {
    List<TestProperty> testCasePropertyList = testCase.getPropertyList();
       for (TestProperty testProperty : testCasePropertyList) {
            ((WsdlTestCase) testCase).removeProperty(testProperty.getName());
        }
}

希望对你有帮助

关于java - 如何使用 java 从 SOAPUI 测试用例中删除自定义属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39220938/

相关文章:

java - 如何在 Joda-Time 中正确获取当前日期和时间?

java - 使用Instrumentation API时,JVM崩溃时EXCEPTION_ACCESS_VIOLATION

java - 为什么我收到 java.lang.NullPointerException 而不是 soap 响应?

SoapUI 中的 WCF wsHttpBinding

SSL 客户端 (soapUI) 未使用证书响应服务器 CertificateRequest

Java 内部类设计的好处

java - 使用 Groovy 动态更改 Java 应用程序的行为

java - 不支持的内容类型 : text/plain; charset=ISO-8859-1

javascript - Node.js 能否取代 java 作为 Web 应用程序中的服务器端技术

soap - 手动测试grpc接口(interface)