gpt4 book ai didi

testing - Gatling 脚本引发错误 "type mismatch"

转载 作者:行者123 更新时间:2023-11-28 21:36:20 26 4
gpt4 key购买 nike

我的脚本有问题,我将它从 HAR 文件转换并分成两个单独的 exec,如下所示。我相信我做得很好(但我不是 100% 确定)

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.core.structure.{ChainBuilder, ScenarioBuilder}
import io.gatling.commons.validation._

class logingood extends Simulation {

val httpProtocol = http
.baseUrl("https://webapi.wage.iteodev.com")
.inferHtmlResources()
.userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36")
.proxy(Proxy("localhost", 8888).httpsPort(8888))

val headers_0 = Map(
"Accept" -> "application/json, text/plain, */*",
"Origin" -> "https://frontend.iteodev.com",
"Sec-Fetch-Mode" -> "cors")

val headers_1 = Map(
"Access-Control-Request-Headers" -> "authorization",
"Access-Control-Request-Method" -> "GET",
"Origin" -> "https://frontend.iteodev.com",
"Sec-Fetch-Mode" -> "cors")

val headers_2 = Map(
"Accept" -> "application/json, text/plain, */*",
"Origin" -> "https://frontend.iteodev.com",
"Sec-Fetch-Mode" -> "cors",
"authorization" -> "Bearer ${authToken}")


val headers_3 = Map("Sec-Fetch-Mode" -> "no-cors")

val headers_7 = Map(
"Origin" -> "https://frontend.iteodev.com",
"Sec-Fetch-Mode" -> "cors",
"content-type" -> "application/x-www-form-urlencoded; charset=UTF-8")

val uri1 = "https://api.wage.iteodev.com/signalr"
val uri2 = "https://frontend.iteodev.com/static/media/download-app-headline.a2c2b312.svg"

val scn = scenario("logingood")
.exec(http("request_0")
.post("/api/oauth/token")
.headers(headers_0)
.formParam("username", "test@evxmail.net")
.formParam("password", "Zaq1@wsx")
.formParam("grant_type", "password")
.check(jsonPath("$..access_token").exists.saveAs("authToken"))
.resources(http("request_1")
.options("/api/account")
.headers(headers_1),
http("request_2")
.get("/api/account")
.headers(headers_2),
http("request_3")
.get(uri2)
.headers(headers_3),
http("request_4")
.options("/api/conversations/")
.headers(headers_1),
http("request_5")
.get("/api/conversations/")
.headers(headers_2),
http("request_6")
.options("/api/notifications")
.headers(headers_1)))

.exec(http("request_7")
.get(uri1 + "/negotiate?clientProtocol=1.5&Authorization=Bearer%20${authToken}&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D")
.headers(headers_7),
http("request_8")
.get("/api/notifications")
.headers(headers_2),
http("request_9")
.get(uri1 + "/start?transport=serverSentEvents&clientProtocol=1.5&Authorization=Bearer%20${authToken}&connectionToken=${MyConnectionToken}&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D")
.headers(headers_7))


setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

但是 Gatling 抛出错误

GATLING_HOME is set to "C:\Gatling"
JAVA = ""C:\Program Files\Java\jdk-12\\bin\java.exe""
10:28:27.322 [ERROR] i.g.c.ZincCompiler$ - C:\Gatling\user-files\simulations\logingood.scala:74:21: type mismatch;
found : io.gatling.http.request.builder.HttpRequestBuilder
required: io.gatling.core.structure.Execs[_]
.headers(headers_7),
^
10:28:27.325 [ERROR] i.g.c.ZincCompiler$ - C:\Gatling\user-files\simulations\logingood.scala:77:21: type mismatch;
found : io.gatling.http.request.builder.HttpRequestBuilder
required: io.gatling.core.structure.Execs[_]
.headers(headers_2),
^
10:28:27.326 [ERROR] i.g.c.ZincCompiler$ - C:\Gatling\user-files\simulations\logingood.scala:80:21: type mismatch;
found : io.gatling.http.request.builder.HttpRequestBuilder
required: io.gatling.core.structure.Execs[_]
.headers(headers_7))
^
10:28:27.371 [ERROR] i.g.c.ZincCompiler$ - three errors found
10:28:27.378 [ERROR] i.g.c.ZincCompiler$ - Compilation crashed
sbt.internal.inc.CompileFailed: null
at sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:253)
at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:122)
at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:95)
at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:91)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:186)
at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$3(MixedAnalyzingCompiler.scala:82)
at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$3$adapted(MixedAnalyzingCompiler.scala:77)
at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:215)
at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:77)
at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:146)
at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:343)
at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:343)
at sbt.internal.inc.Incremental$.doCompile(Incremental.scala:120)
at sbt.internal.inc.Incremental$.$anonfun$compile$4(Incremental.scala:100)
at sbt.internal.inc.IncrementalCommon.recompileClasses(IncrementalCommon.scala:180)
at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:98)
at sbt.internal.inc.Incremental$.$anonfun$compile$3(Incremental.scala:102)
at sbt.internal.inc.Incremental$.manageClassfiles(Incremental.scala:155)
at sbt.internal.inc.Incremental$.compile(Incremental.scala:92)
at sbt.internal.inc.IncrementalCompile$.apply(Compile.scala:75)
at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:348)
at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:301)
at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:168)
at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:248

