Gatling. Check, if a HTML result contains some string

限于喜欢 提交于 2019-12-06 13:41:42

问题


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?


回答1:


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:


Here ist the solution

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



回答3:


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



来源:https://stackoverflow.com/questions/35596668/gatling-check-if-a-html-result-contains-some-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!