我在“登录”请求的session =>
中传递.formParam
时收到错误。有人可以帮忙吗?谢谢: - )
这是我的剧本,
// 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")
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)
}
在编译时失败,这是错误:
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)
答案 0 :(得分:1)
import java.util.concurrent.ThreadLocalRandom: - )
答案 1 :(得分:0)
解决。忘了添加
import java.util.concurrent.ThreadLocalRandom