Skip to content

Assertions

Browse implementations

Assertions🔗

Assert🔗

This action takes a list of assertions written using SpEL and validates they are all true.

Required Name Type Default
* asserts List of Map

No outputs

Example🔗

1
2
3
4
5
AssertAction(
    asserts = listOf(
        "\${#status==200}"
    )
)

Json assert🔗

Asserts that JSON nodes have expected values.

Required Name Type Default Description
* document String json's string representation
* expected Map Keys contain json paths used to extract json node's data.
Values contain expected nodes values or assertions functions.

No outputs

Example🔗

JsonAssertAction(
    document = """
                {
                    "something": {
                        "value": my_value
                    }
                }
               """,
    expected = mapOf(
        "$.something.value" to "my_value"
    )
)

Xml assert🔗

Asserts that XML nodes have expected values.

Required Name Type Default Description
* document String xml's string representation
* expected Map keys contain xml paths used to extract xml node's data.
Values contain expected nodes values or assertions functions.

No outputs

Example🔗

XmlAssertAction(
    document =  """
                <root>
                   <node1 at1=\"val3\">
                       <leaf1>val1</leaf1>
                       <leaf2>5</leaf2>
                       <leaf3><![CDATA[val2]]></leaf3>
                   </node1>
                </root>
                """,
    expected = mapOf(
        "/root/node1/leaf1" to "val1",
        "//leaf2" to 5,
        "//node1/leaf3" to "val2",
        "//node1/@at1" to "val3"
    )
)

Assertions functions🔗

Placeholders used by xml-assert and json-assert actions to assert actual values.

Placeholder Description Example
$isNull must be null "$isNull"
$isNotNull must be not null "$isNotNull"
$contains must contains given value "$contains:abcde"
$isBeforeDate must be before given date "$isBeforeDate:2010-01-01T11:12:13.1230Z"
$isAfterDate must be after given date "$isAfterDate:1998-07-14T02:03:04.456Z"
$isEqualDate must be equal to given date "$isEqualDate:2000-01-01T11:11:12.123+01:00"
$matches must match given regex "$matches:\\d{4}-\\d{2}-\\d{2}"
$isLessThan must be less than given number $isLessThan:42000
$isGreaterThan must be greater than given number $isGreaterThan:45
$isEmpty string or array must be empty "$isEmpty"
$lenientEqual must be equal to given json using lenient compare mode "$lenientEqual:{\"object\": {\"att\": \"val\"}}"
$value[index] array's element at index must have expected value "$value[0]:three"

Validations🔗

Step

For functional validations, it's recommended to use above actions. For technical validations, it's possible to do them on scenario step validation.

Json validation🔗

Validates JSON structure using a given schema.

Required Name Type Default Description
* json String json's string representation
* schema String json schema

No outputs

Example🔗

JsonValidationAction(
    json = """
           {
               "id": 1,
               "name": "mouse",
               "price": 12
           }
           """,
    schema = """
             {
                 "${'$'}schema": "http://json-schema.org/draft-04/schema#",
                 "title": "Product",
                 "description": "A product from the catalog",
                 "type": "object",
                 "properties": {
                     "id": {
                         "description": "The unique identifier for a product",
                         "type": "integer"
                     },
                     "name": {
                         "description": "Name of the product",
                         "type": "string"
                     },
                     "price": {
                         "type": "number",
                         "minimum": 0,
                         "exclusiveMinimum": true
                     }
                 },
                 "required": ["id", "name", "price"]
             }
            """
)

Xml validation🔗

Validates XML structure using a given schema.

Required Name Type Default Description
* xml String xml's string representation
* xsd String xsd schema path

No outputs

Example🔗

XsdValidationAction(
    xml = """
          <?xml version=\"1.0\"?>
          <Employee xmlns=\"https://www.chutneytesting.com/Employee\">
              <name>my Name</name>
              <age>29</age>
              <role>Java Developer</role>
              <gender>Male</gender>
          </Employee>
          """,
    xsdPath = "/xsd_samples/employee.xsd"
)
XSD files example
    <?xml version="1.0" encoding="UTF-8"?>
    <schema xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="https://www.chutneytesting.com/Employee"
        xmlns:empns="https://www.chutneytesting.com/Employee"
        xmlns:gedns="https://www.chutneytesting.com/Gender"
        elementFormDefault="qualified">
        <import namespace="https://www.chutneytesting.com/Gender" schemaLocation="./gender.xsd" />
        <element name="Employee" type="empns:EmployeeType"></element>
        <complexType name="EmployeeType">
            <sequence>
                <element name="name" type="string"></element>
                <element name="age" type="int"></element>
                <element name="role" type="string"></element>
                <element name="gender" type="gedns:Gender"></element>
            </sequence>
        </complexType>
    </schema>
    <?xml version="1.0" encoding="UTF-8"?>
    <schema xmlns="http://www.w3.org/2001/XMLSchema"
           targetNamespace="https://www.chutneytesting.com/Gender"
           xmlns:gedns="https://www.chutneytesting.com/Gender"
          elementFormDefault="qualified">
        <simpleType name="Gender">
            <restriction base="string">
                <enumeration value="Male" />
                <enumeration value="Female" />
            </restriction>
        </simpleType>
    </schema>

XSD schema can be loaded from different paths

prefix description example
empty load xsd from classpath. It can load also from a jar in classpath xsdPath = "/xsd_samples/employee.xsd"
classpath: load xsd from classpath. It can load also from a jar in classpath xsdPath = "classpath:/xsd_samples/employee.xsd"
file: load xsd from file system xsdPath = "file:C:/my_data/xsd_samples/employee.xsd"

Comparison🔗

Compare🔗

Compares two strings using a comparison mode.

Required Name Type Default Description
* actual String actual string value
* expected String expected string value
* mode String comparison mode

No outputs

Example🔗

1
2
3
4
5
CompareAction(
    actual = "chutney",
    expected = "chutney",
    mode = "EQUALS" // case insensitive
) 

Available modes

mode description
equals actual and expected are equals
not equals / not-equals actual and expected are not equals
contains actual contains expected
not-contains / not contains actual doesn't contain expected
greater-than / greater than actual is greater than expected
less-than / less than actual is less than expected

Json compare🔗

Compares two JSON inputs (the whole content or only some nodes) using a comparison mode.

Required Name Type Default Description
* document1 String first json
* document2 String second json
* comparingPaths Map Map.of("$", "$") to be compared nodes json paths
* mode String STRICT comparison mode

No outputs

Example🔗

    JsonCompareAction(
        document1 = """
                {
                    "something": {
                        "value": 3
                    },
                    "something_else": {
                        "value": 5
                    },
                    "a_thing": {
                        "type": "my_type"
                    }
                }
                """,
        document2 = """
                {
                    "something_else": {
                        "value": 5
                    },
                    "a_thing": {
                        "type": "my_type"
                    }
                }
                """,
        comparingPaths = mapOf(
            "$.something.value" to "$.something_else.value",
            "$.a_thing" to "$.a_thing"
        ),
        mode = JsonCompareMode.STRICT
    )

Available modes

mode description
STRICT strict comparison
LENIENT even if the document1 contains extended fields (which document2 doesn't have), the test will still pass