无法从Jmeter的reg表达式提取器接收值(Cant receive value from reg expression extractor at Jmeter)

我创建了一个包含两个请求的测试计划。 在第一个请求中,我收到一个JSON响应,我从中选择一个身份验证令牌。 在第二个请求中,我应该使用此令牌到达页面,但我得到: Authorization: Bearer ${token}''

第一反应:

{"message":"Success","authentication_token":"UG5FzqsXNb9jnvG8dzbo","token_type":"Bearer","refresh_token":"","user_id":1,"first_name":"John","last_name":"Doe"}

正则表达式:

"authentication_token":"(.+?)"

正则表达似乎没问题。 我用View Results Tree测试了它。 我在第二个请求中仍然有Authorization: Bearer ${token}'' 。

I created a test plan with two requests. In the first request I receive a JSON response from which I select an auth token. In the second request I should reach a page with this token, but instead I get: Authorization: Bearer ${token}''

First response:

{"message":"Success","authentication_token":"UG5FzqsXNb9jnvG8dzbo","token_type":"Bearer","refresh_token":"","user_id":1,"first_name":"John","last_name":"Doe"}

Regular expression:

"authentication_token":"(.+?)"

The regular expression seems to be OK. I tested it with the View Results Tree. I still have Authorization: Bearer ${token}'' in the second request.

最满意答案

解析json的最简单方法是使用JMeter Plugin JSON Path Extractor 。 在这里找到好的例子('解析JSON'副标题)

无论如何,RexExp和Xpath Extractor应该可以工作。 你如何使用它? 你能提供更多细节吗?

The simplest way to parse json - is to use JMeter Plugin JSON Path Extractor. Find good example here ('Parsing JSON' subtitle)

Anyway, RexExp and Xpath Extractor should work. How do you use it? Could you provide more details?

更多推荐