这是加特林录音机脚本。如何使用相关性在加特林中获取票据
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