Skip to main content

Element asserts

<element> should[ not] be <state>

Checks whether or not an element is in a given state.

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

<element> should[ not] be <state>  @Message("my custom assert fail message")


Without any timeout (as of v3.73.0):

@Timeout('0s') <element> should[ not] be <state>


With custom timeout (as of v3.73.0):

@Timeout('10s') <element> should[ not] be <state>

Where

  • <element> is the name of the element to check
  • not negates the state if included
  • <state> is one of:

    • displayed to check if the element is displayed
    • hidden to check if the element is not displayed
    • checked (or ticked since v2.4.0) to check if a checkbox is ticked
    • unchecked (or unticked since v2.4.0) to check if a checkbox is not ticked
    • enabled to check if the element is enabled
    • disabled to check if the element is disabled
  • <timeoutSecs> is the timeout period in seconds
  • <wait|timeout> is either wait or timeout

Example

  Given my todo list can be located by css ".todo-list"
When I navigate to "https://todomvc.com/examples/react/dist"
Then my todo list should be empty
<element> should[ not] <match> "<expression>"

Checks whether or not the text value of an element matches a given expression. Reports an assertion error if the match fails.

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

<element> should[ not] <match> "<expression>"  @Message("my custom assert fail message")


Without any timeout (as of v3.73.0):

@Timeout('0s') <element> should[ not] <match> "<expression>"


With custom timeout (as of v3.73.0):

@Timeout('10s') <element> should[ not] <match> "<expression>"

Where

  • <element> is the name of the element to check
  • 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 (can be in DocString position)
  • <timeoutSecs> is the timeout period in seconds
  • <wait|timeout> is either wait or timeout

Example

  Given the todo field can be located by class "new-todo"
And my todo list can be located by css ".todo-list"
When I navigate to "https://todomvc.com/examples/react/dist"
And I enter "Get the milk" in the todo field
Then my todo list should contain "Get the milk"

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
<element> should[ not] <match> <expressionRef>

Checks whether or not the text value of an element matches a referenced expression. Reports an assertion error if the match fails.

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

<element> should[ not] <match> <expressionRef>  @Message("my custom assert fail message")


Without any timeout (as of v3.73.0):

@Timeout('0s') <element> should[ not] <match> <expressionRef>


With custom timeout (as of v3.73.0):

@Timeout('10s') <element> should[ not] <match> <expressionRef>

Where

  • <element> is the name of the element to check
  • 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
  • <expressionRef> is the name of the binding containing the expression to match

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

Example

  Given the todo field can be located by class "new-todo"
And my todo list can be located by css ".todo-list"
And my item is "Feed the cat"
When I navigate to "https://todomvc.com/examples/react/dist"
And I enter my item in the todo field
Then my todo list should contain my item

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