Forum Discussion

NareshNayini's avatar
NareshNayini
Occasional Contributor
12 years ago

How to load a request from xml file using groovy script?

Hi,

We found that request can be replaced with a sample xml file configured as per our requirement using the below process:

Go to XML tab in the request window -> right click -> "Load from" -> browsing the required xml.

But what my requirement is, how can we do this automatically using script?

Thanks in advance,

Naresh Nayini

4 Replies

  • priyanshu's avatar
    priyanshu
    Occasional Contributor
    Yes you can do it in following steps:
    1.On test case level,go to setup script and write the code to load the data in custom property of test case level e.g.

    def myRequest=new File("Location of Your xml file").getText()
    testRunner.testCase.setPropertyValue( "Request", myRequest )

    2.Use a transfer property step to transfer the this data into your required step.You can transfer the complete data into request section of step.There is no need of selecting xpath in propety transfer.
    • Ashvne's avatar
      Ashvne
      New Contributor

      Thanks for the answer .Can you please show it in the code how to load a xml file from folder in soap ui using groovy scripting.

      Thanks in advance

      • ChrisA's avatar
        ChrisA
        Contributor

        Hi,

         

        Is this related to the question posted on StackOverflow recently? how-to-copy-a-request-in-soapui-to-a-folder-using-groovy/46542756#46542756

         

        I answered something similar to this on StackOverflow recently....

         

        The below flow is an example of writing the request to a file and then pulling it back in to another request.

         

        Step 1 - Some REST request

        Step 2 - Copy the Raw Request value from Step 1 to file

        Step 3 - Load the Raw Request from file

        Step 4 - Run REST Request with payload form file

         

         

         

        Contents of 'Request Copy - Groovy Script'

        def rawRequest = context.expand( '${REST Test Request#RawRequest}' )
        
        def file1 = new File('c:/temp/groovy1.txt');file1.write (rawRequest);
        return rawRequest;

         

        Contents of 'Load Saved Request from File - Groovy Script'.  All this does is 'return' a string.

        def file1 = new File('c:/temp/groovy1.txt');
        
        return file1.text;

         

        In the final step, I deleted the existing payload in the request section and added a call to the load Groovy script.

         

         

         

        Chris