使用Gatling工具进行jsessionid cookie管理

时间:2014-05-09 19:11:16

标签: cookies gatling

我对涉及登录java webapp的 Gatling 模拟进行了询问。

我设置了以下模拟,我很惊讶地发现即使我没有明确地检索并在请求之间设置JSESSIONID cookie,它也能正常工作。

我原本期望得到//AUTHENTICATED REQUEST HERE的评论失败....

有人可以提供见解吗?

class SigninAndAct extends Simulation {

    val baseURL = "http://localhost:8080"
    val httpConf = httpConfig
            .baseURL(baseURL)
            .acceptHeader("*/*")
            .acceptEncodingHeader("gzip, deflate")
            .acceptLanguageHeader("fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3")
            .connection("keep-alive")
            .userAgentHeader("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0")


    val headers_1 = Map(
            "Accept" -> """text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"""
    )

    val headers_2 = Map(
            "Accept" -> """text/css,*/*;q=0.1"""
    )

    val headers_31 = Map(
            "Accept" -> """text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8""",
            "Content-Type" -> """application/x-www-form-urlencoded"""
    )


    val scn = scenario("Signin-scn")
                .exec(http("open-signin-page")
                    .get("/bignibou/signin")
                    .headers(headers_1)
                    .check(regex("""<input type="hidden" name="_csrf" value="(.*)" />""")
                    .saveAs("_csrf")))
                .exec(http("signin")
                    .post("/bignibou/signin")
                    .headers(headers_1)
                    .param("_csrf", "${_csrf}")
                    .param("username","balteo@yahoo.fr")
                    .param("password","------")
                    .check(currentLocation.is(baseURL+"/bignibou/dashboard")))
                .exec(http("open-edit-add-page")
                     .get("/bignibou/advertisement/childminder/edit/32768")//AUTHENTICATED REQUEST HERE
                     .headers(headers_1)
                     .check(currentLocation.is(baseURL+"/bignibou/advertisement/childminder/edit/32768")))

    setUp(scn.users(1).protocolConfig(httpConf))
}

1 个答案:

答案 0 :(得分:3)

那是因为加特林为你照顾这个。它会自动将它们存储在用户的会话中,并将它们传递给下一个请求。