1

This is the Gatling recorder script.

val httpProtocol = http
  // LaunchURL
  .baseURL("https://mywebsite/instance")
  .acceptHeader("*/*")
  .acceptEncodingHeader("gzip, deflate")
  .acceptLanguageHeader("en-US,en;q=0.5")
  .connection("keep-alive")
  .userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0")

  // Login
  .exec(http("request_6")
   .post("""/cas/login;jsessionid=cN7KK9FvXzsqWjmLxL2M5xjk.undefined?service=https://mywebsite/instance/index.jsp""")
   .headers(headers_6)
   .param("""username""", """abc""")
   .param("""password""", """abcpwd""")
   .param("""lt""", """LT-828-wppjtrEoGU6gj9UVFt3soVqQ3mLMwe""")
   .param("""execution""", """e1s1""")
   .param("""_eventId""", """submit""")
   .param("""submit""", """LOGIN"""))
   .pause(10)

If we see these three lines:

.param("""username""", """abc""")
.param("""password""", """abcpwd""")
.param("""lt""", """LT-828-wppjtrEoGU6gj9UVFt3soVqQ3mLMwe""")

We will use parametrization for username and password. these are input values we can get from a csv file while running the test. Here "lt" is the parameter for ticket. it was generated by CAS when we Launch the URL.

The following code is the portion of BaseURL response.

<table width="100%">
  <tr>
    <td>
      <label for="username" class="fl-label"><span class="accesskey">U</span>sername:</label>
      <input id="username" name="username" class="required" tabindex="1" accesskey="u" type="text" value="" size="25" autocomplete="false"/>
    </td>
  </tr>
  <tr>
    <td>                          
      <label for="password" class="fl-label"><span class="accesskey">P</span>assword:</label>
      <input id="password" name="password" class="required" tabindex="2" accesskey="p" type="password" value="" size="25" autocomplete="off"/>
    </td>
  </tr>
  <tr>
    <td>
      <input id="warn" name="warn" value="true" tabindex="3" accesskey="w" type="checkbox" />
      <label for="warn"><span class="accesskey">W</span>arn me before logging me into other sites.</label>
      <input type="hidden" name="lt" value="LT-828-wppjtrEoGU6gj9UVFt3soVqQ3mLMwe" />
      <input type="hidden" name="execution" value="e1s1" />
      <input type="hidden" name="_eventId" value="submit" />
    </td>
  </tr>
  <tr>
    <td>
      <input class="btn-submit" name="submit" accesskey="l" value="LOGIN" tabindex="4" type="submit" />
      <input class="btn-reset" name="reset" accesskey="c" value="CLEAR" tabindex="4" type="reset" />          
    </td>
  </tr>
</table>

Here CAS generated ticket "LT-828-wppjtrEoGU6gj9UVFt3soVqQ3mLMwe" in BaseURL Response. Here, I need to extract ticket from the BaseURL Response and use this ticket in Login request.

Previous i extracted ticket using regular expression in Jmeter as name="lt" value="(.*?)" from BaseURL Response.

Please help me how to extract ticket in Gatling.

and can u please tell me how to correlate View states also.

Thanks & Regards

Narasimha

user2571340
  • 31
  • 1
  • 6

1 Answers1

3

First of all, you will need to make a first GET request to your service as such:

http("getLogin")
  .get(casUrl)

Considering the casUrl val contains the path to your actual service, then, and only then, will you be able to retrieve the information you need, let's say, with a css expression:

http("getLogin")
  .get(casUrl)
  .check(css("input[name='lt']", "value").saveAs("lt"))

Checkers are used to extract data from the body of a request. The saveAs is the important part. It will allow you to record data into gatling's session.

You can reuse it this way:

http("postLogin")
  .post(...)
  ...
  .param("lt", "${lt}")

The brackets are also mandatory : it notices Gatling to try and search in the session the value associated with the key lt.

Here is a full example based on your script:

val casUrl = "/cas/login;jsessionid=cN7KK9FvXzsqWjmLxL2M5xjk.undefined?service=https://mywebsite/instance/index.jsp"

val httpProtocol = http
  // LaunchURL
  .baseURL("https://mywebsite/instance")
  .acceptHeader("*/*")
  .acceptEncodingHeader("gzip, deflate")
  .acceptLanguageHeader("en-US,en;q=0.5")
  .connection("keep-alive")
  .userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0")

  // Login
  .exec(
    http("getLogin")
      .get(casUrl)
      .check(css("input[name='lt']", "value").saveAs("lt")))
  .exec(
    http("postLogin")
      .post(casUrl)
      .headers(headers_6)
      .param("username", "abc")
      .param("password", "abcpwd")
      .param("lt", "${lt}")
      .param("execution", "e1s1")
      .param("_eventId", "submit")
      .param("submit", "LOGIN"))

I took the liberty to remove the triple quotes, which are not necessary in this use case.

notdryft
  • 163
  • 7
  • Hi notdrft, i need to correlate viewstates also. can u please tell me. – user2571340 Aug 21 '13 at 12:10
  • I don't know what that is, you should really take some time and read the wiki : https://github.com/excilys/gatling/wiki/Checks. I'll be glad to help you in any way afterwards. – notdryft Aug 21 '13 at 12:18