Skip to main content

Until/While

Since v3.48.0, the following implicit attributes are available to <step>s:

  • gwen.iteration.number = current iteration starting at 1
  • gwen.iteration.index = current iteration starting at 0
<step> <until|while> <condition>

Repeatedly exectues a step until or while a condition is satisfied using a default delay and timeout period. The default delay between iterations is one tenth of the configured gwen.web.wait.seconds setting (or 1 second if not set). The default timeout period is 30 times the delay. The default delay and timeout can be overridden using the @Delay and @Timeout annotations.

Where

  • <step> is the DSL step or StepDef to execute in each iteration
  • <until|while> is one of:

    • until to repeat until the condition is satisfied
    • while to repeat while the condition is satisfied
  • <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
  • The following implicit binding is available in <step>:

    • iteration number (or gwen.iteration.number since v2.52.0) is the current iteration number (starting at 1)

Example

    Given the search field can be located by name "q"
And the next page link can be located by id "pnnext"
And topic is "what is gwen"
And topic link can be located by partial link text "${topic}"
And topic not found is defined by js
"""
[...document.querySelectorAll("a")]
.filter(a => a.textContent.includes('${topic}'))
.length == 0
"""
When I navigate to "https://google.com"
And I enter "gwen interpreter" in the search field
And I click the next page link while topic not found
And I click topic link
Then the page title should contain "${topic}"

With explicit delay and timeout since v3.73.0

    Given the search field can be located by name "q"
And the next page link can be located by id "pnnext"
And topic is "what is gwen"
And topic link can be located by partial link text "${topic}"
And topic not found is defined by js
"""
[...document.querySelectorAll("a")]
.filter(a => a.textContent.includes('${topic}'))
.length == 0
"""
When I navigate to "https://google.com"
And I enter "gwen interpreter" in the search field
And @Delay('10s') @Timeout('1m') I click the next page link while topic not found
And I click topic link
Then the page title should contain "${topic}"

With no delay or timeout since v3.73.0

    Given the search field can be located by name "q"
And the next page link can be located by id "pnnext"
And topic is "what is gwen"
And topic link can be located by partial link text "${topic}"
And topic not found is defined by js
"""
[...document.querySelectorAll("a")]
.filter(a => a.textContent.includes('${topic}'))
.length == 0
"""
When I navigate to "https://google.com"
And I enter "gwen interpreter" in the search field
And @Delay('0s') @Timeout('0s') I click the next page link while topic not found
And I click topic link
Then the page title should contain "${topic}"
<step> <until|while> <element> is[ not] <state>

Repeatedly exectues a step until or while an element is in a given state using a 1 second delay interval and 1 minute timeout period. The default delay and timeout can be overridden using the @Delay and @Timeout annotations.

Where

  • <step> is the DSL step or StepDef to execute in each iteration
  • <until|while> is one of:

    • until to repeat until the condition is satisfied
    • while to repeat while the condition is satisfied
  • <element> is the name of the element to check the state of
  • not negates the state if included
  • <state> is one of:

    • displayed to execute the step until or while the element is displayed
    • hidden to execute the step until or while the element is not displayed
    • checked or ticked to execute the step until or while a checkbox is ticked
    • unchecked or unticked to execute the step until or while a checkbox is not ticked
    • enabled to execute the step until or while the element is enabled
    • disabled to execute the step until or while the element is disabled
  • The following implicit binding is available in <step>:

    • iteration number (or gwen.iteration.number since v2.52.0) is the current iteration number (starting at 1)

Example

    Given the search field can be located by name "q"
And the next page link can be located by id "pnnext"
When I navigate to "https://google.com"
And I enter "gwen interpreter" in the search field
And I click the next page link while the next page link is displayed
Then the next page link should not be displayed

With explicit delay and timeout since v3.73.0

   Given the search field can be located by name "q"
And the next page link can be located by id "pnnext"
When I navigate to "https://google.com"
And I enter "gwen interpreter" in the search field
And @Delay('5s') @Timeout('40s') I click the next page link while the next page link is displayed
Then the next page link should not be displayed

With no delay or timeout since v3.73.0

   Given the search field can be located by name "q"
