Comparing results from two different web sites

Hi,

I’m fairly new to Gatling Scripting. So please pardon some noob questions from me.

I’m building a script that would test if the json response from website A is the same (or a subset) as the json response from website B.

Basically my steps are:

  1. Call website A and save the ids into a list

val scn1 = scenario(“Basic SimilarToTrending”)
.exec(http(“scenario 1 request 1”)
.get(“http://IPAddress:Port/recommendations/similarTo/titles/35f7d582-5bf6-4c2a-a935-d95db10611ea”)
.headers(headers_1)
.check(status.is(200))

.check(jsonPath(“$…titles.id”).findAll.transform(_.mkString(“,”)).saveAs(“idListA”))

)
.pause(250 milliseconds)

  1. Call website B and save the ids in a list

val scn2 = scenario(“Basic SimilarToTrending”)

.exec(http(“scenario 1 request 1”)
.get(“http://192.168.105.59:9000/recommendations/similarTo/titles/35f7d582-5bf6-4c2a-a935-d95db10611ea”)
.headers(headers_1)
.check(status.is(200))
.check(jsonPath(“$…titles.id”).findAll.transform(_.mkString(“,”)).saveAs(“idListB”))
)
.pause(250 milliseconds)

  1. foreach on the elements of idListA and see if it exists in idListB

A couple of questions I have are:

  • I plan to print to console the contents of the idListA as part of debugging but with no success. I’m using the foreach loop. I am assuming here that each element of the idListA is of string type because of the transform I made. here is the piece of code with foreach:

val scn1 = scenario(“Basic Test 1”)
.exec(http(“scenario 1 request 1”)
.get(“http://IPAddress:Port/recommendations/similarTo/titles/35f7d582-5bf6-4c2a-a935-d95db10611ea”)
.headers(headers_1)
.check(status.is(200))
.check(jsonPath(“$…titles.id”).findAll.transform(_.mkString(“,”)).saveAs(“idList”))
)
.foreach(“${idList}”, “ids”){
println(“${ids}”)
})
.pause(250 milliseconds)

Compile error:

GATLING_HOME is set to “C:\gatling”
01:51:51.262 [ERROR] c.e.e.g.a.ZincCompiler$ - C:\gatling\user-files\simulations
\fileName.scala:40: ‘;’ expected but ‘)’ found.
01:51:51.266 [ERROR] c.e.e.g.a.ZincCompiler$ - })
01:51:51.267 [ERROR] c.e.e.g.a.ZincCompiler$ - ^
01:51:51.281 [ERROR] c.e.e.g.a.ZincCompiler$ - one error found
Exception in thread “main” Compilation failed
at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:76)
at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:35)
at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:29)
at sbt.compiler.AggressiveCompile$$anonfun$4$$anonfun$compileScala$1$1.a
pply$mcV$sp(AggressiveCompile.scala:71)

Can someone help me to understand this?

  • After successfully printing the elements in the console, I’m planning to maybe store each elements in an Array. Are all these possible in Gatling?

Thank You guys. Looking forward to all your help.

You shouldn’t be trying to save idListA and idListB in separate scenarios. Just chain both requests.
Then, your compilation error is that you have an extra closing “)” after your foreach, before your pause.
Finally, you can’t pass whatever you want to Gatling foreach, stick to what you can find in the documentation.

For printing in the console something from the Session, do it in an exec: http://gatling.io/docs/2.0.0-RC3/general/scenario.html?highlight=exec#exec