Home > front end >  JMeter - RegEx Extractor seems correct but request header has ${token} instead of value
JMeter - RegEx Extractor seems correct but request header has ${token} instead of value

Time:10-18

Set-up

Request #1

POST https://url/

RegEx Extractor

enter image description here

Response #1

{
 "Token":"WkQTxNnZRR0nofyJzb-kioALlXgwc7cN9rokXrKzWmtB2BDedUXeQnd94S5KWvaz0",
 "ExpirationUTC":"2121-09-17T14:39:57.504Z",
 "TokenId":"string"
}

Request #2

GET https://some-other-url

Header Manager

As shown: enter image description here

Result

Instead of Authorization: Bearer WkQTxNnZRR0nofyJzb-kioALlXgwc7cN9rokXrKzWmtB2BDedUXeQnd94S5KWvaz0 we have Authorization: Bearer ${token}

enter image description here

Debug Component Results - Starting to Look Like a Variable Scope Issue

enter image description here ... but: enter image description here

Result of RegExp Tester

Here, I used the same reg-ex as I used in the Reg Ex Extractor, and it finds the desired string.

enter image description here

JSON Extractor Attempt

enter image description here

Still says Bearer ${token}

CodePudding user response:

As per JMeter Documentation Variables are local to a thread hence you cannot refer the variables which are set in one Thread Group in another Thread Group.

You either need to convert the variable into a JMeter Property using __setProperty() function in 1st thread group and load it using __P() function in 2nd thread group or go for Inter-Thread Communication Plugin

Also be informed that JSON is not a regular language hence using regular expressions is not the best choice for extracting the token from the response

  • Related