I need to call a Rest API ONCE to get a SAML Token to use in the Authorization Header for all other Thread Group/Users in my test. What is the preferred way of doing this? I can see where I can add a header manager and use the variables from there, but it looks like the variable is scoped to the thread group. I assume I can use a property. To make it simple I want one thread group that calls the api to get the token, so it will only call once set some property and all the other thread groups will use the property to get the SAML token. I am newbie so please be nice, it seems like this is a standard thing to do. My plan was a JSON Extractor and somehow use that to set a property.
The easier way is using JMeter Functions instead of Beanshell (moreover Beanshell scripting is a kind of performance anti-pattern). Also you don't need this 2nd "property to variable" conversion.
In 1st Thread Group use __setProperty() function in order to convert JMeter Variable into a property like
${__setProperty(token,${token},)}
In 2nd Thread Group use __P() function to get the token property value like
${__P(token,)}
In general using single SAML token for the multiple threads doesn't seem very good idea to me as normally different users should have different tokens and good load test needs to represent real life situations as close as possible. So I would recommend considering using single token per single virtual user. If you need to pass the tokens across thread groups you can go for Inter-Thread Communication Plugin, it is way easier, moreover you will have confidence that 2nd thread won't start until it receives the token from 1st thread.
I found these thread(s) that helped:
How to get value from property in BeanShell (jmeter)
Still not sure if this is the correct way, but it worked.
I called my REST API to get my Token
I Used a JSON extractor to get the Token
I Set a Global Property to hold my token using a Bean Shell Assertion
props.put("token", vars.get("token"));
In my other thread group I get the token from the property
String token = props.get("token");
vars.put("token",token );
In the HTTP Header Manager I get the token from local variable ${token}
This seems tedious, I am hoping there is better way.
Related
While doing performance testing via JMETER, I encountered one usecase where the POST request call is taking the dynamic data from the website. So in that case when we run our script it fails as that data is no more available on the website.
Payload looks like given below. It is a POST CALL and the payload is changing everytime.
{"marketId":"U-16662943","price":{"up":98,"down":100,"dec":"1.98"},"side":"HOME","line":0,"selectionids":["W2-1"]}
Could anyone suggest how we can make this payload dynamic when we create a script in JMETER?
I can think of 3 possible options:
Duplicate data is not allowed. If this is the case you can use JMeter Functions like __Random(), __RandomString(), __counter() and so on
The data you're sending needs to be aligned with the data in the application somehow, in this case you can use JDBC PreProcessor in order to build a proper request body basing on the data from the application under test database
The data is present in previous response. In that case it's a matter of simple correlation, the dynamic values should be extracted from the previous response using suitable Post-Processors and variables needs to be sent instead of hard-coded parameters
Is there a way for all Receive samplers to ignore specific responses in JMeter and wait for the one that we are interested?
To be more precise, we have created a jmx file that contains a large flow like a user would create on the browser. Each request sent is followed by a response, so we use a request handler followed by the corresponding receive handler for each call. And everything seems to work fine.
But there are cases that another kind of response may arrive, which is not the one we expect in our flow, but it is triggered by another independent mechanism. You can think of it like notifications sent to the user that is doing the flow and are independent of the flow itself, but theu are received in the channel (for us inside the websocket connection).
So we are trying to find a way to ignore a specific set of responses that may come while we are running the tests.
We firstly tried to add a While Controller in each receive sampler that checks if the content is of the desired type and if not loops again. But this solution has 3 disadvantages :
we have to add the sampler for the specific receive twice - one before the while element and one inside the element because we have to first extract the received data and while does not execute its contents before doing the while condition check
we have so many pairs of send-receive in our jmeter test script , that we have to add so many while controllers inside the script
since the received message may not be of the type we expect but another one that we want to ignore, then we cannot add a Response Assertion because it will fail if the notification arrives, so we have to verify the content indirect -> in the condition of the while loop
We use apache-jmeter-5.3.
So we are wondering if we could do another kind of configuration in order to avoid all these while loops.
It may be irrelevant to the solution, but we use websocket through "WebSocket Samplers by Peter Doornbosch".
Thanks
You don't have to, just amend your While Controller's condition to accept undefined variable as well
Sounds like a potential use case for using Module Controller to avoid code duplication
If you're getting the response you don't expect you can change the response body using JSR223 PostProcessor to the one you expect, example code
if (!prev.getResponseDataAsString().contains('foo')) {
prev.setResponseData('foo', 'UTF-8')
}
Sorry for my poor English, and thank you in advance.
I'm trying to make a thread group that makes jmeter logged in our system.
to accomplish this, I need to POST data which contains ID, password, and token.
The token generated every time when the page has opened and hold in hidden value.
So, the usual solution which is like GET response, do the regular expression extractor, and make the value variable and POST it later request doesn't work for me.
since the token become different from when jmeter GET token and POST it.
Then, I found a parallel controller and this might be a solution for me.
but I can't find a way to do it.
also, there are no references in my mother language(Japanese).
I want POST token to certain login action so I need to do regular expression extractor with parallel controller.
then POST the token with ID and password at same time.
I want to know the way of the above or if it's impossible, is there any alternative solution that might work for me.
Thank you a lot for your help.
Don't worry about language at all :)
I will add a solution according to how I understand your problem.
As I understood, your scenario is,
We Request a page
We will get a response with token
We fetch the token and send the next request with the token
We will get a response with a different token
Need to fetch the new token and send another request
In this case, I think you are trying to use the first token in all the requests. Without doing that what if you fetch the token per each request?
The problem with the parallel controller is if you want to fetch the token from a previous request. It might not work.
Please correct me if I haven't understood the question correctly
Parallel Controller is not something you should be using, it's for simulating AJAX requests as JMeter cannot execute JavaScript like browser does and hence cannot run multiple HTTP request samplers in parallel with one virtual user.
Your test plan structure should be much simpler, to wit:
HTTP Request sampler (to get login page)
a Post-Processor (most probably you're looking for CSS Selector Extractor) to get the values from hidden fields
HTTP Request sampler (to perform login)
See Variabilize and Correlate the script chapter for more details on the concept
In light words the problem could be stated as "I am setting an environment variable in one transformation t1.ktr and using the variable in another transformation t2.ktr. I want to update the variable every 15 mins without actually stopping the t2.ktr i.e. during the execution of t2.ktr . How can I achieve that ?
To give you an overview :
I am making rest api call using HTTP POST step in my transformation (multi-threaded). To make this rest api call I need to pass a certain Token which gets expired in every 15 mins. I am getting this token via another API call. So in one transformation lets say token.ktr I am getting the token and storing it in environment variable TOKEN via Set Variable step and in next transformation lets call it rest.ktr I am getting this variable via Get Variable step and using it in HTTP POST call.
For 15 min I get proper responses, but after that I get error responses since token gets expired.
Let me know if further clarification is needed.
I've had a similar case that i produced a sequence of KTRs in a Job with Evaluations.
I achieved this with a Job and 2 KTRs
DISCLAIMER - For my case, i have to make several HTTP GET's, not just a single long one, so i can easily loop from one GET to another and check the Expiration of the Token bettween HTTP GETs, this is how i achieved it.
Step 1:
Start your KTR that has the Auth API Call. In this KTR you'll also use a formula step, creating a DateTime row using the NOW() function, this will get the timestamp of when you called the Authorization. This KTR will end by setting the Auth and this timestamp as variables in the Parent job.
KTR1 - Example
Step 2:
In the Job you will call this KTR first, and right after it, you'll use a Set Variables step, i named this variable Expiration, and here you'll set it to OK, signaling Token not expired. Next you'll call the KTR that makes the HTTP GET, using the Token. The result of this KTR will be Success (not expired token, success on HTTP GET, moves on), or Fail (Token expired, set Expiration to "Expired").
JOB Example
Step 3:
After the HTTP GET you need to check to result, whether or not it succeeded, or if the token expired mid way, so you would need to renew token and continue the loop, or end the loop if no more HTTP GETs are needed.
Again, this is for a very especific use case, and i'm sure other people can do better, but, this is my take on the issue, it works for me.
I have 3 Rest API's, each one of them dependent on each other, how to create test plan for them, jmeter firing those urls non sequential order i want it in Sequential order, when i check on "view result tree" i am getting 403 error.
Are they in the same thread group? If so, they ought to fire sequentially in order.
If the three are dependent on each other you need to take following steps:
Add thread group
Put the API's one after the other based on the values and dependency.
Extract the value from the first API and pass it to the next using Post Processors like Regular Expression Extractor or JSON extractor.
You are seeing 403 which is related to forbidden access, it means that you are not allowed to access that particular URL or missing some authentication token or cookies or username/password.
So add the authorization manager to your test plan if that's missing and send appropriate values.