加特林记录并不是将所需的cookie传递给每个获取请求

发布于 2025-02-13 01:59:44 字数 2077 浏览 0 评论 0原文

我已经使用加特林记录器录制了测试。但是在每个.get请求脚本将脚本重定向到主页/基本URL,因为cookie没有通过。如何保存cookie,然后将其传递到每个。我已经阅读了HTTP帮助者的盖林文档,但这不是很具体。我显然是对加特林的新手。谢谢!

这是一些示例代码:

private val httpProtocol = http
    .baseUrl("https://branch3.coverageforcompanies.com")


  private val scn = scenario("AgentTest")
    .exec(
      http("Open C4C on Chrome")
        .get("/")
        .headers(headers_0)
        
    )
    .pause(5)
    .exec(
      http("Enter Agent email and password")
        .post("/")
        .headers(headers_4)
        .formParam("_token", "sometoken")
        .formParam("username", "someemail.com")
        .formParam("password", "somepassword")
        .resources(
          http("Click on Sign in and bring up dashboard")
            .get("/a/dashboard")
            .headers(headers_5),
            pause(5)
    .exec(
      http("Click on My Book Link")
        .get("/a/mybook")
        .headers(headers_5)

从第二.get(.get“/a/mybook”)的重定向具有302响应,并重定向到主页。这是日志文件的示例结果:

Request:
Click on My Book Link: OK 
=========================
Session:
Session(AgentTest,1,HashMap(gatling.http.cache.baseUrl ->https://baseurl.com, gatling.http.ssl.sslContexts 
GET https://branch3.coverageforcompanies.com/a/mybook

cookies:
    XSRF-TOKEN=token number
    laravel_session=laravel session number
=========================
HTTP response:
status:
    302 Found
    
    headers:
    Cache-Control: no-cache, private
    Content-Type: text/html; charset=UTF-8
    Location: https://baseurl.com
    Server: Microsoft-IIS/10.0
    X-UA-Compatible: IE=edge
    Set-Cookie: XSRF-TOKEN=token number
    
    Set-Cookie: laravel_session = laravel session number
    Date: Wed, 06 Jul 2022 18:00:10 GMT
    content-length: 406
    
    Request:
Click on My Book Link Redirect 1: OK 
=========================
Session:
Session(AgentTest,1,HashMap(gatling.http.cache.baseUrl -> https://baseurl.com, gatling.http.ssl.sslContexts ->
=========================
HTTP request:
GET https://baseurl.com
headers:

I've recorded a test using the Gatling recorder. But at each .get request the script redirects to the home page/base url because the cookie isn't being passed. How can I save the cookie then pass it into each .get call?? I've read the Gatling documentation for HTTP Helpers but it's not very specific. I'm obviously new to Gatling. Thanks!

Here is some example code:

private val httpProtocol = http
    .baseUrl("https://branch3.coverageforcompanies.com")


  private val scn = scenario("AgentTest")
    .exec(
      http("Open C4C on Chrome")
        .get("/")
        .headers(headers_0)
        
    )
    .pause(5)
    .exec(
      http("Enter Agent email and password")
        .post("/")
        .headers(headers_4)
        .formParam("_token", "sometoken")
        .formParam("username", "someemail.com")
        .formParam("password", "somepassword")
        .resources(
          http("Click on Sign in and bring up dashboard")
            .get("/a/dashboard")
            .headers(headers_5),
            pause(5)
    .exec(
      http("Click on My Book Link")
        .get("/a/mybook")
        .headers(headers_5)

The redirect from the second .get (.get"/a/mybook") has a 302 response and redirects to the home page. Here is a sample result from the log file:

Request:
Click on My Book Link: OK 
=========================
Session:
Session(AgentTest,1,HashMap(gatling.http.cache.baseUrl ->https://baseurl.com, gatling.http.ssl.sslContexts 
GET https://branch3.coverageforcompanies.com/a/mybook

cookies:
    XSRF-TOKEN=token number
    laravel_session=laravel session number
=========================
HTTP response:
status:
    302 Found
    
    headers:
    Cache-Control: no-cache, private
    Content-Type: text/html; charset=UTF-8
    Location: https://baseurl.com
    Server: Microsoft-IIS/10.0
    X-UA-Compatible: IE=edge
    Set-Cookie: XSRF-TOKEN=token number
    
    Set-Cookie: laravel_session = laravel session number
    Date: Wed, 06 Jul 2022 18:00:10 GMT
    content-length: 406
    
    Request:
Click on My Book Link Redirect 1: OK 
=========================
Session:
Session(AgentTest,1,HashMap(gatling.http.cache.baseUrl -> https://baseurl.com, gatling.http.ssl.sslContexts ->
=========================
HTTP request:
GET https://baseurl.com
headers:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰火雁神 2025-02-20 01:59:44

只要服务器将其设置为流程的一部分,GATLING就可以在运行时为您处理cookie。

Gatling的录音机不会记录您在启动录音之前设置的现有cookie,这是有充分理由的:cookie的到期日期,通常不应在多个虚拟用户中共享。您想重播盖林测试,而不是突然破裂,因为录制的饼干已经过期。

您必须在场景中包含登录步骤,以便盖特林虚拟用户可以从服务器接收cookie。

您可能应该以浏览器匿名模式录制,以绕过任何先前存储的cookie。

Gatling handles cookies for you at runtime, as long as the server sets them as part of the flow.

Gatling's Recorder won't record your existing cookies that were set prior to starting the recording for good reasons: cookies have an expiration date, and should usually not be shared amongst multiple virtual users. You want to have your Gatling tests replayable, not suddenly break because a recorded cookie has expired.

You must include your login steps in your scenario so that your Gatling virtual users can receive a cookie from the server.

You should probably record in browser anonymous mode to bypass any previously stored cookie.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文