Gang  Yan
Gang Yan

Reputation: 39

Jmeter : How to get first userID from first request and transfer to second request same userId?

I have a script include two HTTP request

1 The first request is User Authentication。include userId.....

2: the second request also includes userId.

The two parameters are consistent。

How to get the first userID from the first request and transfer to second request same userId?

I want to get userID from the first request, not from the response, response body does not include userId, transfer the same userId to the second request.

Here is the first request body:

[

   {"productId":"5551",
   "userId":"${__RandomString(32,44e00d674dee4ff7a2d4f0081991b6d40Bs9Hc)}",
   "service":"200008",
   "app_system":"7.1.1",
   "equipmentId":"866935038314977",
   "app_devicetype":"vivo X20A",
   "app_platform":"Android",
   "app_version":"3.1.3",
   "market":"icash_main"}
] 

Upvotes: 0

Views: 787

Answers (1)

Masud Jahan
Masud Jahan

Reputation: 2978

Use Extractors for the co-relating your requests and responses.

First, you need to extract the userID from the response of your 1st requests.

To do this, choose an extractor (Use JSON Extractor if your requests return the JSON response) and add to your 1st request.

Second, After getting the value of userId through a variable using the extractor, you can use it in your subsequent requests.

Edit:

As you want to use the same userId in both requests, use User Defined Variables in your test plan and add a variable userID in it like this:

enter image description here

In your request body use the variable of userId like this:

{"productId":"5551",
   "userId":"${userId}",
   "service":"200008",
   "app_system":"7.1.1",
   "equipmentId":"866935038314977",
   "app_devicetype":"vivo X20A",
   "app_platform":"Android",
   "app_version":"3.1.3",
   "market":"icash_main"}

Here is the requests body of the two requests which are using the same userId

Body of the Request 1:

enter image description here

Body of the Request 2:

enter image description here

Upvotes: 1

Related Questions