Skip to main content

If

<step> if[ not] <condition>

Executes a step depending on whether or not a JS condition evaluates to true.

Where

  • <step> is the DSL step or StepDef to potentially execute
  • not negates the condition if included (Since v3.4.0)
  • <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
    • Since v3.14.1, the condition name cannot contain double qutoes

Example

  Given the search field can be located by name "q"
And topic is "Automation Bindings"
And topic link can be located by partial link text "${topic}"
And topic 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 "automation" in the search field
And I click topic link if topic found
Then the page title should contain "${topic}" if topic found
<step> if <element> is[ not] <state>

Executes a step depending on whether or not an element is in a given state.

Where

  • <step> is the DSL step or StepDef to potentially execute
  • <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 if the element is displayed
    • hidden to execute the step if the element is not displayed
    • checked or ticked to execute the step if a checkbox is ticked
    • unchecked or unticked to execute the step if a checkbox is not ticked
    • enabled to execute the step if the element is enabled
    • disabled to execute the step if the element is disabled

Example

  Given the search field can be located by name "q"
And topic is "Automation"
And topic link can be located by partial link text "${topic}"
When I navigate to "https://google.com"
And I enter "automation" in the search field
And I click topic link if topic link is displayed
Then the page title should contain "${topic}"
<step> if <name> is[ not] defined

Executes a step depending on whether or not an attribute is bound in the global or current scope.

Where

  • <step> is the DSL step or StepDef to potentially execute
  • <name> is the name of the attribute (or StepDef <param> since v4.11.0) to check
  • not include to execute step if attribute is not bound

Example

Given the CSV file: lookup/StateCodes.csv

Code,Name
ACT,Australian Capital Territory
NSW,New South Wales
NT,Northern Territory
QLD,Queensland
SA,South Australia
TAS,Tasmania
VIC,Victoria
WA,Western Australia

The following will bind "New South Wales" in the 2nd record to state name in the global scope

 Given the state code is "UNKNOWN"
When I lookup Name in the "lookup/StateCodes.csv" file as state name where "'${data.record.Code}' == '${the state code}'"
Then unresolved is "true" if state name is not defined
<step> if <name> is[ not] <blank|empty>

Executes a step depending on whether or not an element or attribute is bound to a blank or empty value.

Where

  • <step> is the DSL step or StepDef to potentially execute
  • <name> is the name of the element or attribute (or StepDef <param> since v4.11.0) to check
  • not include to execute step if attribute is not blank

Example

 Given the state code can be located by name "state"
When I navigate to "https://example.com" if the state code is blank
And I navigate to "https://example.com?state=${the state code}" if the state code is not blank
<step> if <name> is[ not] "<value>"

Executes a step depending on whether or not an element or attribute is equal to a value.

Where

  • <step> is the DSL step or StepDef to potentially execute
  • <name> is the name of the element or attribute (or StepDef <param> since v4.11.0) to check
  • not include to execute step if the attribute is not equal to the given value
  • 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" if the state code is "VIC"
And I navigate to "https://example.com?state=Other" if the state code is not "VIC"

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
<step> if <name> <match> "<expression>"`

Executes a step depending on whether or not an element or attribute matches an expression.

Where

  • <step> is the DSL step or StepDef to potentially 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}" if the state code matches regex "(VIC|NSW)"

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

Executes a step depending on whether or not an element or attribute does not match an expression.

Where

  • <step> is the DSL step or StepDef to potentially 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}" if the state code does not match regex "(QLD|NT|wA)"

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
<step> if "<filepath>" file[ not] exists

Executes a step if a file exists (or not).

Where

  • <step> is the DSL step or StepDef to potentially execute
  • <filepath> the path to the file
  • not to execute step if file does not exist (negation)

Examples

   Then call step 1 if "path/to/filename1.csv" file exists
And call step 2 if "path/to/filename2.csv" file not exists
<step> if "<filepath>" file does not exist

Executes a step if a file does not exist.

Where

  • <step> is the DSL step or StepDef to potentially execute
  • <filepath> the path to the file

Examples

    And call step 2 if "path/to/filename2.csv" file does not exist
<step> if "<filepath>" file is[ not] empty

Executes a step if a file is empty (or not).

Where

  • <step> is the DSL step or StepDef to potentially execute
  • <filepath> the path to the file
  • not to execute step if file is not empty (negation)

Examples

   Then call step 1 if "path/to/filename1.csv" file is empty
And call step 2 if "path/to/filename2.csv" file is not empty
<step> if <filepathRef file>[ not] exists

Executes a step if a file exists (or not).

Where

  • <step> is the DSL step or StepDef to potentially execute
  • <filepathRef file> is the name of the binding containing the path of the file
  • not to execute step if file does not exist (negation)

Examples

  Given my file is "path/to/filename.csv"
Then call step 1 if my file exists
And call step 2 if my file not exists
<step> if <filepathRef file> does not exist

Executes a step if a file does not exist.

Where

  • <step> is the DSL step or StepDef to potentially execute
  • <filepathRef file> is the name of the binding containing the path of the file

Examples

  Given my file is "path/to/filename.csv"
And call step 2 if my file does not exist
<step> if <filepathRef file> is[ not] empty

Executes a step if a file is empty (or not).

Where

  • <step> is the DSL step or StepDef to potentially execute
  • <filepathRef file> is the name of the binding containing the path of the file
  • not to execute step if file is not empty (negation)

Examples

  Given my file is "path/to/filename.csv"
Then call step 1 if my file is empty
And call step 2 if my file is not empty
<step> if there is 1 open <tab|window>

Executes a step if there is 1 open tab or window.

Where

  • <tab|window> is either tab or window

Examples

  When I navigate to "https://google.com"
Then call step 1 if there is 1 open window
<step> if there are <count> open <tab|window>s

Executes a step if the given number of tabs/windows are open.

Where

  • <count> is the number of open tabs/windows to check
  • <tab|window> is either tab or window

Examples

  When I navigate to "https://google.com"
And I start a new browser tab
Then call step 1 if there are 2 open windows