1

My test framework uses karate & python & its for backend testing.

I want to execute my tests in both dev & staging environments & so I have to pass data based on that condition to my feature file. (Similar to if else condition in java)

Below is my feature file setup

Scenario: xyz

  • def something = abc
  • def result = karate.exec("curl -X blah blah" + API-KEY + Endpoint)

Here I want it in such a way that:

if(Endpoint.contains('dev')) API-KEY = 'dev api key'

Else if(Endpoint.contains('sig')) API-KEY = 'Staging api key'

I want to be able to choose which data to be sent based on the environment that it's executing in.. This is for automated runs in GitHub.

Thanks in advance for your help.

ram
  • 21
  • 2

1 Answers1

0

You could use something like this:

* def apiKey = Endpoint.includes('dev') ? 'a' : 'b'

Or just write the logic in JS and call it, there are many options. Refer the docs on using JS functions: https://github.com/karatelabs/karate#javascript-functions

Also refer this answer: https://stackoverflow.com/a/50350442/143475

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