2

Also, I need the json file path to be provided from root folder of the project for following code:

Feature: sample karate test script

Background:
* url 'http://somesample.com'

Scenario: Testing Karate

Given path '/json_verify'
And request read ('a_confirm1.json')
And header Accept = 'application/json'
When method post
Then status 200 

I have filenames like a_confirm1, a_confirm2 and so on.

Adrien
  • 1,080
  • 4
  • 14
AAK
  • 21
  • 2

1 Answers1

0

First, you can do this in the read() function because it is pure JS:

And def index = <index>
And request read ('a_confirm' + index + '.json')

Then please read up on data-driven testing: https://github.com/intuit/karate#data-driven-tests

Examples:
| index |
|     1 |
|     2 |

There are many other ways to do this, for e.g. using loops. Just go through the examples and demos. From "root folder" is a bad practice, try to keep them under your project directory. But if you insist, refer this: https://stackoverflow.com/a/53304969/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Hi Peter, Thanks for your response. I have 30 folders, each containing 100 JSON files (requests). My intention is to iterate over each of the folders and each of the files to get response for each one of them. Since, i am new to Javascript and Karate would you be able to suggest a good approach of achieving this? FYI, I have done this in JAVA and Rest-Assured but its too lengthy and code readability is less. – AAK Feb 01 '19 at 20:04
  • @AAK take some time and read the docs. also search through some of the answers on stack overflow. all the best. you can also ask SPECIFIC questions instead of this :) – Peter Thomas Feb 02 '19 at 00:39