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

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"}
]

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:
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:
Body of the Request 2:

Related

How to add parameters to a HttpRequest programatically in JMeter

I use JMeter in our product performance testing now.
I have a performace test scenario below:
Exract 1000 unique IDs from a request A.
Add the 1000 unique IDs to next request B as "form parameters". check the request B response time.
The request B is like:
Method: Post
URL: http://www.aaa.com/abc/def
Form parameters:
para1 : value1
para2 : value2
ID : ID1
ID : ID2
ID : ID3
......
ID : ID1000
I know this request isn't a Canonical usage of http request. but it is used in our product for years.
Now I get the 1000 unique IDs from request A with the help of "regular expression extractor",
My question is:
how to pass the variables to request B, and set the 1000 IDs as "form parameters" of request B?
Add JSR223 PreProcessor as a child of the HTTP Request sampler where you need to add 1000 parameters
Put the following code into "Script" area:
def data = new org.apache.jmeter.config.Arguments()
1.upto(vars.get('ID_matchNr') as int, index -> {
def parameter = new org.apache.jmeter.protocol.http.util.HTTPArgument('ID', vars.get('ID_' + index))
data.addArgument(parameter)
})
sampler.setArguments(data)
That's it, the JSR223 PreProcessor will read all the JMeter Variables which start with ID_1 and ending with ID_XXXX and add a corresponding parameter to the HTTP Request sampler
More information on Groovy scripting in JMeter context: Apache Groovy - Why and How You Should Use It

Is it possible to pass query parameters in the request body for Clickhouse's http interface?

According to the docs, the Clickhouse's http interface allows me to pass query parameters in a query string like this:
First, I can write a query with a parameter:
SELECT * FROM foo WHERE id = {id:text}
This query is passed in the body request, and the value for id is passed in the query string as follows:
http://clickhouse-host:8123/param_id=1
However, I wonder if there's a way to pass both the query and its parameters in the body request. I could not find how to achieve this in the docs.

Change request parameters name - Laravel

is there anyway to change the parameters name of request in laravel?
something like :
//we have $request['email'] in our request object and we need to change the name of it NOT VALUE
ChangeParaName($request['email'],$request['password']);
//now instead of $request['email'] we have $request['password'] with same value in our request object and just name of parameter changed
You could do this:
$request->merge(['password' => $request->email]);
This will simply put a key called password in $request with value of $request->email.
The email key would still be there.
There are two steps. First of all, you have to merge then you have to unset or remove the old request parameter name.
First merge the request
$request->merge(['password' => $request->email]);
Remove request parameter name
$request->request->remove('email');
I think it will help you.

How to setup nested ForEach Controller and send sub-request on JMeter

I have 3 types of request,
request 1: www.test.com/data
will return data in JSON Array
request 2: www.test.com/img/{img_id}
{img_id} comes from items return by request 1, and requst 2 will return an {uid}
request 3: www.test.com/test/{uid}
I use jmeter to test this flow, now I was able to send request 1 and
then use ForEach Controller to send some request 2, but I don't how to send request 3 according to the response of each request 2
I'm newbie to JMeter , Is anyone could help , Thanks
You need to add one more ForEach Controller nested in the previous one.
So your Test Plan structure will be looks like:
Thread Group
Request 1
RegExpExtractor 1
ForEach Controller 1
Request 2
RegExpExtractor 2
ForEach Controller 2
Request 3
You may use Regular Expression Extractor with -1 as a Match No. parameter to use it in ForEach Controller (from RegExpExtractor 1 to ForEach Controller 1 and from RegExpExtractor 2 to ForEach Controller 2).
Check this Test Plan as an example.

Execute request for each element in CSV, not per user

I'm using jMeter 3.2 to write some tests. I have a CSV file with test account info. Each row contains login info for a user. Each user needs to request a token that is used on later requests.
My test plan:
The get token request retrieves a token. The login requests logs in the user and returns another token. Select customer card selects a customer and returns the final token. The code for the postprocesser is (I'm not experienced in this, so any advice is appreciated):
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
// Check if our map already exists
if (props.get("map") == null) {
JSONObject obj = new JSONObject();
obj.put("${department}", new String(data));
log.info("Adding department to map. Department: ${department}. Token: " + new String(data));
props.put("map", obj.toJSONString());
} else {
// Retrieve the current map
map = props.get("map");
JSONParser parser = new JSONParser();
JSONObject jobj = (JSONObject) parser.parse(map);
// Add the new department (with it's token) to the map
jobj.put("${department}", new String(data));
log.info("Updating map for department. Department: ${department}. Token: " + new String(data));
props.put("map", jobj.toJSONString());
}
Attempt 1:
I'm setting up a once only controller to log in a user and retrieve the token.
Now lets say I have 10 lines in my CSV file but in my test I only want to use 3 users and loop 10 times. What happens is that 3 login requests are sent (one for each user). This works fine for the first iteration. At the 2. iteration the 3 threads will use row 4-6 which doesn't have a token and thereby fail.
Attempt 2:
I'm using an if controller to check whether the token has been set or not. I haven't got this working at all. I added a beanshell preprocessor to the controller where I attempt to retrieve the token. If it's null or empty I set the token variable to "". In the if controller I check for this value. But yeah. No luck yet.
Attempt 3
In Beanshell check if the token is created already. If not, call the test fragment that retrieves it. Unfortunately this seems not possible.
It might be worth noting that I store my tokens in a property, so that all threads can access it.
Please let me know if you need more information.
I figured out a solution. In essence what I tried to do is to store a token for each row in the data file.
I did this by creating a setUp Thread Group which is executed before other thread groups. In this I loop through the data and store a token for each. Now all other thread groups may access these as they run.

Resources