Skip to main content

Alert and Popup asserts

the <alert|confirmation> popup message should[ not] be <blank|empty>

Checks whether or not the message in the alert or confirmation popup box matches a blank or empty string. Reports an assertion error if the match fails.

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

the <alert|confirmation> popup message should[ not] be blank  @Message("my custom assert fail message")


Without any timeout (as of v3.73.0):

@Timeout('0s') the <alert|confirmation> popup message should[ not] be blank


With custom timeout (as of v3.73.0):

@Timeout('10s') the <alert|confirmation> popup message should[ not] be blank

Where

  • not negates the match if included
  • <timeoutSecs> is the timeout period in seconds
  • <wait|timeout> is either wait or timeout

Example

  Given the alert link can be located by id "alert"
When I navigate to "https://www.selenium.dev/selenium/web/alerts.html"
And I click the alert link
Then the alert popup message should not be blank

Trimming (since v3.62.0)

  • The @Trim annotation can be used on step to trim strings when comparing
the <alert|confirmation> popup message should[ not] <match> "<expression>"

Checks whether or not the message in the alert or confirmation popup box matches a given expression. Reports an assertion error if the match fails.

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

the <alert|confirmation> popup message should[ not] <match> "<expression>"  @Message("my custom assert fail message")


Without any timeout (as of v3.73.0):

@Timeout('0s') the <alert|confirmation> popup message should[ not] <match> "<expression>"


With custom timeout (as of v3.73.0):

@Timeout('10s') the <alert|confirmation> popup message should[ not] <match> "<expression>"

Where

  • 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 alert link can be located by id "alert"
When I navigate to "https://www.selenium.dev/selenium/web/alerts.html"
And I click the alert link
Then the alert popup message should be "cheese"

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
the <alert|confirmation> popup message should[ not] <match> <expressionRef>

Checks whether or not the message in the alert or confirmation popup box matches a referenced expression. Reports an assertion error if the match fails.

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

the <alert|confirmation> popup message should[ not] <match> <expressionRef>  @Message("my custom assert fail message")


Without any timeout (as of v3.73.0):

@Timeout('0s') the <alert|confirmation> popup message should[ not] <match> <expressionRef>


With custom timeout (as of v3.73.0):

@Timeout('10s') the <alert|confirmation> popup message should[ not] <match> <expressionRef>

Where

  • 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 confirmation link can be located by id "prompt-with-default"
And the expected message is "Enter something"
When I navigate to "https://www.selenium.dev/selenium/web/alerts.html"
And I click the confirmation link
Then the confirmation popup message should be the expected message

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
the <alert|confirmation> popup should[ not] be displayed

Checks whether or not the alert/comnfirmation popup should be displayed or not. Reports an assertion error if the assertion fails.

With custom assertion error message:

the <alert|confirmation> popup should[ not] be displayed  @Message("my custom assert fail message")


Without any timeout:

@Timeout('0s') the <alert|confirmation> popup should[ not] be displayed


With custom timeout:

@Timeout('10s') the <alert|confirmation> popup should[ not] be displayed

Where

  • <alert|confirmation> is either:

    • alert for an alert box with an OK button
    • confirmation for a confirmation box with OK and Cancel buttons
  • not negates the assertion if included (should not be displayed)

Example

  Given the confirmation link can be located by id "prompt-with-default"
When I navigate to "https://www.selenium.dev/selenium/web/alerts.html"
And I click the confirmation link
Then the confirmation popup should be displayed