Forum Discussion

ZP's avatar
ZP
Occasional Contributor
5 years ago
Solved

ReadyAPI - Dynamic POST using .xml files or using .csv file that are saved in the directory

I am using ReadyAPI (SOAPUI) POST method. 

 

I would like to POST content from an external file. 

 

1) In the media type drop down I select application/xml OR application/json

2) And in the area where we put the actual payload, I would like to use the external file path so that content of that extenral file can be read and gets Send via POST method. 

 

Is above achievable? 

 

I can see it can be done for SOAP requests as per - https://www.soapui.org/docs/data-driven-tests/using-files.html

 

BUT i am not sure if its possible to it for REST Request for POST method. I have been googling for days but can't find a solution so any help would be much appreciated. Basically my need is that i will have a bunch of XML payloads created at the given directory which i will need to send via POST method. I know how to make it data driven using DataSource/Loop but not sure if i can send POST request that exists as an external file. I hope i have explained the question correctly. Any further questions please let me know. 

 

Thanks for your help in advance.

 

 

 

 

  • Hi ZP,

    Yep this works for REST requests, but you won't include the 'path' to the file in the request, but if you're using a directory datasource (as ypu appear to describe) then each of your files will be loaded into a single property and within the request field you simply reference the datasource property. (e.g. something like '${#datasource#dataprop}', depending on the name of your datasource and property name)
    I'm driving at moment, but will answer properly with complete details once i get into work (unless someone else answers before then)

    Cheers,

    Rich

9 Replies

  • richie's avatar
    richie
    Community Hero
    Hi ZP,

    Yep this works for REST requests, but you won't include the 'path' to the file in the request, but if you're using a directory datasource (as ypu appear to describe) then each of your files will be loaded into a single property and within the request field you simply reference the datasource property. (e.g. something like '${#datasource#dataprop}', depending on the name of your datasource and property name)
    I'm driving at moment, but will answer properly with complete details once i get into work (unless someone else answers before then)

    Cheers,

    Rich
    • richie's avatar
      richie
      Community Hero

      Hi ZP,

       

      yep - so if you have you REST requests setup and you have a directory which contains your xml files.

       

      In your test, create a Datasource (directory type) call it e.g. 'Datasource - directory' and ensure you browse to the directory containing your .xml files.  Ensure the filename filter field is populated with the correct file extension (e.g. .xml I'm guessing).

      Create a new property and give it a name - e.g. 'fileContents'.

      Within your REST request (immediately below the 'MediaType' dropdown) input ${DatasourceStepName#PropertyName}  - so in the example I've used by value would be ${Datasource - directory#fileContents}

      Considering your directory has multiple files in it - you'll need to add a DatasourceLoop step after the REST request.

      1 thing that caught me out when I tried this originally - launch the Datasource step options and ensure the 'Rows per Iteration' setting is set to '1' - so it picks 1 file at a time - otherwise the test won't work correctly

       

      Cheers,

       

      rich

      • ZP's avatar
        ZP
        Occasional Contributor

        Thanks for your reply and sorry for late reply from my side. I kept on trying this few times but doesn't work. 

         

        I guess i am not setting up the Media Type correctly? I have tried setting up with text/xml as well as application/xml and none of them has worked. 

         

        I am seeing the attached error. I have attached few more screen shots shwoing you the test steps. I have also attached the actual XML screen shot 2. May be an XML issue or media type issue? Just dont know. Tried few different ways. 

         

        Simply posting the XML content as is works perfectly well. Only when using it via File/directory it fails. Refer to screen shot 4(capture_3) to see the success when tried normal way. 

         

         

        Your help much appreciated. 

         

        Thanks