1

I am trying to pass a url to karate.feature from json file. I never get to extract the url in feature file.

Below is my code example based on Pass Json to karate-config.js file.

I have also tried this stackoverflow answer Karate - How to import json data by Peter Thomas

env-data.json

{
   "dev":{
      "url":{
         "uri1":"https://example.com/dev/uri1/",
         "uri2":"https://example.com/dev/uri2/"
      }
   },
   "qa":{
      "url":{
         "uri1":"https://example.com/qa/uri1/",
         "uri2":"https://example.com/qa/uri2/"
      }
   }
}

karate-config.js

 function() {
  var env = 'dev'; // karate.env
  var temp = read('classpath:env-data.json');
  return temp[env];
}

karate.feature

Scenario: Testing that GET response contains specific field
Given url url['uri1']
Given path 'check'
When method GET
Then status 200
And match $ == {#notnull}

testRunner.java

@RunWith(Karate.class)
public class testRunner {    
}

Command I am using:

mvn clean test -Dtest=testRunner -Dkarate.env=dev

when I run the tests, Given url url['uri1'] this step from feature file couldn't able to retrieve the url from json file. Not sure what I am missing. Please help me.

Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
tej
  • 11
  • 1

0 Answers0