Hello,
In my scenario, I have a request which returns this kind of response :
zone.comp-child-0
"<div class="new-component-container" id="comp-child-0"></div>
<div id="comp-137958433060936283718" class="paragraph new">
…
…
It is a Json with the property “comp-child-0” which contains a Html script.
I would like to get the value of the div whose class is “paragraph new”.
Regards
Hassen
Excilys
2
Hi Hassen,
IMHO, the easiest way would be to use a regex.
If you really want to extract twice: first extract your HTML block with JsonPath, then, parse it with either Jodd or Jsoup (Gatling ships both) inside the transform step: https://github.com/excilys/gatling/wiki/Checks#wiki-transforming.
Jodd’s Csselly is pretty easy to use:
http://jodd.org/doc/csselly/
(in order to get a Document: new LagartoDOMBuilder().parse(string))
Cheers,
Stéphane
Thanks Stéphane
I did something like that :
.exec(
http("**** - Content edition - Insert Paragraph")
.get(“http://…/ajax-content/fr/root.html?webaction=insert&previous=0&type=paragraph”)
.check(jsonPath("$…zone.comp-child-0")
.saveAs(“compchild”)
)
)
.exec(session => {
session(“compchild”).validate[String].map(
compchild => session.set(“compchild”,
new NodeSelector(new LagartoDOMBuilder().parse(compchild)).select(“div[class=‘paragraph new’]”).getFirst().getAttribute(“id”))
)
})
Is it possible to optimize ??
Regards
Hassen
Excilys
4
transform, so that you don’t have to store an intermediate result into the session.
.exec(
http("**** - Content edition - Insert Paragraph")
.get(“http://…/ajax-content/fr/root.html?webaction=insert&previous=0&type=paragraph”)
.check(jsonPath("$…zone.comp-child-0")
.transform(_.map { html =>
new NodeSelector(new LagartoDOMBuilder().parse(html)).select(“div[class=‘paragraph new’]”).getFirst().getAttribute(“id”))
}).saveAs(“compchild”)
)
)