2

I want to send POST requests with the the request body (JSON ) from a .txt file. Each line in the .txt file is a JSON request and I want to send the request as is for each line.

Here is my feature file:

Scenario Outline: Read from txt * url blah blah Given request And header Content-Type = 'application/json' When method post Then status 201

Examples:
|Req|
|read('Requests.txt')|

Here is my sample .txt file

{"merch":"asf","name":"twin","currencyCode":"USD","amount":4000}
{"merch":"are","name":"pdf","currencyCode":"USD","amount":2500}

Could you please guide how I could accomplish this. I tried using .csv, but the entire JSON is not read in that case for each line. I am looking for a very simple way of sending the request one by one for each line in the .txt file.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
asasi
  • 31
  • 3

1 Answers1

0

Just write a one-time bit of Java code that loops over the lines and gives you a JSON array and then just use that. You may be even able to do it in JavaScript.

Also see this answer: https://stackoverflow.com/a/64393794/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248