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

SOLVED
ZP
Occasional 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.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

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

Hi @ZP,

 

The Media Type of the request matters - it should be `application/xml`. 

 

On my side, your scenario with a sample Petstore project works fine. My project and a video showing how I run it are attached.

 

Let me know if this helps.

Natalie
Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
9 REPLIES 9
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
Occasional 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

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
Occasional 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
Occasional Contributor

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

Any solution to this problem?

Highlighted
Moderator

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

Hi @ZP,

 

The Media Type of the request matters - it should be `application/xml`. 

 

On my side, your scenario with a sample Petstore project works fine. My project and a video showing how I run it are attached.

 

Let me know if this helps.

Natalie
Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Community Hero

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

Hi @NBorovykh 

 

Natalie - I need to apologise - I've been stuck in bed for a week and a half and never got around to what I intended.  what i understood the problem to be was that the fileContents property (which was the property on the datasource step) wasn't being picked up correctly - so nothing was getting passed to the REST step - whether the Mediatype is correct or would just mean the endpoint ZP was posting to would just respond with a 400 due to a bad request - but he never said that - he said the property wasn't being passed to the REST step.

 

Im back in work for the first time today - once I get home - I'll create a working project (using XML) for @ZP to copy.

 

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
Occasional Contributor

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

That's all good now. Solution has worked. I found that on my directory step i had the slashes the wrong way. It is working fine now...

New Here?
Join us and watch the welcome video:
Join the exciting event
SeptemberHubBub
Top Kudoed Authors
Join the September Hub-bub to show off, learn and win