Wrapper steps

Wrapper steps allow to 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)
}

This feature is defined in the module cornichon-http-mock and requires to extend the trait HttpMockDsl.

By default, this server responds with 201 to any POST request and 200 for all the rest.

Additionally, it provides three administration features:

The server records all requests received as a JSON array of HTTP request for later assertions.

There are two ways to perform assertions on the server statistics, either by querying the session at the end of the block or by contacting directly the server while it runs.

Refer to those examples for more information.

This feature is experimental and may change in the future.

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