這是加特林錄音機腳本。如何使用相關性在加特林中獲取票據
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)
如果我們看到這三條線:
.param("""username""", """abc""")
.param("""password""", """abcpwd""")
.param("""lt""", """LT-828-wppjtrEoGU6gj9UVFt3soVqQ3mLMwe""")
我們將使用參數化的用戶名和密碼。這些是我們在運行測試時可以從csv文件獲得的輸入值。這裏「lt」是ticket的參數。它是在我們啓動URL時由CAS生成的。
以下代碼是BaseURL響應的一部分。
<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>
這裏CAS在BaseURL響應中生成票"LT-828-wppjtrEoGU6gj9UVFt3soVqQ3mLMwe"
。在這裏,我需要從BaseURL Response中提取票證,並在登錄請求中使用此票證。
上一頁我使用Jmeter中的正則表達式提取了來自BaseURL Response的name="lt" value="(.*?)"
的票證。
請幫助我如何提取在加特林的機票。
並且你能告訴我如何關聯視圖狀態。
感謝&問候
納拉辛哈
謝謝。我會盡力讓你知道。 – user2571340
嗨notdrft,我需要關聯視圖狀態也。你能告訴我嗎? – user2571340
我不知道那是什麼,你應該花點時間閱讀wiki:https://github.com/excilys/gatling/wiki/Checks。我很樂意隨後以任何方式幫助你。 – notdryft