# How to resolve type mismatch error in Gatling?

**URL:** https://community.gatling.io/t/how-to-resolve-type-mismatch-error-in-gatling/3403
**Category:** Gatling (Open-Source)
**Created:** [November 23, 2016, 11:26am UTC](https://community.gatling.io/t/how-to-resolve-type-mismatch-error-in-gatling/3403 "2016-11-23T11:26:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@Peter](https://community.gatling.io/u/Peter)
#### Post date: [November 23, 2016, 11:26am UTC](https://community.gatling.io/t/how-to-resolve-type-mismatch-error-in-gatling/3403/1 "2016-11-23T11:26:42Z")

</div>

I am getting error while passing `session =>` in `.formParam` of **“Login” request**. Can anyone help? Thanks 🙂  
Here is my script,

`  
// Random user login logout  
import scala.concurrent.duration.\_  
import io.gatling.core.Predef.\_  
import io.gatling.http.Predef.\_  
import io.gatling.jdbc.Predef.\_  
import io.gatling.core.validation.\_

class mamLoginLogout extends Simulation {

val testServerUrl = System.getProperty(“testServerUrl”, “[https://url](https://url)”)  
val username = System.getProperty(“username”, “TestUser”)  
val password = System.getProperty(“password”, “passwd”)  
val userCount = Integer.getInteger(“userCount”, 10).toInt  
val accountname = System.getProperty(“accountname”, “testrp”)  
val endNum = Integer.getInteger(“EndNumber”, 10).toInt

val httpProtocol = http  
.baseURL(testServerUrl)

val scn = scenario(“Login =\> Browse =\> Logout”)  
.exec(http(“Login”)  
.post("/ma/a/" + accountname + “/login”)  
.headers(headers\_6)  
.formParam(“username”, session =\> username + ThreadLocalRandom.current.nextInt(endNum))  
.formParam(“password”, session =\> password)  
// This script Runs perfact if I use below formParam (So its clear the problem is in above formParam with session =\>, I think it conflicts with below session which is used in .foreach())  
//.formParam(“username”, username)  
//.formParam(“password”, password)  
)

.exec(http(“Browse”)  
.get("/ma/assets/type=media%ofset=1%3Blimit=8")  
.headers(headers\_12)  
.check(jsonPath("$…keyframeId").findAll.saveAs(“IdList”))  
)

.foreach("${IdList}", “id”) {  
doIf(session =\> session(“id”).as[String] != “-1”)  
{  
exec(http(“Set\_Keyframes”)  
.get("/ma/keyframes/${id};width=185;height=103")  
)  
}  
}

.exec(http(“Logout”)  
.get("/ma/logout")  
.headers(headers\_80))

setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)  
}  
`

**Fails at compile time, Here is the error:**

`  
3674 [main] ERROR io.gatling.compiler.ZincCompiler$ - scala:68: type mismatch;  
found : String("${IdList}")  
required: ?{def apply: ?}  
Note that implicit conversions are not applicable because they are ambiguous:  
both method augmentString in object Predef of type (x: String)scala.collection.immutable.StringOps  
and method stringToExpression in object Predef of type [T](string: String)(implicit evidence$1: scala.reflect.ClassTag[T])io.gatling.core.session.Expression[T]  
are possible conversion functions from String("${IdList}") to ?{def apply: ?}

3674 [main] ERROR io.gatling.compiler.ZincCompiler$ - .foreach("${IdList}", “id”) {  
3684 [main] ERROR io.gatling.compiler.ZincCompiler$ - ^  
3695 [main] ERROR io.gatling.compiler.ZincCompiler$ - scala:68: type mismatch;  
found : String(“id”)  
required: ?{def apply: ?}  
Note that implicit conversions are not applicable because they are ambiguous:  
both method augmentString in object Predef of type (x: String)scala.collection.immutable.StringOps  
and method stringToExpression in object Predef of type [T](string: String)(implicit evidence$1: scala.reflect.ClassTag[T])io.gatling.core.session.Expression[T]  
are possible conversion functions from String(“id”) to ?{def apply: ?}  
3695 [main] ERROR io.gatling.compiler.ZincCompiler$ - .foreach("${IdList}", “id”) {  
3695 [main] ERROR io.gatling.compiler.ZincCompiler$ - ^  
3994 [main] ERROR io.gatling.compiler.ZincCompiler$ - scala:53: not found: value ThreadLocalRandom  
3995 [main] ERROR io.gatling.compiler.ZincCompiler$ - .formParam(“username”, session =\> username + ThreadLocalRandom.current.nextInt(endNum))  
3995 [main] ERROR io.gatling.compiler.ZincCompiler$ - ^  
4047 [main] ERROR io.gatling.compiler.ZincCompiler$ - three errors found  
4048 [main] DEBUG io.gatling.compiler.ZincCompiler$ - Compilation failed (CompilerInterface)  
`

Thanks.

---

<div class="post-metadata">

### Author: ![Peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@Peter](https://community.gatling.io/u/Peter)
#### Post date: [November 23, 2016, 1:21pm UTC](https://community.gatling.io/t/how-to-resolve-type-mismatch-error-in-gatling/3403/2 "2016-11-23T13:21:45Z")

</div>

Solved  
I forgot to import this lib.

`import java.util.concurrent.ThreadLocalRandom`
