gpt4 book ai didi

javascript - 加特林不会保存访问 token

转载 作者:行者123 更新时间:2023-11-28 03:28:34 25 4
gpt4 key购买 nike

在下面的示例中,我可以看到 token 的路径是正确的,因为当我更改它时,我会收到诸如 find.exists 之类的错误。什么也没找到。但由于某种原因我无法保存 token 。我收到“无法构建请求:未定义名为“Token”的属性”

import scala.concurrent.duration._
import io.gatling.jsonpath.JsonPath

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import io.gatling.jsonpath.AST._

class Uus extends Simulation {

val httpProtocol = http
.baseUrl("https://testsite.com")
.inferHtmlResources()
.userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36")

val autentimata = Map(
"Access-Control-Request-Headers" -> "authorization",
"Access-Control-Request-Method" -> "GET",
"Origin" -> "https://testsite.com")

val autentitud = Map(
"Accept" -> "application/json, text/plain, */*",
"Origin" -> "https://testsite.com",
"authorization" -> "Bearer ${Token}")

val uri2 = "https://testsite.com"

val scn = scenario("RecordedSimulation")

.exec(http("savingtoken")
.options("/token/get?rememberMe=true")
.headers(autentimata)
.resources(http("request_2")
.get("/token/get?rememberMe=true")
// .check(jsonPath("$.data.accessToken").saveAs("Token"))
.check(status.is(200), jsonPath("$.data.accessToken").ofType[String].saveAs("Token"))
.headers(autentimata)
.basicAuth("11111111111","P2rooliall"),
http("sisselogitud")
.options("/users/11111111111")
.headers(autentimata),
http("kasutaja lehele")
.get("/users/11111111111")
.headers(autentitud)
//.check(jsonPath("$.data.accessToken").saveAs("token"))
.check(status.is(200)),
http("sündmuste lehele")
.options("/events?page=0&size=25&relation=ASSIGNEE,CREATOR&status=OPEN,REOPEN,FINISHED,ARCHIVED&sort=createdDate,desc")
.headers(autentimata),
http("sündmusteleht")
.get("/events?page=0&size=25&relation=ASSIGNEE,CREATOR&status=OPEN,REOPEN,FINISHED,ARCHIVED&sort=createdDate,desc")
.headers(autentitud)
.header("authorization", "Bearer ${Token}")


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

最佳答案

我认为问题出在这一行:

"authorization" -> "Bearer ${Token}"

从此 block :

 val autentitud = Map(
"Accept" -> "application/json, text/plain, */*",
"Origin" -> "https://testsite.com",
"authorization" -> "Bearer ${Token}")

因为没有定义名为“Token”的属性表明您正在尝试使用尚 undefined variable 。事实上,您仅在场景执行期间保存Token

加特林文档指出 Expession EL :

This Expression Language only works on String values being passed to Gatling DSL methods. Such Strings are parsed only once, when the Gatling simulation is being instanciated.

因此,解决方案是重构代码并将 block 传递到 header 内,即使这意味着代码重复。

您可以尝试通过打印其值来验证您的 token 是否已被提取,如下所示:

.exec{
session=>{
println(" Token value" + session("Token").as[String])
session

}}

关于javascript - 加特林不会保存访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58394535/

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