Reputation: 115
I'm using robot framework to send requests without opening a browser. One of the requests is supposed to download a file. But when I send this request the file is not downloaded (even if I have a 200 status code).
${uri} set variable /api/pricing/ExportImportParams/downloadExportParams
Create Session test ${url} cookies=&{cookies}
${resp}= Get Request test ${uri} headers=&{headers}
${resp_code} = Set Variable ${resp.status_code}
${resp_code} = Convert To String ${resp_code}
Run Keyword And Continue On Failure Should be Equal ${resp_code} 200
The test is passed while the status code is 200. But no file is downloaded
Here is the response Headers
content-disposition: attachment; filename="Export Site Parameter_2020-01-03_09-21-39.xlsx"; filename*=UTF-8''Export%20Site%20Parameter_2020-01-03_09-21-39.xlsx content-length: 3767 content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet date: Fri, 03 Jan 2020 09:21:38 GMT server: Kestrel x-powered-by: ASP.NET
Thanks for helping
Upvotes: 1
Views: 3746
Reputation: 6961
Making an assumption that you are using the RequestsLibrary
to perform the HTTP Get request to retrieve the file. Althought the documentation does not specify it, the content
attribute of the returned response object contains the data. This can then be easily stored in a file using the standard OperatingSystem
library.
*** Settings ***
Library RequestsLibrary
Library OperatingSystem
*** Test Cases ***
File Download Using RequestsLibrary
${file_name} Set Variable file_example_XLS_10.xls
${uri} Set Variable /wp-content/uploads/2017/02/${file_name}
Create Session test https://file-examples.com
${response}= Get Request test ${uri}
Run Keyword And Continue On Failure Should Be Equal As Numbers ${response.status_code} 200
Create Binary File ${EXECDIR}/${file_name} ${response.content}
Upvotes: 2