Gatling in scala how to get url from redirect
Asked Answered
A

1

8

I using gatling ver 2.3.0 in scala. Is it possible after send request get a url from redirect to variable? e.g. I request for 192.168.1.30:8080/ and this link redirect me to 192.168.1.30:8080/token/123, can I get /token/123? I tried with this code but occurs error header.find.exists, found nothing but in Fiddler I see this header

 val httpConf = http
        .baseURL("http://192.168.1.30:8080")
 .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
            .acceptEncodingHeader("gzip, deflate")
            .acceptLanguageHeader("en-US,en;q=0.5")
            .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")

val scn = scenario("SCENARIO2")
.exec(http("open")
  .get("/")
  .check(header("Location").saveAs("url")))
.exec(session => {
  val urlN = session.get("url").asOption[String]
  print(urlN.getOrElse("nothing"))
  session
})
Andradite answered 13/9, 2017 at 9:38 Comment(1)
Not quite sure if this answers your question but Gatling follows redirects automaticallyLoop
A
8

I know what is wrong with redirect this is answer on my question: 1) I should add to httpConf .disableFollowRedirect and .check(status.is(302)) to scenario

val httpConf = http
    .baseURL("192.168.1.30:8080") // Here is the root for all relative URLs
   .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // Here are the common headers
    .acceptEncodingHeader("gzip, deflate")
    .acceptLanguageHeader("en-US,en;q=0.5")
    .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")
    .disableFollowRedirect

val scn = scenario("SCENARIO2")
    .exec(http("open")
      .get("/")
      .check(status.is(302))
      .check(header("Location").saveAs("url")))
    .exec(session => {
      val urlN = session.get("url").asOption[String]
      print(urlN.getOrElse("nothing"))
      session
    })
Andradite answered 14/9, 2017 at 13:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.