Skip to main content

Sleeps and waits

I wait for <element>

Waits for an element to appear on a page for a default number of seconds before timing out. The default timeout period is equal to the configured gwen.web.wait.seconds setting value. The default timeout can be overridden using the @Timeout annotation.

Where

  • <element> is the name of the element to wait for

Example

  # Wait for a dynamically rendered input field 
Given the dynamic input field can be located by tag "input"
When I wait for the dynamic input field
Then the dynamic input field should be displayed
I wait for <element> text

Waits for the text of an element to appear on a page for a default number of seconds before timing out.

Where

  • <element> is the name of the element to wait for the text to appear

Example

  # Wait for a dynamically displayed token
Given the one time token can be located by javascript "$('.token').get(0)"
When I wait for the one time token text
And I capture the one time token
I wait until <element> is[ not] <state>

Waits for an element to transition to a given state. The default timeout period is equal to the configured gwen.web.wait.seconds setting value. The default timeout can be overridden using the @Timeout annotation.

Where

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

    • displayed to wait until the element is displayed
    • hidden to wait until the element is not displayed
    • checked (or ticked since v2.4.0) to wait until a checkbox is ticked
    • unchecked (or unticked since v2.4.0) to wait until a checkbox is not ticked
    • enabled to wait until the element is enabled
    • disabled to wait until the element is disabled

Example

  Given my todo list can be located by css ".todo-list"
And the todo field can be located by class "new-todo"
When I navigate to "https://todomvc.com/examples/react/dist"
And I enter "Get the milk" in the todo field
And I wait until my todo list is displayed
I wait until "<javascript>"

Repeatedly executes the given javascript expression or function until true is returned using no delay interval and default timeout period. The default timeout period is equal to the configured gwen.web.wait.seconds setting value. The default timeout can be overridden using the @Timeout annotation.

Where

  • <javascript> is the javascript expression or function that will return a boolean value (can be in DocString position)

    • For a one liner expression, no function, arrow declaration or return prefix is required
    • For a function, use either:

      • Arrow syntax (preferred): () => { body } (Since v3.56.0)
      • Or anonymous function syntax (legacy): (function(){ body })()

Example

 Given the heading can be located by tag "h1"
When I navigate to "https://challengers.flood.io/start"
And I wait until "!!$('h1')"
Then the heading should be "Welcome to our Script Challenge"
I wait until "<filepath>" file[ not] exists

Waits until a file exists (or not). The default timeout period is equal to the configured gwen.web.wait.seconds setting value. The default timeout can be overridden using the @Timeout annotation.

Where

  • <filepath> the path to the file
  • not to wait until the file does not exist (negation)

Examples

   Then I wait until "path/to/filename1.csv" file exists
And I wait until "path/to/filename2.csv" file not exists
I wait until "<filepath>" file does not exist

Waits until a file does not exist. The default timeout period is equal to the configured gwen.web.wait.seconds setting value. The default timeout can be overridden using the @Timeout annotation.

Where

  • <filepath> the path to the file

Examples

    And I wait until "path/to/filename2.csv" file does not exist
I wait until <filepathRef file>[ not] exists

Waits until a file exists (or not). The default timeout period is equal to the configured gwen.web.wait.seconds setting value. The default timeout can be overridden using the @Timeout annotation.

Where

  • <filepathRef file> is the name of the binding containing the path of the file
  • not to wait until the file does not exist (negation)

Examples

  Given my file is "path/to/filename.csv""
Then I wait until my file exists
And I wait until my file not exists
I wait until <filepathRef file> does not exist

Waits until a file does not exist. The default timeout period is equal to the configured gwen.web.wait.seconds setting value. The default timeout can be overridden using the @Timeout annotation.

Where

  • <filepathRef file> is the name of the binding containing the path of the file

Examples

  Given my file is "path/to/filename.csv""
And I wait until my file does not exist
I wait until "<filepath>" file is[ not] empty

Waits until a file is empty. The default timeout period is equal to the configured gwen.web.wait.seconds setting value. The default timeout can be overridden using the @Timeout annotation.

Where

  • <filepath> the path to the file
  • not to wait until the file is not empty (negation)

Examples

   Then I wait until "path/to/filename1.csv" file is empty
And I wait until "path/to/filename2.csv" file is not empty
I wait until <filepathRef file> is[ not] empty

Waits until a file is empty. The default timeout period is equal to the configured gwen.web.wait.seconds setting value. The default timeout can be overridden using the @Timeout annotation.

Where

  • <filepathRef file> is the name of the binding containing the path of the file
  • not to wait until the file is not empty (negation)

Examples

  Given my file is "path/to/filename.csv""
Then I wait until my file is empty
And I wait until my file is not empty
I wait until <condition>

Waits until a condition is satisfied. The default timeout period is equal to the configured gwen.web.wait.seconds setting value. The default timeout can be overridden using the @Timeout annotation.

Where

  • <condition> is either:

    • Since v3.54.0

      • the name of any binding that will return true when the condition is satisfied or false when it is not
    • Or in prior versions

      • the name of a binding containing a javascript function or expression that will return true when the condition is satisfied or false when it is not
      • the name of a binding containing a true or false value literal, since v3.50.0

Example

 Given the heading can be located by tag "h1"
And the heading is displayed is defined by javascript "!!$('h1')"
When I navigate to "https://challengers.flood.io/start"
And I wait until the heading is displayed
Then the heading should be "Welcome to our Script Challenge"
I wait for the <alert|confirmation> popup

Waits for the alert/confirmation popup to appear on a page for a default number of seconds before timing out. The default timeout period is equal to the configured gwen.web.wait.seconds setting value. The default timeout can be overridden using the @Timeout annotation.

Where

  • <element> is the name of the element to wait for

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
And I wait for the alert popup
Then the alert popup message should not be blank
I wait <duration> second[s]

Sleeps for the given number of seconds.

Where

  • <duration> is the number of seconds to sleep
  • Include trailing s when specifying a <duration> that is not 1, omit otherwise

Example

  When I wait for 5 seconds