cancel
Showing results for 
Search instead for 
Did you mean: 

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

ZP
New Contributor

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.

 

 

 

 

6 REPLIES 6
Community Hero

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

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
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
Community Hero

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

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

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
ZP
New Contributor

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

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

Highlighted
Community Hero

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

Ok,

I can see why your REST step isn't picking up the fileContents property.

The parameter value in the content of your request should be ${datasourcestepname#fileContentsproperty} you used my example of 'datasource - directory', but i only use that in the example cos my datasource teststep was called 'datasource - directory'

Make sense?

Cheers,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
ZP
New Contributor

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

In my example it should be as below which i am picking up from right click>>Getdata so its automatic. I am not changing the names or anything and i have tried test again. It is failing with the same exact errors i have posted previously. Does the value of Media Type down matter? I have tried with multiple dorp downs though.

 

${DataSource#fileContents}

ZP
New Contributor

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

Any solution to this problem?

New Here?
Join us and watch the welcome video:
Watch the New Interview
APITestingMistake#2
Top Kudoed Authors