Migration from 2.3.1 to 3.4.2

Hi everyone,

I’m currently migrating a bunch of scenarii from Gatling 2.3.1 (Scala 2.12.3) to 3.4.2 (Scala 2.12.12).
I followed the migration guides (https://gatling.io/docs/current/migration_guides/), but still have compilation issues that I can’t figure out how to fix. This may be only due to my poor Scala or Gatling internals knowledge, but I can’t make it through.

Note that all this code was happily compiling and working with version 2.3.1 (for years :-)).
It may be that a prior code flaw of my own is now becoming out as a compilation error due to a stricter compilation setting / type checking / design, but I’m at loss to see why and how to fix it. :’-|

The construct having the issue is a function providing two different checks depending on the app version (small class SemanticVersion stripped from code below):

val pagename = if ( version >= SemanticVersion(“3.2.0”) ) css("#pageName") else regex("""“pageName”\s*:\s*"([^"]*)"""")

which is used such as in:

exec(http(“request”)
.get("/the/uri")
.check(pagename.is(“MY_PAGE”))

This leads to a type mismatch error:
found : io.gatling.core.check.CheckBuilder[_1,_2,String] where type _2 >: jodd.lagarto.dom.NodeSelector with String <: Object, type _1 >: io.gatling.core.check.css.CssCheckType with io.gatling.core.check.regex.RegexCheckType <: Object
required: io.gatling.http.check.HttpCheck

Looks like the type inference is fumbling - or should I explicitly declare the return type for the pagename function? And which type, then?

I tried explicitly declaring the return type to an HttpCheck:
val pagename : HttpCheck = if ( version >= SemanticVersion(“3.2.0”) ) pagenameVersion32OrMore else pagenameVersion31OrLess

But then:
value is is not a member of io.gatling.http.check.HttpCheck

Any clue, anyone?

Thanks a million
Pascal D

Not sure what is happening, could you try forcing the type of pagename to HttpCheck and import io.gatling.http.check.HttpCheck?

Not sure what is happening, could you try forcing the type of pagename to HttpCheck and import io.gatling.http.check.HttpCheck?

Did that already, but not working:

Oh sorry I read half the message… let me investigate.

That’s not possible.
The intermediate steps of the check DSL don’t share a common super type.
For example, “css” has a different “ofType” than “regex”.

The only thing you can do is something like:

val pagename**: HttpCheck** = if ( version >= SemanticVersion(“3.2.0”) ) css("#pageName").is(“foo”) else regex("""“pageName”\s*:\s*"([^"]*)"""").is(“foo”)

That’s not possible.
The intermediate steps of the check DSL don’t share a common super type.
For example, “css” has a different “ofType” than “regex”.

Ah! Ok, that makes a lot of sense.
Now for the sake of understanding, I’m wondering why it did work with version 2.3.x… Internal classes design changed with 3.x ?

The only thing you can do is something like:

val pagename**: HttpCheck** = if ( version >= SemanticVersion(“3.2.0”) ) css("#pageName").is(“foo”) else regex("""“pageName”\s*:\s*"([^"]*)"""").is(“foo”)

Ok, will make the function having a parameter to perform the check as described.
Will let you know how this goes.

Pascal D

Now for the sake of understanding, I’m wondering why it did work with version 2.3.x… Internal classes design changed with 3.x ?

Exactly

Ok, that explains it. :slight_smile:
Performed the said changes - everything is now working ok.
Thanks a lot!