Search code examples
scalagatling

Gatling. Check, if a HTML result contains some string


Programming Gatling performance test I need to check, if the HTML returned from server contains a predefined string. If it does, break the test with an error.

I did not find out how to do it. It must be something like this:

  val scn = scenario("CheckAccess")
    .exec(http("request_0")
      .get("/")
      .headers(headers_0)
      .check(css("h1").contains("Access denied")).breakOnFailure()
      )

I called the wished function "contains" and "breakOnFailure" in the example above. Does Gatling have something similar?


Solution

  • Better solutions:

    with one single CSS selector:

    .check(css("h1:contains('Access denied')").notExists)
    

    with substring:

    .check(substring("Access denied").notExists)
    

    Note: if what you're looking for only occurs at one place in your response payload, substring is sure more efficient, as it doesn't have to parse it into a DOM.