Skip to main content

JSON asserts

<jsonRef> at json path "<path>" should[ not] be <blank|empty>

Extracts text from the referenced JSON value using the given JSON path and checks whether or not it matches a blank or empty string. Reports an assertion error if the match fails.

With custom assertion error message (as of v3.9.0):

<jsonRef> at json path "<path>" should[ not] be blank  @Message("my custom assert fail message")


Without any timeout (as of v3.73.0):

@Timeout('0s') <jsonRef> at json path "<path>" should[ not] be blank


With custom timeout (as of v3.73.0):

@Timeout('10s') <jsonRef> at json path "<path>" should[ not] be blank

Where

  • <jsonRef> is the name of the binding containing the JSON source text

    • Can be the name of any binding that contains or resolves to a JSON text value, including a web element in which case the text in the element will be dynamically retrieved and used.
  • path is the JSON path selector expression
  • not negates the match if included
  • <timeoutSecs> is the timeout period in seconds
  • <wait|timeout> is either wait or timeout

Example

    Given the json is "{ "status": "passed" }"
Then the json at json path "$.status" should not be blank

Trimming (since v3.62.0)

  • The @Trim annotation can be used on step to trim strings when comparing
<jsonRef> at json path "<path>" should[ not] <match> "<expression>"

Extracts text from the referenced JSON value using the given JSON path and checks that it matches a given expression. Reports an assertion error if the match fails.

With custom assertion error message (as of v3.9.0):

<jsonRef> at json path "<path>" should[ not] <match> "<expression>"  @Message("my custom assert fail message")


Without any timeout (as of v3.73.0):

@Timeout('0s') <jsonRef> at json path "<path>" should[ not] <match> "<expression>"


With custom timeout (as of v3.73.0):

@Timeout('10s') <jsonRef> at json path "<path>" should[ not] <match> "<expression>"

Where

  • <jsonRef> is the name of the binding containing the JSON source text

    • Can be the name of any binding that contains or resolves to a JSON text value, including a web element in which case the text in the element will be dynamically retrieved and used.
  • path is the JSON path selector expression
  • not negates the match if included
  • <match> is the type of match to perform, one of:

    • be for exact match
    • contain for partial match
    • start with for partial leading match
    • end with for partial trailing match
    • match regex for regex match
    • match xpath for XML match
    • match json path for JSON match, since v1.4.0
    • match template for template match, since v2.16.0
    • match template file for template file match, since v2.16.0
  • <expression> is the expression to match
  • <timeoutSecs> is the timeout period in seconds
  • <wait|timeout> is either wait or timeout

Example

    Given the json is "{ "status": "passed" }"
Then the json at json path "$.status" should be "passed"

Trimming and ignoring case (since v3.62.0)

  • The @Trim annotation can be used on step to trim strings when comparing
  • The @IgnoreCase annotation can be used on step to ignore case when comparing