[Tree]
On top of the "Basic" operations there are some features,
giving the test the ability to become dynamic.
This will register a variable named "USERAGENT" you can use later on if you need.
NOTE: The UserAgent can be set only once (with no difference where it's located), more precisely, only the first one will take effect.
- useragent: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/ Safari/530.5"
- name: set-size
resize: 1366x768
- name: some-task
file: "#uploader_1"
value: "https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg"
- name: some-task
file: "#uploader_2"
value: "http://192.168.8.123/Example.jpg" # For On-Prem installations
- name: some-task
file: "#uploader_3"
value: "data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="
NOTE: As mentioned, "include(d)" tasks are the only ones that don't need a name, because they will be overridden with the tasks of the given file (to include).
- include: "test/sub/disable-alerts.yml"
- name: some-task
vars:
foo: bar
tar: baz
val: 1
- name: "some-${foo}-task"
get: "#${baz} h1"
expect: "to.have.count"
value: ${val}
- include: "test/sub/facebook.yml"
vars:
username: fooBarBaz
password: 1qaz2wsx
Variables can also be overridden.
- name: some-task-87
vars:
foo: 12
- name: some-task-88
get: "#rows li:nth-child(${foo})" # This will be translated into '#rows li:nth-child(12)'
expect: "to.be.hidden"
- name: some-task-89
vars:
foo: 22
- name: some-task-90
get: "#rows li:nth-child(${foo})" # And this will be correctly translated into '#rows li:nth-child(22)'
expect: "to.be.visible"
This is similar to "vars" except that it's being populated during the run from the DOM.
This following code is taken from "test/sub/paypal.yml". It's getting the value of the element with an id "payment_type_paypal" and it "registers" it to the variable called "paypal_subscription".
I do it to determine later on the type of paypal page - Checkout vs Subscription.
NOTE: The registered variable can also override other registered variables.
- name: paypal-check-type
get: "#payment_type_paypal"
register: paypal_subscription
This is a (safe) simple if statement.
It has 4 fields:
- cond : The condition value
- op : The operand
- value : The expected value
- dynamic : Which part is dynamic [cond|value|both]
For now there are the following operands (you're welcome to contact me, see test/LICENSE.md):
- 'in'
- 'lt' or '<'
- 'gt' or '>'
- 'lte' or '<='
- 'gte' or '>='
- 'eq' - String comparison
- '==='
- 'ne' - String comparison
- '!=='
- !! (default, if not given)
As we continue the previous example (register)... We would like to click on the element with an id "payment_type_paypal" if there is value in the dynamic variable "paypal_subscription" (!!paypal_subscription).
- name: paypal-choose-account
click: "#payment_type_paypal"
if:
- cond: paypal_subscription
dynamic: cond
Somewhere later, we would want to click on an element with an id "btnNext" and sleep for 2 seconds if the dynamic (condition) variable fully equals (===) null (or in other words - empty).
- name: paypal-account-login-continue
click: "#btnNext"
sleep: 2
if:
- cond: paypal_subscription
op: "==="
value: null
dynamic: cond
We can include the same script/YAML many times with different variable and have small if's navigating the tasks' flow.
- include: 'test/sub/some-test.tml'
vars:
user_id: 1
- include: 'test/sub/some-test.tml'
vars:
user_id: 2
- include: 'test/sub/some-test.tml'
vars:
user_id: 22
Now inside 'test/sub/some-test.tml' you can have simple conditions like
- name: some-task-15
click: "#some-button"
if:
- cond: ${user_id}
op: ">"
value: 5
... or ...
- name: some-task-51
click: "#some-other-button"
if:
- cond: ${user_id}
op: "==="
value: 2
This is used for scheduled runs. I'm adding nowadays an ability to add tags and schedules ("cron" and "rate") for PRO users.
It'll work this way - you'll simply be able to add tags to each task/step.
- name: some-task-87
⋮
tags:
- nightly
- name: some-task-88
⋮
tags:
- nightly
- name: some-task-89
⋮
tags:
- nightly
- daily
This is a complementary option for the "notify" parameter. It can take one of the 4 values:
- json (Default)
- xml
- junit
- form
NOTE: "form" is used when the receipient can accept only application/x-www-form-urlencoded and multipart/form-data. NOTE: "format" should be used per notify, otherwise, it does nothing.
- name: some-task-87
⋮
notify: "http://example.com"
format: junit # This will send http://example.com
- name: some-task-87
⋮
notify: "[email protected]"
format: "email" # This will send an email with the JUnit result to [email protected]
This is a complementary option for the "get", "set" and "click" parameters. It can take be true or false.
- name: some-task-87
click: "//*[@id='btnNext']"
xpath: true
[Source]