Example
-------
Simple scenario
scenario 'Buy many books' do
step {
action: "Log with default account"
}
step {
result: "Check that user is logged"
}
step {
action: "Select the book 'Harry Potter and the order of the phoenix'"
}
step {
action: "Select the book 'Harry Potter and the goblet of fire'"
}
step {
result: "Check that basket contains 2 books"
}
step {
action: "Pay"
}
step {
result: "Check basket is paid"
}
end
This scenario can be refactored with the introduction of action word named 'choose book'
actionword 'Select book' (title) do
step {
action: "Select the book ${title}"
}
end
So now, the scenario can call the action word
scenario 'Buy many books' do
step {
action: "Log with default account"
}
step {
result: "Check that user is logged"
}
call 'Select book'(title = 'Harry Potter and the order of the phoenix')
call 'Select book'(title = 'Harry Potter and the goblet of fire')
step {
result: "Check that basket contains 2 books"
}
step {
action: "Pay"
}
step {
result: "Check that basket is paid"
}
end
We want to add a new scenario about basket canceling. So we create a new action word named 'login'
actionword 'Login' do
step {
action: "Log with default account"
}
step {
result: "Check that user is logged"
}
end
And an action word to check the number of books in the basket
actionword 'Check book count' (count) do
step {
result: "Check that basket contains ${count} books"
}
end
The new scenario can use these action words
scenario 'A selection can be canceled' do
call 'Login'
call 'Select book'(title = 'Harry Potter and the order of the phoenix')
call 'Check book count'(count = 1)
step {
action: "Cancel basket"
}
call 'Check book count'(count = 0)
end
And the scenario 'Buy many books' can now use the new action words
scenario 'Buy many books' do
call 'Login'
call 'Select book'(title = 'Harry Potter and the order of the phoenix')
call 'Select book'(title = 'Harry Potter and the goblet of fire')
call 'Check book count'(count = 2)
step {
action: "Pay"
}
step {
result: "Check that basket is paid"
}
end
Test elements syntax
--------------------
### Scenario syntax
scenario 'scenario name' do
STATEMENT 1
...
STATEMENT 2
end
with parameters
scenario 'scenario name' (x) do
STATEMENT 1
...
STATEMENT 2
end
A scenario can be tagged
@key1 @key2
scenario 'scenario name' do
...
end
A tag can have a value
@key: value
scenario 'scenario name' do
...
end
### Action word syntax
actionword 'action word name' do
STATEMENT 1
...
STATEMENT 2
end
With parameters
actionword 'action word name' (x) do
...
end
A Parameter can have default value
actionword 'action word name' (x = 0) do
...
end
An action word can be tagged
@key1 @key2
actionword 'action word name' do
...
end
A tag can have a value
@key: value
actionword 'action word name' do
...
end
Statement syntax
----------------
### Call action word
call 'action word name'
With parameters
call 'a actionword'(x = 3, y = '4', z = parameter)
### Create a free step
A free step can contain a test action
step {
action: "act"
}
or an expected result
step {
result: "check"
}
### Assignment
i := 5
### If statement
Simple if
if EXPRESSION
STATEMENTS
end
If with else
if EXPRESSION
STATEMENTS
else
STATEMENTS
end
Comments syntax
---------------
# this is a comment
Expression syntax
--------------------
### Identifier
a
abc
$id
_id
### Numeric operators
4 + 6
a - b
a * b
a % b
a / b
### Comparison operators
a == b
a > b
a >= 5
a <= 5
a in R
### Logical operators
a or b
a and b
not a
### Array
[]
[a, b, c]
### Dictionary
{}
{a: 42, b: "Hello ${name}"}
### Access expression
i[4]
i[key]
i.key
i.x.y
### template
"static template"
"a ${variable} template"
Literal syntax
--------------
### String value
'my string'
### Boolean value
true
false
### Integer value
42
-42
### Float value
42.0
4.2
### Null value
null
### Binary value
0b101010
OB101010
### Hexadecimal value
0x2A
0X2A
### Scientific notation
4E+42
4e-42