我正在尝试使用Gatling执行负载测试,并且我需要从cookie中保存X-XSRF-TOKEN并将其传递到下一个请求头中。这是我的场景:
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import scala.util.Random
class addvehicle extends Simulation {
object randomIntegerGenerator {
def randomInteger(range: Int) =
scala.util.Random.nextInt(range).toString
}
val feeder = Array(
Map( "Authorization" -> "Bearer XXXX" ),
Map( "Authorization" -> "Bearer YYYY" )
).random
val httpProtocol = http
.baseUrl("https://192.168.165.176:30479")
.inferHtmlResources()
.acceptHeader("application/json, text/plain, */*")
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("IR")
.userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0")
val headers_8 = Map("X-XSRF-TOKEN" -> "f50b2810-ee6a-435b-87d6-5a40dd45bbb1")
val headers_9 = Map(
"Content-Type" -> "application/json",
"Origin" -> "https://192.168.165.176:30479"
val headers_10 = Map(
"Content-Type" -> "application/json",
"Origin" -> "https://192.168.165.176:30479"
val headers_11 = Map("X-XSRF-TOKEN" -> "050e6282-febd-4452-a68b-e88fbc8d3134")
val req = s"""{"entryDate":"2020-10-03","vehicleVersion":"vehicleVersionValue"]}"""
var randomSession = Iterator.continually(
Map(
"randsession" -> (req
.replace("vehicleVersionValue", randomIntegerGenerator.randomInteger(10))
)
))
val scn = scenario("addvehicle")
.feed(feeder)
.feed(randomSession)
.pause(1)
.exec(
http("request_8")
.get("/find/usable?category=Vehicle")
.header("Authorization","${Authorization}")
.headers(headers_8))
.pause(1)
.exec(getCookieValue(CookieKey("XSRF-TOKEN").saveAs("X-XSRF-TOKEN")))
.exec(
http("request_9")
.post("/api/universal/search")
.header("Authorization","${Authorization}")
.header("X-XSRF-TOKEN","${X-XSRF-TOKEN}")
.headers(headers_9)
.body(ElFileBody("C:/Users/test/Downloads/Gatling/user-files/resources/addvehicle/0009_request.json")))
.pause(1)
.exec(getCookieValue(CookieKey("XSRF-TOKEN").saveAs("X-XSRF-TOKEN1")))
.exec(
http("request_10")
.post("/api/vehicle/create")
.header("Authorization","${Authorization}")
.header("X-XSRF-TOKEN","${X-XSRF-TOKEN1}")
.headers(headers_10)
.body(StringBody("""${randsession}"""))
.resources(http("request_11")
.get("/api/bank/find")
.header("Authorization","${Authorization}")
.headers(headers_11),
http("request_12")
.get("/api/vehicle/find?page=0&size=6&sort=createdDate,DESC")
.header("Authorization","${Authorization}")
.headers(headers_11)))
setUp(scn.inject(atOnceUsers(5))).protocols(httpProtocol)
}我想保存Request8Cookie中的X-XSRF-TOKEN并在Request9头部中传递给服务器,如何在此场景下使用check()和saveAs()接口进行多次负载测试?
https://stackoverflow.com/questions/64423791
复制相似问题