If
<step> if[ not] <condition>
Executes a step depending on whether or not a JS condition evaluates to true.
<step> if[ not] <condition>
Where
<step>is the DSL step or StepDef to potentially executenotnegates the condition if included (Since v3.4.0)<condition>is either:Since v3.54.0
- the name of any binding that will return
truewhen the condition is satisfied orfalsewhen it is not
- the name of any binding that will return
Or in prior versions
- the name of a binding containing a javascript function or expression that will return
truewhen the condition is satisfied orfalsewhen it is not - the name of a binding containing a
trueorfalsevalue literal, since v3.50.0
- the name of a binding containing a javascript function or expression that will return
- 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.
<step> if <element> is[ not] <state>
Where
<step>is the DSL step or StepDef to potentially execute<element>is the name of the element to check the state ofnotnegates the state if included<state>is one of:displayedto execute the step if the element is displayedhiddento execute the step if the element is not displayedcheckedortickedto execute the step if a checkbox is tickeduncheckedoruntickedto execute the step if a checkbox is not tickedenabledto execute the step if the element is enableddisabledto 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.
<step> if <name> is[ not] defined
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 checknotinclude 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.
<step> if <name> is[ not] <blank|empty>
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 checknotinclude 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.
<step> if <name> is[ not] "<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 checknotinclude to execute step if the attribute is not equal to the given valuevalueis 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
@Trimannotation can be used on step to trim strings when comparing - The
@IgnoreCaseannotation 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.
<step> if <name> <match> "<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:containsfor partial matchstarts withfor partial leading matchends withfor partial trailing matchmatches regexfor regex matchmatches xpathfor XML matchmatches json pathfor JSON match, since v1.4.0matches templatefor template match, since v2.16.0matches template filefor 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
@Trimannotation can be used on step to trim strings when comparing - The
@IgnoreCaseannotation 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.
<step> if <name> does not <match> "<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:containfor partial matchstart withfor partial leading matchend withfor partial trailing matchmatche regexfor regex matchmatche xpathfor XML matchmatche json pathfor JSON match, since v1.4.0matche templatefor template match, since v2.16.0matche template filefor 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
@Trimannotation can be used on step to trim strings when comparing - The
@IgnoreCaseannotation 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).
<step> if "<filepath>" file[ not] exists
<step> if "<filepath>" file does not exist
Executes a step if a file does not exist.
<step> if "<filepath>" file does not exist
<step> if "<filepath>" file is[ not] empty
Executes a step if a file is empty (or not).
<step> if "<filepath>" file is[ not] empty
<step> if <filepathRef file>[ not] exists
Executes a step if a file exists (or not).
<step> if <filepathRef file>[ not] exists
Where
<step>is the DSL step or StepDef to potentially execute<filepathRef file>is the name of the binding containing the path of the filenotto 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.
<step> if <filepathRef file> does not exist
<step> if <filepathRef file> is[ not] empty
Executes a step if a file is empty (or not).
<step> if <filepathRef file> is[ not] empty
Where
<step>is the DSL step or StepDef to potentially execute<filepathRef file>is the name of the binding containing the path of the filenotto 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.
<step> if there is 1 open <tab|window>
<step> if there are <count> open <tab|window>s
Executes a step if the given number of tabs/windows are open.
<step> if there are <count> open <tab|window>s