2013-03-27 92 views
0

我期待在現有的SoapUI項目中自動創建測試步驟。每個測試步驟都從記錄在單個文件中的SOAP請求中加載。每個測試步驟可以具有相同的斷言,從另一個測試步驟複製。如何以編程方式在SoapUI中創建測試步驟?

我想我可以在安裝腳本中使用Groovy。我還有其他選擇嗎?

回答

1

有很多不同的測試步驟。對於常規測試步驟,你可以試試這個:

public String createGroovyScriptTestStep() { 
    try { 
     String projectName = "C:\\YourProjectName.xml"; 
     File projectFile = new File(projectName); 
     WsdlProjectPro project = new WsdlProjectPro(projectName); 

     if (!projectFile.exists()) { 
      return "no_project_already_exists"; 
     } 

     WsdlTestSuite testSuite = project 
       .getTestSuiteByName("TestSuiteName"); 

     if (testSuite == null) { 
      return "testsuite does not exist"; 
     } else { 
      WsdlTestCase testCase = testSuite 
        .getTestCaseByName("TestCaseName"); 

      if (testCase == null) { 
       return "testcase does not exist"; 
      } else { 

       if (testCase.getTestStepByName("StepName") != null) { 

        return "teststep_already_exists"; 
       } 

       WsdlGroovyScriptTestStep testStep = (WsdlGroovyScriptTestStep) testCase 
         .addTestStep(GroovyScriptStepFactory.GROOVY_TYPE, 
           "StepName"); 

       testStep.setDescription("Description"); 
       testStep.setScript("System.out.println('Hi')"); 

       project.saveIn(projectFile); 

       return "teststep_successfully_created"; 
      } 
     } 
    } catch (Exception ex) { 
     ex.printStackTrace(); 
    } 
} 

你需要以下Maven依賴條件:

<dependency> 
     <groupId>com.github.redfish4ktc.soapui</groupId> 
     <artifactId>maven-soapui-extension-plugin</artifactId> 
     <version>4.6.4.1</version> 
    </dependency> 
    <dependency> 
     <groupId>com.fifesoft</groupId> 
     <artifactId>rsyntaxtextarea</artifactId> 
     <version>1.4.1</version> 
    </dependency> 
相關問題