1

Sample Response

{
    "data": [
    {
        "name": "DJ", 
        "status": "ACTIVE"
    } 
    ]
}

Sample Feature File

@ignore
Feature: Sample

  @smoke
  Scenario: Karate expression to check if value exists in array 
    Given url url
    And path '/test'
    When method GET
    Then status 200
    And def users = response.data
    And def possibleStatus = ["ACTIVE", "INACTIVE"]

    And def schema =
    """
    {
      name: '#string',
      status: ? 
    }
    """
    And match each users contains schema

Is there a way to check if status is either ACTIVE or INACTIVE using karate expression ?

NOTE: It can be achieved by writing custom JS function.

0

1 Answer 1

3
* def statuses = [ 'ACTIVE', 'INACTIVE' ]
* def response = [{ name: 'DJ', status: 'ACTIVE' }, { name: 'PJ', status: 'INACTIVE' }]
* match each response == { name: '#string', status: '#? statuses.contains(_)' }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.