Create a custom validator. Check, if the past of some HTML file contains a substring.

*The sophisticated Scala of Gatling drives me crazy. It sound simple, but after two days I did not find a glue, how to reach it.*

*I have:*

*val scn = scenario("test")
    .check(css("h1").is("Full header")

*I want:*

*val scn = scenario("test")
    .check(css("h1").contains("Part of the header")

*Does somebody have an example to do it?*

Have you given a thought that something that basic is of course already built in?

2Stéphane: Is it build-in?

I did found a possibility to get a substring of the whole response body.


But how to get a substring of the result of the css call? Something like this is needed:


Call specified in the documentation

check(css("*").validate(name, validator))

does not exist.

Use transform to perform the substring on the css selector result.

**It works as**

**check(css("h1").transform((s: String) => s.indexOf("Part of the header")).greaterThan(-1)))**

or (shorter):
check(css(“h1”).transform(_.indexOf(“Part of the header”)).greaterThan(-1)))

or:check(css(“h1”).transformOption(_.flatMap(string => if (string.contains(“Part of the header”)) Some(string) else None)))

check(css(“h1”).transformOption(_.collect { case string if string.contains(“Part of the header”) => string }))