JKal
JKal

Reputation: 21

Testing REST API using Robot Framework. Can't upload a CSV File and data via POST request

I am very new to testing / developing. I am currently testing a REST API. In Postman I send a POST request by specifying parameters and uploading a .csv file using form-data in the body. My request always succeeds. However, when I try to translate this into Robot Framework (using the Requests Library), I get a 400 Error.

I am posting my code below.

I have been trying to resolve this issue for a while now. Any help in the right direction would be much appreciated!

  Create Session  Alias  http://{{HOST}}{{PORT}}

  ${data}  Create Dictionary   inputFileTypeId=1  dataType=csv 

  Set to Dictionary   ${data}

  ${file_data}  Get Binary File  ${CURDIR}${/}File1.csv

  ${files}  Create Dictionary  file  ${file_data}

  Log  ${files}

  Log  ${data}

  ${resp}  RequestsLibrary.Post Request  ALias  /URI  files=${files}  data=${data}

  Log  ${resp}


  Should Be Equal As Strings  ${resp.status_code}  200

Upvotes: 1

Views: 2232

Answers (1)

JKal
JKal

Reputation: 21

Create Session  Alias  http://{{HOST}}{{PORT}}

${data}  Create Dictionary   inputFileTypeId=1  dataType=csv 

Set to Dictionary   ${data}

${file_data}  Get Binary File  ${CURDIR}${/}File1.csv

${files}  Create Dictionary  File1.csv  ${file_data}

Log  ${files}

Log  ${data}

${resp}  RequestsLibrary.Post Request  ALias  /URI  files=${files}  data=${data}

Log  ${resp}

Should Be Equal As Strings  ${resp.status_code}  200

Upvotes: 1

Related Questions