Testing Keywords
Keywords for test setup, assertions, and test variations.
Setup Keywords
given:
Declarative test setup. Describes the initial state.
Scenario-level:
scenario: checkout
given:
@customer is logged in
cart has items
$total: number is 1200Event-level:
on :checkout from @customer (api)
given:
$discount_code is "SUMMER20"
? discount is valid
apply discountexpect:
Defines assertions to verify outcomes.
Event-level:
on :checkout from @customer (api)
order moves to #processing
expect:
= order is in #processingScenario-level:
scenario: complete purchase
on :checkout from @customer (api) ...
on :payment_success from @payment ...
expect:
= order is in #paid
= @customer received :confirmationGuard Keywords
otherwise
Default case when no guards match.
? $total > 1000
priority becomes "high"
? $total > 100
priority becomes "medium"
otherwise
priority becomes "low"Equivalent to empty ?:
? $total > 100
apply discount
?
no discountTest File Keywords
test:
Defines a test file for a machine or system.
test: @order
test: system checkoutfor scenario:
Targets a specific scenario for testing.
test: @order
for scenario: checkout
// tests for checkout scenariofor :event:
Targets transition tests for a specific event handler.
for :checkout:
empty cart rejected:
with scenario:
cart is empty
= @customer received :errorfor :event to @actor:
For system tests, targets an event to a specific machine.
for :checkout to @order:
guest rejected:
// test variationsVariation Keywords
with scenario:
Overrides scenario-level given block.
with scenario:
cart is empty
@customer is not logged inwith event:
Overrides event data/payload.
with event:
payment_method is "bank_transfer"with given:
Overrides event-level given block.
with given:
shipping_address is invalidwith context:
Overrides context variables.
with context:
$total is 5000
$retry_count is 2Behavior Control Keywords
assume:
Controls guard/action behavior for the test.
assume:
? cart is valid = false
process payment throws "Error"
send email returns { status: "sent" }observe:
Watches actions without changing behavior.
observe:
send confirmation email
update inventory
= send confirmation email was called
= update inventory was not calledResponse Assertion Keywords
= reply status is
Verifies the HTTP status code of a reply.
expect:
= reply status is 201
= reply status is 400= reply.field
Verifies a field value in the response.
expect:
= reply.id is not empty
= reply.status equals "awaiting_payment"
= reply.customer.name equals "John"= reply contains / does not contain
Checks for field presence in response.
expect:
= reply contains id
= reply does not contain tracking= callback for :event was sent
Verifies async callback delivery.
expect:
= callback for :generate_report was sentPath Divergence Keywords
after
Specifies divergence point in scenario tests.
payment fails:
after :checkout
receive :payment_failed
= order is in #failedreceive
Specifies event received after divergence.
after :checkout
receive :payment_failed from @paymentthen
Continues event sequence after divergence.
after :checkout
receive :payment_failed from @payment
then :payment_success from @payment
= order is in #paid