13 Assertions - biswajitsundara/Karate GitHub Wiki
Karate assert/match keywords work for string. There are more validations for Integer using assert keyword.
Feature: User details
  Background: 
    * url 'https://reqres.in'
    * def expectedoutput = read('./data/data.json')
  Scenario: Assert JSON response
    Given path '/api/users/2'
    When method GET
    Then status=200
    And print response
    And match response == expectedoutput
  Scenario: JSON order doesn't matter
    * def userReq = {"name":"Ranveer","wife":"Deepika"}
    * def userRes = {"name":"Ranveer","wife":"Deepika"}
    And match userReq == userRes
    * def userRes1 = {"wife":"Deepika","name":"Ranveer"}
    And match userReq == userRes1
  Scenario: Not equals
    * def userReq = {"name":"Ranveer"}
    * def userRes = {"name":"Virat"}
    And match userReq != userRes
  Scenario: Contains (check if the field exists)
    Given path '/api/users/1'
    When method GET
    Then status=200
    And print response
    And match response.data contains {"email":"[email protected]"}
    And match response.data !contains {"email":"[email protected]"}
  Scenario: Match array
    Given path '/api/users/'
    And param page = 2
    When method GET
    Then status=200
    And print response
    And match response.data[*].id contains [7,8,9]
    And match response..id contains [7,8,9]
  #Here match response.total > 10 doesn't work
  Scenario: Integer value
    Given path '/api/users/'
    And param page = 2
    When method GET
    Then status=200
    And print response
    And match response.total == 12
    And assert response.total > 10
- Let's say if we want to assert the value returned from a function.
def result = sum(1,2) assert sum(1,2) == 3