调用/集成SoapUI到自动化回归测试项目

时间:2016-09-08 04:00:37

标签: java automation automated-tests integration-testing soapui

我们正在使用SoapUI来触发Web服务。 现在,我正在创建一个自动化回归测试项目(Java,Maven,Selenium Webdirver)。有许多测试套件需要SoapUI在测试的开始或中间发送Web服务请求。我想知道是否有一种方法可以导入SoapUI源代码或将SoapUI jar安装到我的项目中。所以我可以直接调用SoapUI函数或方法或类。 我已将这些依赖项添加到我的pom.xml中:

if highScoreDefault.valueForKey("Highscore") != nil {
        highScore = highScoreDefault.valueForKey("Highscore") as! NSInteger!
    }

if toSend > highScore
    {
        highScore = toSend
        highScoreDefault.setValue(highScore, forKey: "Highscore")
        highScoreDefault.synchronize()
    }

我还安装了SoapUI Intellij Idea插件。但似乎没有改变。 感谢您的帮助和建议。或者,如果有任何其他方法来实现此功能也会很棒。

2 个答案:

答案 0 :(得分:0)

从C:\ Program Files(x86)\ SmartBear \ SoapUI-5.2.1 \ lib和C:\ Program Files \ SmartBear \ SoapUI-5.2.1 \ bin导入所有soapUi jar和SoapUI.jar。

public void runTestCase(String tarSuite, String tarCase) throws Exception {

    String reportStr = "";

    SoapUI.setSoapUICore(new StandaloneSoapUICore(true));

    WsdlProject project = new WsdlProject("C:\\Users\\tshi\\Documents\\Maven Projects\\ASORT\\WebServiceResource\\Suncorp_Issuing-soapui-project.xml");

    List<TestSuite> suiteList = project.getTestSuiteList();

    for (TestSuite aSuiteList : suiteList) {

        String suiteName = aSuiteList.getName();

        List<TestCase> caseList = aSuiteList.getTestCaseList();
        //System.out.println("Test Suite: " + suiteName);

        if (suiteName.equals(tarSuite)) {

            for (TestCase aCaseList : caseList) {

                String caseName = aCaseList.getName();
                //System.out.println("Test Case: " + caseName);

                if (caseName.equals(tarCase)) {

                    long startTime = System.currentTimeMillis();

                    TestRunner runner = project.getTestSuiteByName(suiteName).getTestCaseByName(caseName).run(new PropertiesMap(), false);

                    long duration = System.currentTimeMillis() - startTime;

                    reportStr = reportStr + "\n\tTestCase: " + aCaseList.getName() + "\tStatus: " + runner.getStatus() + "\tReason: " + runner.getReason() + "\tDuration: " + duration;

                }

            }

        }

    }

    System.out.print(reportStr);

}

这可能不是实现目标的最佳方式。但它实际上适合我。欢迎所有设备。谢谢你们。

答案 1 :(得分:-1)

看来你试图通过maven运行soapUI。如果是这样,那么pom.xml应该包含soapui-maven-pluginpluginRepository。所以你的pom.xml应如下所示。它还包括maven-surefire-report-plugin以获取HTML类型报告。您必须更改<projectFile>sample-soapui-project.xml</projectFile> 以包含项目文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>mytest</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>mytest</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <pluginRepositories>
   <pluginRepository>
      <id>eviwarePluginRepository</id>
      <url>http://www.eviware.com/repository/maven2/</url>
   </pluginRepository>
</pluginRepositories>
<build>
<plugins>
  <plugin>
  <groupId>com.smartbear.soapui</groupId>
  <artifactId>soapui-maven-plugin</artifactId>
  <version>5.1.2-m-SNAPSHOT</version>
  <configuration>
    <!--soapUI project file location-->
    <projectFile>sample-soapui-project.xml</projectFile>
    <!--output file location-->
    <outputFolder>${project.basedir}/output/</outputFolder>
    <!--junit results file-->
    <junitReport>true</junitReport>
  </configuration>
  <executions>
    <execution>
      <id>soapUI</id>
      <phase>test</phase>
      <goals>
       <goal>test</goal>
      </goals>
    </execution>
  </executions>
  </plugin>
</plugins>
</build>
<reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.18.1</version>
      </plugin>
    </plugins>
  </reporting>
</project>