Wrapper steps
Wrapper steps let you control the execution of a series of steps to build more powerful tests.
- repeating a series of
steps
Repeat(3) {
When I get("http://superhero.io/batman")
Then assert status.is(200)
}
- repeating a series of
stepswith access to the current iteration index
Repeat(3, "index") {
When I get("http://superhero.io/heroes/<index>")
Then assert status.is(200)
}
- repeating a series of
stepsduring a period of time
RepeatDuring(300.millis) {
When I get("http://superhero.io/batman")
Then assert status.is(200)
}
- repeat a series of
stepsfor each input element
RepeatWith("Superman", "GreenLantern", "Spiderman")("superhero-name") {
When I get("/superheroes/<superhero-name>").withParams("sessionId" -> "<session-id>")
Then assert status.is(200)
Then assert body.path("hasSuperpowers").is(true)
}
- retry a series of
stepsuntil it succeeds or reaches the limit
RetryMax(3) {
When I get("http://superhero.io/batman")
Then assert status.is(200)
}
- repeating a series of
stepsuntil it succeeds over a period of time at a specified interval (handy for eventually consistent endpoints)
Eventually(maxDuration = 15.seconds, interval = 200.milliseconds) {
When I get("http://superhero.io/random")
Then assert body.ignoring("hasSuperpowers", "publisher").is(
"""
{
"name": "Batman",
"realName": "Bruce Wayne",
"city": "Gotham city"
}
"""
)
}
- execute a series of steps
timestimes in batches ofparallelismin parallel and waitmaxTimefor completion.
RepeatConcurrently(times = 10, parallelism = 3, maxTime = 10.seconds) {
When I get("http://superhero.io/batman")
Then assert status.is(200)
}
- execute each step in parallel and wait
maxTimefor completion.
Concurrently(maxTime = 10.seconds) {
When I get("http://superhero.io/batman")
When I get("http://superhero.io/superman")
}
- execute a series of steps and fail if the execution does not complete within
maxDuration.
Within(maxDuration = 10.seconds) {
When I get("http://superhero.io/batman")
Then assert status.is(200)
}
- repeat a series of
stepsfor each element in anIterable(more flexible version ofRepeatWith)
val heroes = List("Superman", "GreenLantern", "Spiderman")
RepeatFrom(heroes)("superhero-name") {
When I get("/superheroes/<superhero-name>").withParams("sessionId" -> "<session-id>")
Then assert status.is(200)
}
- repeat a series of steps with different inputs specified via a data-table
WithDataInputs(
"""
| a | b | c |
| 1 | 3 | 4 |
| 7 | 4 | 11 |
| 1 | -1 | 0 |
"""
) {
Then assert a_plus_b_equals_c
}
def a_plus_b_equals_c =
AssertStep("sum of 'a' + 'b' = 'c'", sc => GenericEqualityAssertion(sc.session.getUnsafe("a").toInt + sc.session.getUnsafe("b").toInt, sc.session.getUnsafe("c").toInt))
- repeat a series of steps with different inputs specified via JSON
WithJsonDataInputs(
"""
[
{ "a": "1", "b": "3", "c": "4" },
{ "a": "7", "b": "4", "c": "11" },
{ "a": "1", "b": "-1", "c": "0" }
]
"""
) {
Then assert a_plus_b_equals_c
}
- WithHeaders automatically sets headers for several steps useful for an authenticated scenario.
WithHeaders(("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==")){
When I get("http://superhero.io/secured")
Then assert status.is(200)
}
- WithBasicAuth automatically sets basic auth headers for several steps.
WithBasicAuth("admin", "root"){
When I get("http://superhero.io/secured")
Then assert status.is(200)
}
-
HttpListenTocreates a temporary HTTP server for testing. See HTTP Mock for full documentation. -
Log duration
By default, all Step execution times can be found in the logs, but sometimes one needs to time a series of steps.
This is where LogDuration comes in handy, it requires a label that will be printed as well to identify results.
LogDuration(label = "my experiment") {
When I get("http://superhero.io/batman")
Then assert status.is(200)
}