Unable to capture alpha numeric data using regular expression extractor in JMeter

*爱你&永不变心* 提交于 2019-12-11 12:27:16

问题


I am using regular expression extractor in JMeter to extract the response data which contains something like the following:

Set-Cookie: X-Tr-Auth=b1eada98-ffa1-45a3-522e-591a84dd48f2; Path=/msf; Expires=Fri, 05 Dec 2064 09:25:44 UTC; HttpOnly

The above data is sent from the server after user logs in, I need to use the above authcode to post a JSON body.

I have set the regular expression extractor to the following values:

Reference Name: authcode

Regular Expression: Set-Cookie: "(.+?)"

Template: $1$

Match No. : 1

Default Value: 0

I am getting 0 every time I run the test. I saw a similar question in Stack-overflow with no satisfactory answer. Need expert advise.


回答1:


You should be able to get the cookie value without having to extract it using regex.

  1. Add CookieManager.save.cookies=true line into user.properties file which lives under /bin folder of your JMeter installation
  2. Restart JMeter if it's running (reading properties from file is not dynamic and performen on load)
  3. Add a HTTP Cookie Manager to your test plan
  4. Add a HTTP Header Manager as a child of the request you need to parametrize and configure it as follows:
    • Name: Cookie X-Tr-Auth
    • Value: ${authcode}



回答2:


Try this regular expression,

Auth\=(.*); Path

with remaining settings which you have used.

In this I am expecting you need only authcode value, As Authocde label is constant no need to extract it.



来源:https://stackoverflow.com/questions/27313024/unable-to-capture-alpha-numeric-data-using-regular-expression-extractor-in-jmete

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