How to download a file from ReadyAPi using groovy script
Is there a way from Ready APi to download a file using groovy script, and place it in my local directory?
ie., when i hit a URL the excel file download automatically when it get downloads it must get stored into my local directory path. and to download the file authorization is required, so how to pass the authorization?
Thanks in Advance.
Solved! Go to Solution.
Yes i have assigned the value for the custom property and now i am getting the response as.
"message" : "You must specify only one folder in the url for POST requests."
Thank for trying.
But you should try it out on your own instead of just try what is mentioned.
From the error message it is clear that what you are hitting is not a file url, instead a directory.
Your question is to download a file. Isn't it?
Even you could try the your in your browser. And see.
Automation is important, but priority is to understand how things work manually and find the right way to achieve and then think of automating it. Thank you.
Thanks for the update, When i try manually hitting the url in browser, it downloads the excel file under downloads folder. i have already tried this manually before.
So, Please let me know whether we can achieve it using readyAPi?
I am member like you, explore the problems, see what works and suggest some solutions as part of that in spare time.
You may feel free to check with SmartBear customer support.
Just a quick update. From your description what youre asking is entirely achievable in ReadyAPI!.
It appears that the dynamically generated URL you are building differs from the URL you are submitting in the browser.
1. Grab the URL you are submitting in the browser, plug it into a url decoder to remove the percent encoding (via https://www.url-encode-decode.com)
2. Submit the request in ReadyAPI!, go to the RAW tab and grab the URL that is generated. Plug this into the html encoder/decoder and decode to remove the percent encoding
3. Compare the browser URL which works against the one submitted in ReadyAPI! and tske note of the differences.
4. Update the config in ReadyAPI! so that the dynamically generated URL matches the format/pattern of the browser URL
By the way, I can see the file downloaded in the temp directory(check attachments tab below response editor) when this is tried.
Note, Download Resources checkbox ticked.
Explore what you are doing differently.
Thanks for the Information, I done get with the dynamic URL, with the HTTP method, Now i am getting the raw response as below, but i am not seeing any attachments tab under response, I am not sure where the file got downloaded. Do you have any idea where the file got downloaded?
and i dont see any difference the url which i am posting in the browser and the dynamic url. only thing before i was doing POST request. for HTTP Request
HTTP/1.1 200 OK
Date: Mon, 01 Jun 2020 05:34:41 GMT
Content-Disposition: attachment; filename=testing_AutoAPI_Dev_7505_20200601.xlsm
Last-Modified: Mon, 01 Jun 2020 05:24:47 GMT
Cache-Control: public, max-age=43200
Expires: Mon, 01 Jun 2020 17:34:41 GMT
Ive never tested response attachments before, but ive a couple of points to raise that might help.
Firstly without any readyapi! config overriding the operating system id expect a file to be written to your usr profile somewhere or at least a temp directory.
Im not in front of my laptop right now to check but have you had a look in the Preferences to see if you have a default download directory set?
Have you tried searching your hard drive for the filename or part of the filename?
This leads me onto my next point. Is the file coming in as an attachment on the response OR is it actually embedded within the response as a payload? Reason i ask is that you state the attachments tab isnt available on your response and also your screenshot appears to display encoded data. If you cant find a file on your harddrive id suspect (considering your screenshot) that perhaps the response doesnt have an attachment.
Once im back in front of my laptop i'll have a quick google and look in my readyapi! settings and update this response but in the meantime can you check your settings and if file exists on you harddrive
Thanks for the detailed explanation, I have already checked whether the file is available in my local directory with the name, but i haven't found any file with the name and i have checked the preferences also there is no directory mentioned.
- « Previous
- Next »
- « Previous
- Next »