Wrapper steps

Wrapper steps let you control the execution of a series of steps to build more powerful tests.

Repeat(3) {
  When I get("http://superhero.io/batman")

  Then assert status.is(200)
}
Repeat(3, "index") {
  When I get("http://superhero.io/heroes/<index>")

  Then assert status.is(200)
}
RepeatDuring(300.millis) {
  When I get("http://superhero.io/batman")

  Then assert status.is(200)
}
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)
}
RetryMax(3) {
  When I get("http://superhero.io/batman")

  Then assert status.is(200)
}
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"
      }
      """
    )
  }
RepeatConcurrently(times = 10, parallelism = 3, maxTime = 10.seconds) {

  When I get("http://superhero.io/batman")

  Then assert status.is(200)
}
Concurrently(maxTime = 10.seconds) {

  When I get("http://superhero.io/batman")

  When I get("http://superhero.io/superman")
}
Within(maxDuration = 10.seconds) {

  When I get("http://superhero.io/batman")

  Then assert status.is(200)
}
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)
}
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))
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(("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==")){
  When I get("http://superhero.io/secured")
  Then assert status.is(200)
}
WithBasicAuth("admin", "root"){
  When I get("http://superhero.io/secured")
  Then assert status.is(200)
}

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)
}