How to check the status code of one API from karate-config.js?

Viewed 83

We have to call two APIs only once in whole project which is a pre-requisite for all other features to run. All features are using values set in userId and unitId.

The first feature call is working fine but I am not sure how to add if condition on status code as only when the status code of first feature@test1 is 200 only then we want to call the second one else not.

The below code displayed the value as

User Id is -------------378

But is not going in the if condition although this API returned response code as 200.

 var result = karate.callSingle('classpath:util/users.feature@test1',config);
  config.userId = result.response.value[0].id;
  karate.log("User Id is -------------" + config.userId)
  if( result.status == 200 ) 
  {
    var result1 = karate.callSingle('classpath:util/users.feature@test2',config);
    config.unitId = result1.response.value[0].id;
    karate.log("Unit Id is -------------" + config.unitId)
  }

1 Answers

It should be result.responseStatus.

Related