Apache Jmeter extracting __RequestVerificationToken and using it to log in

 ̄綄美尐妖づ 提交于 2019-12-11 00:34:06

问题


I am currently using Jmeter to automate this process however I am not able to automate the login process. I have used the following regular expression to extract the __RequestVerificationToken <input name="__RequestVerificationToken" type="hidden" value="([A-Za-z0-9+=/\-\_]+?)">

I then proceed to request the token when attempting to log in

When running the test however I am receiving Response code of 500. When investigating the request data the token is not being pulled correctly


回答1:


Remember not to use regular expressions to parse HTML data. It is a real headache to develop and maintain regular expressions dealing with HTML code, moreover regular expressions are very sensitive to any markup change (line break, extra space, attributes order change, etc.) so I would recommend considering switching to CSS/JQuery Extractor instead. The relevant configuration will be as simple as:

  • Reference name: anything meaningful, tok will be fine
  • CSS/JQuery Expression: input[name=__RequestVerificationToken]
  • Attribute: value

This way you will have robust and reliable way of extracting the __RequestVerificationToken value.

Demo:

See How to Use the CSS/JQuery Extractor in JMeter article for more information.




回答2:


Your regular expression was missing one escaping character:

<input name="__RequestVerificationToken" type="hidden" value="([A-Za-z0-9+=\/\-\_]+)">

You can check regex




回答3:


You have used,

Reference Name: tok

and from Screenshot 2 it's clearly visible that

__RequestVerificationToken=%20%7Btok%7D

So, my guess is you have stored the value in the variable tok but used the variable literally. You have to use ${tok} to replace the value stored in the Reference.



来源:https://stackoverflow.com/questions/46808129/apache-jmeter-extracting-requestverificationtoken-and-using-it-to-log-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!