1

There are following 2 responses based on the value of env variable.

if env = Prod,

[
  {
    "_": {
      "name": "FA",
      "icon-url": "https://test.com/static/images/air/partner.png"
    },
    "@": {
      "code": "00"
    }
  },
  {
    "_": {
      "name": "DA",
      "icon-url": "https://test.com/static/images/air/partner.png"
    },
    "@": {
      "code": "0D"
    }
  }]

And we want to replace test.com with prod.com

if env is SIT

[
  {
    "code": "00",
    "name": "FA",
    "iconUrl": "https://test.com/static/images/air/partner.png"
  },
  {
    "code": "0D",
    "name": "DA",
    "iconUrl": "https://test.com/static/images/air/partner.png"
  }
]

The catch here is the iconUrl key name in both the responses is different. In case the env is Prod, we want to replace icon-url 'test.com' with 'prod.com' In case the env is SIT, we want to replace iconUrl 'test.com' with 'sit.com'

user1873274
  • 181
  • 1
  • 9

1 Answers1

0

There are many ways to solve this. First please read this advice on keeping tests simple: https://stackoverflow.com/a/54126724/143475

For ideas on conditional logic, refer: https://stackoverflow.com/a/50350442/143475

One possible way is to have two copies of the expected result. And depending on the environment, load the right one:

* match response = read('expected-' + karate.env + '.json')

Otherwise I leave it as a homework for you as to how to modify a given JSON based on some parameters. Please read this: https://stackoverflow.com/a/62567262/143475 - and the other linked answers.

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