1
votes

So I have the following response after login:

       Response Data: {"status":"ok","userId":"GTBA6520506207","token":"74bb0ba8be426d50"}
Request type : POST

I need to form my Regular expression extractor. What should be the parameters? I am using the following:

Reference name : token
Regular expression : "$token":"(.+?)"
Template: $1$.

Sample Request header:

Request Headers:
Connection: keep-alive
Referer: ****************/
Accept-Language: en-US,en;q=0.5
X-Token: 59d7ff6833495fcc
X-User-Id: R1RCQTY1MjA1MDYyMDc=
DNT: 1
Accept-Encoding: gzip, deflate, br
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0
Accept: application/json, text/plain, */*
Host: **************

The token changes on each login for the login page in Jmeter but for all the other pages the token remains the same and it is not changing. What should I do to solve that?

Jmeter Results Tree:

Login Page - (Token changes on each Jmeter run)

Page 1 Page 2 & Page 3 - Token remains the same.

Thank you

2
Please show your test plan, also do you assign token variable in another place as user parameters?user7294900

2 Answers

2
votes
  1. Add JSON Extractor as a child of the first request and configure it as follows:

    • Reference Name: token
    • JSON Path Expressions: $.token
    • other fields can be left as they are
  2. Add HTTP Header Manager as a child of the 2nd request and configure it to send the following headers:

    • X-Token with the value of ${token}
    • X-User-Id with the value of ${__base64Encode(GTBA6520506207,)}

You need to have Custom JMeter Functions plugin bundle to be installed in order to have __base64Encode() function, you can install Custom JMeter Functions using JMeter Plugins Manager.


If for some reason you cannot use JMeter Plugins you can encode your username using __groovy() function like

${__groovy('GTBA6520506207'.bytes.encodeBase64() as String,)}
0
votes

Use the following expression, Reference name : token Regular expression : "token":"(.+?)" Template: $1$

The above expression will work fine. "${token}" is used to call the loaded token value.

You can also get your work done by using JSON Path Extractor.

Expression for JSON Path Extractor,

Variable names: token JSON Path expression: $..token Match No. : -1 Default Value: 0

Here ${token} is used to call the value of token wherever required.

JSON Path Extractor