Webinject - 解析 cookie 的内容
我有一个 Webinject 测试用例,需要使用之前收到的 cookie 的内容设置一个附加标头。我的第一个测试用例登录到 Web 应用程序并获取用于识别的令牌。 cookie的部分内容需要设置为附加标头。我怎样才能实现这个目标?
将设置的 Cookie 如下所示:
login=user%40myurl.com; __utma=1.748102029.1314655544.1314657537.1316179965.3; __utmz=1.1316179965.3.2.utmcsr=myurl.com|utmccn=(referral)|utmcmd=referral|utmcct=/subpage; __utma=1.748102029.1314655544.1314657537.1316179965.3; __utmz=1.1316179965.3.2.utmcsr=murul.com|utmccn=(referral)|utmcmd=referral|utmcct=/subpage; JSESSIONID=E976943F6BA0D6FDCC7567BAA5988F77; __utmb=1.3.10.1317046713; __utmc=1; token=44962ede5de74d45b1162a935ee18fbf; identifier=""; login=user%40myurl.com
测试用例如下所示。
<case
id="2"
description1="Logging into Login Page"
method="post"
url="http://myurl.com"
postbody="name=user%40myurl.com&password=12345&fragment=}"
verifynegative="^.*The user name and/or password is incorrect!.*$"
verifyresponsecode="302"
errormessage="Could not login (wrong credentials?)"
parseresponse="token=|;"
logresponse="yes"
logrequest="yes"
>> 这是我想解析 cookie 的地方,但我认为它只是解析响应。
<case
id="3"
description1="Open Subpage"
method="get"
url="http://myurl.com/subpage"
addheader="x-subpage-id:{PARSEDRESULT}"
verifyresponsecode="200"
verifypositive="^.*Title: foo bar.*$"
errormessage="Unable to open View"
logresponse="yes"
logrequest="yes"
>>
这是我想添加附加标头的地方。它一定是我想要解析的 cookie 的部分。
I have a Webinject testcase that needs to set an additional header with the content of a previously received cookie. My first testcase logs into a web application and gets a token for identification. Parts of the content of the cookie need to be set as additional header. How can I achieve this?
The Cookie which will be set looks like this:
login=user%40myurl.com; __utma=1.748102029.1314655544.1314657537.1316179965.3; __utmz=1.1316179965.3.2.utmcsr=myurl.com|utmccn=(referral)|utmcmd=referral|utmcct=/subpage; __utma=1.748102029.1314655544.1314657537.1316179965.3; __utmz=1.1316179965.3.2.utmcsr=murul.com|utmccn=(referral)|utmcmd=referral|utmcct=/subpage; JSESSIONID=E976943F6BA0D6FDCC7567BAA5988F77; __utmb=1.3.10.1317046713; __utmc=1; token=44962ede5de74d45b1162a935ee18fbf; identifier=""; login=user%40myurl.com
The testcases look like the following.
<case
id="2"
description1="Logging into Login Page"
method="post"
url="http://myurl.com"
postbody="name=user%40myurl.com&password=12345&fragment=}"
verifynegative="^.*The user name and/or password is incorrect!.*$"
verifyresponsecode="302"
errormessage="Could not login (wrong credentials?)"
parseresponse="token=|;"
logresponse="yes"
logrequest="yes"
/>
This is where I want to parse the cookie but I think it is only parsing the response.
<case
id="3"
description1="Open Subpage"
method="get"
url="http://myurl.com/subpage"
addheader="x-subpage-id:{PARSEDRESULT}"
verifyresponsecode="200"
verifypositive="^.*Title: foo bar.*$"
errormessage="Unable to open View"
logresponse="yes"
logrequest="yes"
/>
This is where I want to add the addition header. It must be the parts from the cookie I want to parse.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
启用 http.log,并查看第一次测试的结果;您应该会看到“Set-Cookie:”行。这对解析器是可见的,即它被考虑。像这样:
在您的情况下,cookie 应该提供更多信息。然后,parseresponse 允许使用正则表达式,因此如果您可以找出所需内容的分隔符,那么您就解决了。
webinject 邮件列表可以更及时地回答问题。
https://groups.google.com/forum/?fromgroups#!forum/webinject
enable http.log, and look at the result from your first test; you should see a 'Set-Cookie:' line. This is visible to the parser, i.e. it gets considered. Like so:
The cookie should be more informative in your case. Then, parseresponse allows to use regular expressions, so if you can make out the delimiter around what you need, you are settled.
The webinject mailing list answers questions in a more timely manner.
https://groups.google.com/forum/?fromgroups#!forum/webinject