at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:74)
at io.gatling.compiler.ZincCompiler$.doCompile(ZincCompiler.scala:210)
at io.gatling.compiler.ZincCompiler$.delayedEndpoint$io$gatling$compiler$ZincCompiler$1(ZincCompiler.scala:215)
at io.gatling.compiler.ZincCompiler$delayedInit$body.apply(ZincCompiler.scala:39)
at scala.Function0.apply$mcV$sp(Function0.scala:39)
at scala.Function0.apply$mcV$sp$(Function0.scala:39)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
at scala.App.$anonfun$main$1$adapted(App.scala:80)
at scala.collection.immutable.List.foreach(List.scala:392)
at scala.App.main(App.scala:80)
at scala.App.main$(App.scala:78)
at io.gatling.compiler.ZincCompiler$.main(ZincCompiler.scala:39)
at io.gatling.compiler.ZincCompiler.main(ZincCompiler.scala)
Java HotSpot(TM) 64-Bit Server VM warning: Ignoring option AggressiveOpts; support was removed in 12.0
Choose a simulation number:

我做错了什么?在许多示例中,它看起来很相似并且可以正常工作。我搜索了整个互联网,但没有找到任何解决方案。

最佳答案

exec 执行一个 Action 、一个链或一个可变参数的 Execs。

在包含 request7 的 block 中,您有一个 exec,您在其中尝试传递看起来像 httpRequrestBuilders 的可变参数。

所以代替

.exec(http("request_7")
.get(uri1 + "/negotiate?clientProtocol=1.5&Authorization=Bearer%20${authToken}&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D")
.headers(headers_7),
http("request_8")
.get("/api/notifications")
.headers(headers_2),
http("request_9")
.get(uri1 + "/start?transport=serverSentEvents&clientProtocol=1.5&Authorization=Bearer%20${authToken}&connectionToken=${MyConnectionToken}&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D")
.headers(headers_7))

您需要将它们全部设为 Exec,或者将它们链接起来

.exec(
exec(http("request_7")
.get(uri1 + "/negotiate?clientProtocol=1.5&Authorization=Bearer%20${authToken}&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D")
.headers(headers_7)),
exec(http("request_8")
.get("/api/notifications")
.headers(headers_2)),
exec(http("request_9")
.get(uri1 + "/start?transport=serverSentEvents&clientProtocol=1.5&Authorization=Bearer%20${authToken}&connectionToken=${MyConnectionToken}&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D")
.headers(headers_7)))

我猜您代码段中的第一个 exec 可以正常工作,因为除第一个之外的所有请求都是作为资源完成的

关于testing - Gatling 脚本引发错误 "type mismatch",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58428311/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com