Dave221
Dave221

Reputation: 47

How to Use the SoapUI API to Create a Test Suite, Test Cases, Test Steps, and Assertions

I need to create a SoapUI test suite and test cases programmatically using Java and the SoapUI API. I’m able to create the SoapUI project and import a WSDL into that project but I am having problems understanding which classes I use to create the test suite, test cases, test steps, and assertions. I’ve read the SoapUI API Javadoc, but are there sample code snippets and/or documentation I can use to learn which classes I would use and how to use those classes?

Upvotes: 1

Views: 6298

Answers (2)

lidox
lidox

Reputation: 1971

Following code generates your needs: I use the trial version of SoapUI Pro. You cannot use this in the free version, because you will have problems with the saveIn method: project.saveIn(projectFile); to generate the XML-file

/**
 * Creates a SoapUI-Project with a TestSuite and a TestCase for each operation the webservice provides
 * @param projectFileName The xml-file where to save the project
 * @param wsdlName for example: http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL
 * @param projectName The name of the project
 * @param suiteName The name of the TestSuite
 * @param caseName The prefix for the TestCase name
 * @param stepname The prefix for the TestStep name
 * @throws Exception
 */
public void createProject(String projectFileName, String wsdlName, String projectName, String suiteName, String caseName, String stepname) throws Exception{
    // create File
    File projectFile = new File(projectFileName);

    SoapUI.setSoapUICore(new StandaloneSoapUICore(true));
    WsdlProject project = new WsdlProject();
    project.setName(projectName);


    WsdlInterface wsdl = WsdlInterfaceFactory.importWsdl(project, wsdlName,true)[0];
    int c = wsdl.getOperationCount();
    WsdlTestSuite TS = project.addNewTestSuite(suiteName);
    TS.setName(suiteName);

    for (int i = 0; i < c; i++) {
        WsdlOperation operation = wsdl.getOperationAt(i);
        String opName = operation.getName();

        // Create new TestCase and the specified TestStep
        TestStepConfig testStepConfig = WsdlTestRequestStepFactory.createConfig(operation, caseName+opName);
        WsdlTestCase testCase = TS.addNewTestCase(caseName+opName);
        WsdlTestStep testStep = testCase.addTestStep(testStepConfig);
        testStep.setName(stepname+opName);



    }
    project.saveIn(projectFile);
}

You also need following maven pom.xml dependencies:

    <dependencies>
    <dependency>
        <groupId>eviware</groupId>
        <artifactId>maven-soapui-plugin</artifactId>
        <version>4.5.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>eviware</id>
        <url>http://www.eviware.com/repository/maven2/</url>
    </repository>
</repositories>

Upvotes: 1

olyv
olyv

Reputation: 3817

I would try to start from this http://www.soapui.org/Developers-Corner/integrating-with-soapui.html. But to be honest, I have to say that I used only SoapUI GUI.

Upvotes: 0

Related Questions