Search code examples
soapuitest-suite

Include requests saved in file in soapUI project


I have a catalog with my soap requests and I want to reuse them for building a test suite. I tried using ENTITY definitions but couldn't make it work, while using xi:include for the piece of code I want to include seems soapUI doesn't recognize it.

My actual project has the following structure:

<con:soapui-project>

    <con:interface >
        <con:endpoints>
            <con:endpoint>http://localhost/GestionePreventiviRemoteImpl/GestionePreventiviService_v1</con:endpoint>
        </con:endpoints>

        <con:operation isOneWay="false" action="" name="aggiornaPreventivo" bindingOperationName="aggiornaPreventivo" >
            <con:settings/>
        </con:operation>

        <con:operation isOneWay="false" action="" name="creaPreventivo" bindingOperationName="creaPreventivo" >
            <con:settings/>
        </con:operation>

        <con:operation isOneWay="false" action="" name="recuperaPreventivo" bindingOperationName="recuperaPreventivo">
            <con:settings/>
        </con:operation>
    </con:interface>

    <con:testSuite name="GestioneServicePortBinding TestSuite">
        <con:testCase name="aggiornaPreventivo TestCase">
            <con:testStep name="aggiornaPreventivo">
                <con:config>
                    <con:interface>GestioneServicePortBinding</con:interface>
                    <con:operation>aggiornaPreventivo</con:operation>
                    <con:request name="aggiornaPreventivo">
                        <con:endpoint>http://localhost/GestionePreventiviRemoteImpl/GestionePreventiviService_v1</con:endpoint>

                        <con:request>
                            <![CDATA[
                            <?xml version="1.0" encoding="UTF-8"?>
                            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://simulatore.Prodotto.be.service.bmed.it/v1">
                               <soapenv:Header/>
                               <soapenv:Body>
                                  <v1:aggiornaPreventivo>
                                     <input>
                                        <aggiornaPreventivoDTO>
                                           <codPrev>1001</codPrev>
                                           <codCliente>205</codCliente>
                                           .....
                                        </aggiornaPreventivoDTO>
                                     </input>
                                  </v1:aggiornaPreventivo>
                               </soapenv:Body>
                            </soapenv:Envelope>
                            ]]>
                        </con:request>
                    </con:request>
                </con:config>
            </con:testStep>
        </con:testCase>
    </con:testSuite>

</con:soapui-project>

And what I need is to include the request in the test case in order to handle input parameters outside the testsuite. So something like:

<con:testStep name="aggiornaPreventivo">
    <con:config>
        <con:interface>GestioneServicePortBinding</con:interface>
        <con:operation>aggiornaPreventivo</con:operation>
        <con:request name="aggiornaPreventivo">
            <con:endpoint>http://localhost/GestionePreventiviRemoteImpl/GestionePreventiviService_v1</con:endpoint>
            <con:request>
                <xi:include href="aggiornaPreventivoRequest.xml" parse="xml" xpointer="title"/>
            </con:request>
        </con:request>
    </con:config>
</con:testStep>

Where aggiornaPreventivoRequest.xml has the content like:

<v1:aggiornaPreventivo>
    <input>
        <aggiornaPreventivoDTO>
           <codPrev>1001</codPrev>
           <codCliente>205</codCliente>
           .....
        </aggiornaPreventivoDTO>
    </input>
</v1:aggiornaPreventivo>

Thank you for any help!


Solution

  • I don't know if you can use <include> from http://www.w3.org/2001/XInclude in SOAPUI, however if you want to control the node values of your request outside the request itself you can use properties.

    You can add the properties on project, testSuite, testCase, testStep level and so on, to use it directly in your request you have to use the follow notation depends on the level where you define your properties. From SOAPUI documentation:

    ${#Project#yourProperty} - references a Project property(Reference properties across a particular SoapUI project)

    ${#TestSuite#yourProperty} - references a TestSuite property in the containing TestSuite

    ${#TestCase#yourProperty} - references a TestCase property in the containing TestCase

    ${TestStep name#yourProperty} - references a TestStep property

    For example if you add the property on the testSuite:

    <v1:aggiornaPreventivo>
        <input>
            <aggiornaPreventivoDTO>
               <codPrev>${#TestSuite#codPrevValue}</codPrev>
               <codCliente>${#TestSuite#codClienteValue}</codCliente>
               .....
            </aggiornaPreventivoDTO>
        </input>
    </v1:aggiornaPreventivo>
    

    If you don't know how to add properties to your project take a look at this.

    There is also another possibility if you're really interested to send a request from a local file you can also use a groovy testStep with the follow code to send a request from specific file location:

    import java.io.IOException;
    import java.io.FileInputStream;
    import org.apache.http.entity.FileEntity
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.ResponseHandler;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.BasicResponseHandler;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.params.DefaultedHttpParams;
    import org.apache.http.params.HttpParams;
    
    def httpclient = new DefaultHttpClient();
    // the directory with your xml requests
    def directory = new File("/tmp/myRequests/")
    // for each file in the directory
    directory.eachFile{ file -> 
        // create the request
        HttpPost post = new HttpPost("http://your_endpoint")
        def reqEntity = new FileEntity(file,"application/xml");
         post.setEntity(reqEntity)
        // make the post and get the response
        def responseHandler = new BasicResponseHandler()
        def responseBody = httpclient.execute(post, responseHandler)
        log.info responseBody
    };
    

    Hope this helps,