Parameters¶
Parameters may be used within actions, assertions and data providers.
A parameter is prefixed with $
. This denotes that something is a parameter and not a literal value.
There are five types of parameter:
- built-in objects
- test configuration
- data parameters
- element parameters
- environment variables
Built-in Objects¶
Browser properties and page properties are built-in objects that can be referenced in actions and assertions.
Use $browser.{name}
and $page.{name}
to reference these built-in objects.
# examples/step/browser-size.yml
actions:
- set $browser.size to "1024,768"
# examples/step/google-assert-open-literal.yml
assertions:
- $page.url is "https://www.google.com"
- $page.title is "Google"
Test Configuration¶
The config
section of a test is referenced within the test using $config.{name}
.
# examples/test/about-google-verify-opened-page.yml
config:
browsers:
- chrome
url: https://about.google/
"verify about.google is open":
assertions:
- $page.url is $config.url
- $page.title is "About | Google"
Data Parameters¶
Data parameters can be used in actions and assertions. Literal values are replaced with data parameters.
Data is passed to a test step from a test. Data passed to a test step is referenced within the step using
$data.{name}
.
# examples/step/assert-page-open-parameterised.yml
assertions:
- $page.url is $data.expected_url
- $page.title is $data.expected_title
# examples/test/google-open-parameterised.yml
config:
browsers:
- chrome
url: https://www.google.com
imports:
steps:
assert_opened_page_step: "../step/assert-page-open-parameterised.yml"
"verify Google is open":
use: assert_opened_page_step
data:
# Just a single data set needed here
0:
expected_url: $config.url
expected_title: "Google"
Element Parameters¶
Element parameters can be used in the identifiers of actions and assertions. Identifiers are replaced with element parameters.
Elements are passed to a test step from a test. Elements passed to a test step are referenced using $elements.{name}
.
# examples/step/google-query-parameterised.yml
actions:
- set $elements.search_input to $data.query_term
- click $elements.search_button
assertions:
- $page.title is $data.expected_title
# examples/page/google.com.yml
url: "https://www.google.com"
elements:
search_input: $".gLFyf.gsfi"
search_button: $".FPdoLc.VlcLAe input[name=btnK]"
# examples/test/google-imported-steps-with-page-model.yml
config:
browsers:
- chrome
url: google_com.url
imports:
pages:
google_com: "../page/google.com.yml"
steps:
google_query: "../step/google-query-parameterised.yml"
"verify Google is open":
assertions:
- $page.title is "Google"
"query 'example'":
use: google_query
data:
0:
query_term: "foo"
expected_title: "foo - Google Search"
elements:
search_input: $google_com.elements.search_input
search_button: $google_com.elements.search_button
Environment Variables¶
Environment variables can be treated as parameters within actions, assertions and
data providers. Values can be referenced using $env.{name}
.
# examples/data-provider/example-sign-in.yml
user1:
username: $env.TEST_USER_1_USERNAME
password: $env.TEST_USER_1_PASSWORD
user2:
username: $env.TEST_USER_2_USERNAME
password: $env.TEST_USER_2_PASSWORD