2
votes

Programming Gatling performance test I need to check, if the HTML returned from server contains a predefined string. It 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 features "contains" and "breakOnFailure". Does Gatling something similar?

3

3 Answers

8
votes

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.

2
votes

Here ist the solution

.check(css("h1").transform((s: String) => s.indexOf("Access denied"))
.greaterThan(-1)).exitHereIfFailed
0
votes

You can write it very simple like:

.check(css("h1", "Access denied").notExists)

If you are not sure about H1 you can use:

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

IMO server should respond with proper status, thus:

.check(status.not(403))

Enjoy and see http://gatling.io/docs/2.1.7/http/http_check.html for details

EDIT: My usage of CSS selector is wrong see Stephane Landelle solution with CSS. I'm using substring way most of the time :)