0

Have a variable 'dummyVariable' in a function of MyService.java file. Now I am calling an endpoint 'dummyEndpoint' that sets the value of 'dummyVariable' to true or false.

I want to extract this value of 'dummyVariable' after I call 'dummyEndpoint' using Karate feature files by call() method.

Further I want to perform different actions in feature file depending on this value being true or false. Basically this can be treated as knowing whether an experiment is on or off in java service during an endpoint calling.

More crisp explanation-> dummyEndpoint called from Karate file-> sets a variable's value in java service -> want to extract that value after call completion.

//MyKarateFile .feature file



Scenario: Make a call to service
  Given url baseUrl
  And path ‘/some-path’
  And header Authorization = api
  And param environment = env
  And request req
  When method POST
  Then status 200
  //want to check dummyVariable 's value here

//MyService .java

private final DummyVariableSetter dummyVariableSetter;
public int myFunction() {
    boolean dummyVariable = dummyVariableSetter.isDummyVaribaleOn();
    if(!dummyVariable) return 0;
    return 1;
}

//DummyVariableSetter .java

public boolean isDummyVaribaleOn() {
    return getVersion(“some-property”) >= 0;
}

tried using exits() method of Karate but did not worked.

1 Answers1

0

Normally teams use karate.callSingle() for this kind of use-case: https://stackoverflow.com/a/56853597/143475

If you insist on using Java, use a singleton as described here: https://stackoverflow.com/a/54571844/143475

Please note that tests that depend on each other is not a good practice and not supported by Karate: https://stackoverflow.com/a/46080568/143475

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