Skip to main content

Text asserts

<textRef> should[ not] be <blank|empty>

Checks whether or not the text reference matches a blank or empty string. Reports an assertion error if the match fails.

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

<textRef> should[ not] be <blank|empty>  @Message("my custom assert fail message")


Without any timeout (as of v3.73.0):

@Timeout('0s') <textRef> should[ not] be blank


With custom timeout (as of v3.73.0):

@Timeout('10s') <textRef> should[ not] be blank

Where

  • <textRef> is the name of the binding containing the text to check

    • Can be the name of any binding that contains or resolves to a text value, including a web element in which case the text in the element will be dynamically retrieved and used.
  • not negates the match if included
  • <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
And I capture my todo list as current items
Then current items should not be empty

Trimming (since v3.62.0)

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

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

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

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


Without any timeout (as of v3.73.0):

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


With custom timeout (as of v3.73.0):

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

Where

  • <textRef> is the name of the binding containing the text to check

    • Can be the name of any binding that contains or resolves to a text value, including a web element in which case the text in the element will be dynamically retrieved and used.
  • 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
And I capture my todo list as current items
Then current items 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
<textRef> should[ not] <match> <expressionRef>

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

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

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


Without any timeout (as of v3.73.0):

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


With custom timeout (as of v3.73.0):

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

Where

  • <variable> is the name of the variable or setting 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
And I capture my todo list as current items
Then current items 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
<textRef> should[ not] <match> <percentage>% similar to "<text>"

Compares a text reference with a text value for similarity using the DSC (Dice Similarity Coefficient) algorithm.

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

<textRef> should[ not] <match> <percentage>% similar to "<text>"  @Message("my custom assert fail message")


Without any timeout (as of v3.73.0):

@Timeout('0s') <textRef> should[ not] <match> <percentage>% similar to "<text>"


With custom timeout (as of v3.73.0):

@Timeout('10s') <textRef> should[ not] <match> <percentage>% similar to "<text>"

Where

  • <textRef> is the name of the binding containing a text reference

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

    • be for exact match
    • be less than for less than match
    • be at most for less than or equal to match
    • be more than for greater than match
    • be at least for greater than or equal to match
  • <text> is the text to compare <textRef> against
  • <timeoutSecs> is the timeout period in seconds
  • <wait|timeout> is either wait or timeout

The calculated similarity score is implicity bound to the similarity score attribute in the global scope.

Examples

  Given the phrase is "Hello world!"
Then the phrase should be more than 90% similar to "Hello world"
And @IgnoreCase the phrase should be at least 90% similar to "hello world"
And the phrase should be 94.12% similar to "Hello world"
And @IgnoreCase the phrase should be 94.12% similar to "hello world"
And the phrase should be 82.35% similar to "hello world"
And the phrase should not be less than 90% similar to "Hello world"

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
<textRef1> should[ not] <match> <percentage>% similar to <textRef2>

Compares a text reference with another for similarity using the DSC (Dice Similarity Coefficient) algorithm.

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

<textRef1> should[ not] <match> <percentage>% similar to <textRef2>  @Message("my custom assert fail message")


Without any timeout (as of v3.73.0):

@Timeout('0s') <textRef1> should[ not] <match> <percentage>% similar to <textRef2>


With custom timeout (as of v3.73.0):

@Timeout('10s') <textRef1> should[ not] <match> <percentage>% similar to <textRef2>

Where

  • <textRef1> is the name of the binding containing the first text reference

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

    • be for exact match
    • be less than for less than match
    • be at most for less than or equal to match
    • be more than for greater than match
    • be at least for greater than or equal to match
  • <percentage> is a percentage number between 0 and 100 (internally rounded to 2 decimal places)
  • <textRef2> is the name of the binding containing the second text reference to compare <textRef1> against

    • Can be the name of any binding that contains or resolves to a text 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

The calculated similarity score is implicity bound to the similarity score attribute in the global scope.

Examples

  Given phrase 1 is "Hello world!"
And phrase 2 is "Hello world"
And phrase 3 is "hello world"
Then phrase 1 should be more than 90% similar to phrase 2
And @IgnoreCase phrase 1 should be at least 90% similar to phrase 2
And phrase 1 should be 94.12% similar to phrase 2
And @IgnoreCase phrase 1 should be 94.12% similar to phrase 3
And phrase 1 should be 82.35% similar to phrase 3
And phrase 1 should not be less than 90% similar to phrase 2

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