Gatling无法登录该应用程序

时间:2016-11-03 11:08:29

标签: performance cookies gatling

当我执行我的脚本时,登录到应用程序成功。我得到所有的cookie然后随下一个请求发送(每个请求看起来与浏览器中的相同),但下一步失败。失败的步骤是请求“用户”。我得到302而不是200.任何想法在我的场景中可能出错?也许这是cookie策略的问题,例如在JMeter中我可以指定cookie策略和实现。 JMeter中的类似场景有效。我的情景:

import scala.concurrent.duration._

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

class TestScenario extends Simulation {

    val httpProtocol = http
        .baseURL("https://test.test.net")
        .inferHtmlResources(BlackList(""".*\.css""", """.*\.js""", """.*\.jpg""", """.*\.png""", """.*\.gif""", """.*\.ico"""), WhiteList())
        .acceptHeader("application/json, text/plain, */*")
        .acceptEncodingHeader("gzip, deflate, br")
        .acceptLanguageHeader("en-US,en;q=0.5")
        .connectionHeader("close")
        .userAgentHeader("Mozilla/5.0 (Windows NT 6.3; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0")
        //.disableAutomaticReferer

    val headers_standard = Map(
        "Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
        "Accept-Encoding" -> "gzip,deflate,sdch",
        "Accept-Language" -> "pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4",
        "User-Agent" -> "Mozilla/5.0(WindowsNT6.3;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/48.0.2564.116Safari/537.36")

    val headers_referer = Map(
        "Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
        "Accept-Encoding" -> "gzip,deflate,sdch",
        "Accept-Language" -> "pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4",
        "User-Agent" -> "Mozilla/5.0(WindowsNT6.3;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/48.0.2564.116Safari/537.36",
        "Referer" -> "https://test.test.net")

    val headers = Map("Content-Type" -> "application/json;charset=utf-8")

    val uri1 = "https://test.test.net:443"
    val uri2 = "https://test.test.net:443"

    val scn = scenario("Test scenario")
        .exec(
            http("First step")
                .get("/main").headers(headers_standard)
                .disableFollowRedirect 
                .check(
                  status.is(302)
                )
        )
        .exec(
            http("Login Service")
                .get(uri1 + "/login?service= https%3A%2F%test.test.net")
                .headers(headers_standard)
                .disableFollowRedirect
                .check(
                  status.is(401),
                  regex("""input type="hidden" name="execution" value=""").exists,
                  regex("""input type="hidden" name="execution" value="(.+?)"""").saveAs("execution")
                )
        )
        .exec(
            http("Log in")
              .post(uri1 + "/login?service=https%3A%2F%test.test.net")
                .headers(headers_referer)
                .disableFollowRedirect
              .formParam("username", """user""")
                .formParam("password", "pass")
                .formParam("execution", "${execution}")
                .formParam("_eventId", "submit")
                .check(
                    status.is(302),
                    headerRegex("Location", "ticket=(.+).dev").saveAs("ticket")
                    )
        )
        .exec(
            http("Ticket")
              .get("/")
              .queryParam("ticket","${ticket}.dev")
              .headers(headers_referer)
              .check(
                 status.is(200),
                 regex("""<meta name="generator" content="HTML Tidy for HTML5""").exists
                  )
    )
        .exec(
        http("user")
          .get("/user")
          .headers(headers)
          .disableFollowRedirect
          .check(
              status.is(200),
              regex("""Work in the""").exists
              )
    )
        .exec(
            http("Log out")
                .get(uri1 + "/logout")
                .headers(headers)
                .check(
                    status.is(200),
                    regex("""Successful log out""").exists
                    )
      )

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

1 个答案:

答案 0 :(得分:0)

据我所知,您必须启用以下重定向。然后状态响应为200.试试这个。希望它能帮助你......` .exec(             http(“第一步”)                 获得( “/主”)。标题(headers_standard)                 。检查(status.is(200)                 )         )...