And the next page link can be located by id "pnnext"
When I navigate to "https://google.com"
And I enter "gwen interpreter" in the search field
And @Delay('0s') @Timeout('0s') I click the next page link while the next page link is displayed
Then the next page link should not be displayed
<step> <until|while> <name> is[ not] defined

Repeatedly exectues a step until or while an attribute is defined (or not) using a 1 second delay interval and 1 minute timeout period. The default delay and timeout can be overridden using the @Delay and @Timeout annotations.

Where

  • <step> is the DSL step or StepDef to execute in each iteration
  • <until|while> is one of:

    • until to repeat until the attribute is defined (or not)
    • while to repeat while the attribute is defined (or not)
  • <name> is the name of the attribute (or StepDef <param> since v4.11.0) to check
  • not include to execute step until or while attribute is not defined
  • The following implicit binding is available in <step>:

    • iteration number (or gwen.iteration.number since v2.52.0) is the current iteration number (starting at 1)
<step> <until|while> "<filepath>" file[ not] exists

Repeatedly exectues a step until or while a file exists (or not) using a 1 second delay interval and 1 minute timeout period. The default delay and timeout can be overridden using the @Delay and @Timeout annotations.

Where

  • <step> is the DSL step or StepDef to execute in each iteration
  • <until|while> is one of:

    • until to repeat until the attribute is defined (or not)
    • while to repeat while the attribute is defined (or not)
  • <filepath> the path to the file to check
  • notto wait until the file does not exist (negation)
  • The following implicit binding is available in <step>:

    • iteration number (or gwen.iteration.number since v2.52.0) is the current iteration number (starting at 1)
<step> <until|while> "<filepath>" file does not exist

Repeatedly exectues a step until or while a file does not exist using a 1 second delay interval and 1 minute timeout period. The default delay and timeout can be overridden using the @Delay and @Timeout annotations.

Where

  • <step> is the DSL step or StepDef to execute in each iteration
  • <until|while> is one of:

    • until to repeat until the attribute is defined (or not)
    • while to repeat while the attribute is defined (or not)
  • <filepath> the path to the file to check
  • The following implicit binding is available in <step>:

    • iteration number (or gwen.iteration.number since v2.52.0) is the current iteration number (starting at 1)
<step> <until|while> "<filepath>" file is[ not] empty

Repeatedly exectues a step until or while a file is empty (or not) using a 1 second delay interval and 1 minute timeout period. The default delay and timeout can be overridden using the @Delay and @Timeout annotations.

Where

  • <step> is the DSL step or StepDef to execute in each iteration
  • <until|while> is one of:

    • until to repeat until the attribute is defined (or not)
    • while to repeat while the attribute is defined (or not)
  • <filepath> the path to the file to check
  • notto wait until the file is not empty (negation)
  • The following implicit binding is available in <step>:

    • iteration number (or gwen.iteration.number since v2.52.0) is the current iteration number (starting at 1)
<step> <until|while> <filepathRef file>[ not] exists

Repeatedly exectues a step until or while a file exists (or not) using a 1 second delay interval and 1 minute timeout period. The default delay and timeout can be overridden using the @Delay and @Timeout annotations.

Where

  • <step> is the DSL step or StepDef to execute in each iteration
  • <until|while> is one of:

    • until to repeat until the attribute is defined (or not)
    • while to repeat while the attribute is defined (or not)
  • <filepathRef file> is the name of the binding containing the path of the file to check
  • notto wait until the file does not exist (negation)
  • The following implicit binding is available in <step>:

    • iteration number (or gwen.iteration.number since v2.52.0) is the current iteration number (starting at 1)
<step> <until|while> <filepathRef file> does not exist

Repeatedly exectues a step until or while a file does not exist using a 1 second delay interval and 1 minute timeout period. The default delay and timeout can be overridden using the @Delay and @Timeout annotations.

Where

  • <step> is the DSL step or StepDef to execute in each iteration
  • <until|while> is one of:

    • until to repeat until the attribute is defined (or not)
    • while to repeat while the attribute is defined (or not)
  • <filepathRef file> is the name of the binding containing the path of the file to check
  • The following implicit binding is available in <step>:

    • iteration number (or gwen.iteration.number since v2.52.0) is the current iteration number (starting at 1)
