1

I have the below requirement where I need to dynamically change the key-value pair of the query string, but I am able to dynamically change the value of the query parameter but not the key part. It is taking the text value like 'paramName' in the request.

  • string reqBody = version == 'v2' ? 'ABC' : 'DEF'
  • string paramName = version == 'v2' ? 'json_body' : 'proto_body'
  • param paramName = reqBody

GET https://test.apis.com/sample?paramName=ABC or GET https://test.apis.com/sample?paramName=DEF

Deepak Rai
  • 171
  • 1
  • 1
  • 10

1 Answers1

1

If you need dynamic param names, use params: https://github.com/karatelabs/karate#params

* def temp = version == 'v2' ? { json_body: 'ABC' } : { proto_body: 'DEF' }
* params temp 

If you still have questions, read this: https://stackoverflow.com/a/50350442/143475

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