<step> <until|while> <filepathRef file> is[ not] empty

Repeatedly exectues a step until or while a file is empty (or not) using a 1 second delay interval and 1 minute timeout period. The default delay and timeout can be overridden using the @Delay and @Timeout annotations.

Where

  • <step> is the DSL step or StepDef to execute in each iteration
  • <until|while> is one of:

    • until to repeat until the attribute is defined (or not)
    • while to repeat while the attribute is defined (or not)
  • <filepathRef file> is the name of the binding containing the path of the file to check
  • notto wait until the file is not empty (negation)
  • The following implicit binding is available in <step>:

    • iteration number (or gwen.iteration.number since v2.52.0) is the current iteration number (starting at 1)
<step> <while|until> <name> is[ not] <blank|empty>

Repeatedly exectues a step until or while an element or attribute is bound to a blank or empty value (or not) using a 1 second delay interval and 1 minute timeout period. The default delay and timeout can be overridden using the @Delay and @Timeout annotations.

Where

  • <step> is the DSL step or StepDef to repeatedly execute
  • <name> is the name of the element or attribute (or StepDef <param> since v4.11.0) to check
  • not to negate the condition

Example

 Given the state code can be located by name "state"
When I navigate to "https://example.com"
And I refresh the current page while the state code is blank
<step> <while|until> <name> is[ not] "<value>"

Repeatedly exectues a step until or while an element or attribute is equal to a value (or not) using a 1 second delay interval and 1 minute timeout period. The default delay and timeout can be overridden using the @Delay and @Timeout annotations.

Where

  • <step> is the DSL step or StepDef to repeatedly execute
  • <name> is the name of the element or attribute (or StepDef <param> since v4.11.0) to check
  • not to negate the condition
  • value is the given value

Example

 Given the state code can be located by name "state"
When I navigate to "https://example.com?state=Victoria"
And I refresh the current page while the state code is not "VIC"

Trimming and ignoring case

  • 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
<step> <while|until> <name> <match> "<expression>"`

Repeatedly exectues a step until or while an element or attribute matches an expression using a 1 second delay interval and 1 minute timeout period. The default delay and timeout can be overridden using the @Delay and @Timeout annotations.

Where

  • <step> is the DSL step or StepDef to repeatedly execute
  • <name> is the name of the element or attribute (or StepDef <param> since v4.11.0) to check
  • <match> is the type of match to perform, one of:

    • contains for partial match
    • starts with for partial leading match
    • ends with for partial trailing match
    • matches regex for regex match
    • matches xpath for XML match
    • matches json path for JSON match, since v1.4.0
    • matches template for template match, since v2.16.0
    • matches template file for template file match, since v2.16.0
  • <expression> is the expression to match (can be in DocString position)

Example

 Given the state code can be located by name "state"
When I navigate to "https://example.com?state=${the state code}"
And I refresh the current page until the state code matches regex "(VIC|NSW)"

Trimming and ignoring case

  • 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
<step> <while|until> <name> does not <match> "<expression>"`

Repeatedly exectues a step until or while an element or attribute does not match an expression using a 1 second delay interval and 1 minute timeout period. The default delay and timeout can be overridden using the @Delay and @Timeout annotations.

Where

  • <step> is the DSL step or StepDef to repeatedly execute
  • <name> is the name of the element or attribute (or StepDef <param> since v4.11.0) to check
  • <match> is the type of match to perform, one of:

    • contain for partial match
    • start with for partial leading match
    • end with for partial trailing match
    • matche regex for regex match
    • matche xpath for XML match
    • matche json path for JSON match, since v1.4.0
    • matche template for template match, since v2.16.0
    • matche template file for template file match, since v2.16.0
  • <expression> is the expression to match (can be in DocString position)

Example

 Given the state code can be located by name "state"
When I navigate to "https://example.com?state=${the state code}"
And I refresh the current page until the state code does not match regex "(VIC|NSW)"

Trimming and ignoring case

  • 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