ForEach Controller won't run multiple HTTP Requests - jmeter

I have a ForEach Controller that loops over an array of values which works. Inside the ForEach block I have two HTTP requests and one extractor.
ForEach Loop {
+ HTTP Request 1 (This uses attribute from ForEach)
+ Extractor
+ HTTP Request 2 (This uses attribute from Extractor)
}
The first HTTP request runs and the extractor as well but the second HTTP request fails to run.
I've checked the logs and nothing is mentioned about this HTTP Request. I also tried moving the Extractor out from under the HTTP Requestor 1 but that also doesn't work.

There is no problem to have multiple Samplers as ForEach Controller children
The possible reasons for not executing the 2nd HTTP Request are in:
Your extractor fails somewhere somehow, double check that the variable is set and has expected value using Debug Sampler and View Results Tree listener combination
Your 2nd HTTP Request configuration is not correct, i.e. invalid characters in "Server Name" field or unsupported protocol or the request is actually being executed but takes too long, etc. I would recommend looking into jmeter.log file as normally it has enough troubleshooting information

Related

Set the whole request url in jmeter

I have a request, which gives upload url as response body.
{
"uploadUrl": "https://test.com:9000/sample_uploadurl"
}
I'm able to extract the uploadUrl using JSON extractor.
I want to use above upload url to in next http request. How to set the new request here ?
adding directly doent work, because JMeter prepends http/https before request, in this case we already have https.
It got failed because it has https://[https://test.com:9000/sample_uploadurl]
Leave HTTP Request fields empty except Path, put there the variable and it will be executed
As a special case, if the path starts with "http://" or "https://" then this is used as the full URL.
example
The options are in:
Put the whole ${UPLOAD_URL} to "Path" field of the HTTP Request sampler like:
however this approach might be flaky and cause the malfunction of certain configuration elements like HTTP Cookie Manager. So it's better to go for option 2.
Split the ${UPLOAD_URL} into individual components like protocol, host, port and path.
Add JSR223 PostProcessor after the JSON Extractor
Put the following Groovy code into "Script" area:
URL url = new URL(vars.get('UPLOAD_URL'))
vars.put('protocol', url.getProtocol())
vars.put('host', url.getHost())
vars.put('port', url.getPort() as String)
vars.put('path', url.getPath())
The above code will generate the following JMeter Variables
So you should be able to use the generated variables in the next HTTP Request sampler:

How do you have multiple Regular Expression Extractors running in one test plan?

I'm trying to extract variables returned from one HTTP request, use them in a second HTTP request then extract the variables returned from the second HTTP request.
I then need to use both the first extracted and second extracted variables in a third HTTP request.
I can extract the variables from the first HTTP request and use these in the second HTTP request but cant seem to get the variables extracted from the second HTTP request to then use in the third HTTP request.
Is it even possible to do this?
This is my current set up
It should be straightforward and possible as long as both extractors are going into unique variable names. The Debug Postprocessor will show you the values stored in each variable after a test run. What do you see in those in the context of the third http request?

JMeter reponse headers values before redirection on status code 302

I am performing load testing on an API using JMeter. For that, I call an oauth link, which returns a code in the headers which I use for further testing. But the link redirects to another link and I am unable to capture the value of the response headers when a response with status code 302 is returned. How can I do that.
If your situation is like this one:
You can still extract the dynamic value from the latter sample result by modifying Regular Expression Extractor scope
As per documentation:
Apply to:
This is for use with samplers that can generate sub-samples, e.g. HTTP Sampler with embedded resources, Mail Reader or samples generated by the Transaction Controller.
Main sample only - only applies to the main sample
Sub-samples only - only applies to the sub-samples
Main sample and sub-samples - applies to both.
JMeter Variable - assertion is to be applied to the contents of the named variable
By default Regular Expression Extractor is looking into Main sample only, in the above example it is HTTP Request, if the data you're looking for is stored in one of the sub-samples it is enough to change Regular Expression Extractor's scope to look into sub-results as well:
You have 2 options:
Do not allow HTTP request to redirect. Simply uncheck "Follow Redirects" checkbox in the HTTP Sampler:
That way you can process this request normally. The drawback is of course that you need to add a second request which will take you to a link to which you are normally redirected automatically.
Most post-processors allow you to extract value from either main sample, or sub-samples, or both. So follow redirect as before, but change Post-Processor to extract value from sub-sample. For example Regular Expression Extractor:

Manipulating the request body of HTTP thread based on the data extracted from the previous HTTP response

I want to manipulate the request body of HTTP thread based on the data extracted (using 'Regular Expression Extractor') from the previous HTTP response.
Here is the scenario:-
I have extracted the statusFlag and statusId from 'HTTP request 1' as:
Ref name: status
Reg. Exp: "statusFlag":"(\w+)","statusId":"(\w+)"
So, first I want to check that the value of statusFlag is 'New' or not.
If it is New then I have to proceed and feed statusId in next HTTP request or else display statusFlag mismatch.
Need help. Got stuck badly.
I believe Response Assertion is what you're looking for. Add it after the Regular Expression Extractor and configure it as follows:
Apply to: JMeter Variable -> statusFlag (or your reference name)
Pattern Matching Rules: Equals
Add New as a "Pattern to Test"
The assertion will check whether "statusFlag" is "New" and if not - it will fail the sampler and report the expected and the actual value.
Optionally you can add If Controller after the Response Assertion, use ${JMeterThread.last_sample_ok} as a condition and place 2nd request as a child of the If Controller - it will be executed only if "statusFlag" is new.
See How to Use JMeter Assertions in Three Easy Steps guide for more information on conditionally setting pass or fail criteria to requests in your JMeter test.
That's how your Jmeter project should look like.
Regular Expression Extractor stores extracted value in ct variable that can be accessed in If Controller as "${ct}" == "yourvalue" and, if true, can be also sent as a part of Request 2 body using the same ${ct} reference.
Jmeter project structure

Conditionally sending jmeter variables with HTTP request

I am using JMeter to send HTTP POST requests.
My body of the request is JSON, for example something like {"Var1": "${Var1}","Var2": ${Var2},"Var3":"${Var3}"}.
These are set in the parameters of the HTTP requests with no name for the parameter. This works fine and I am able to send requests using the variables that I set in a beanshell pre processor (by setting the variables and using vars.put() ).
My question is how can I send programmatically through the preprocessor part of the parameters? For example:
if(a){
send parameters `{"Var1": "${Var1}","Var2": ${Var2}` as my JSON
}
else {
send parameters `{"Var3":"${Var3}"}` as my JSON
}
vars.remove() doesn't work for me as it removes the value from the variable but still sends it in the request (for example as "${Var1}").
Replace the preprocessor by a Beanshell Sampler that will compute a boolean value a and put it as a var:
vars.put("a", value)
Then use 2 If Controllers where each one will contain a sampler with the different parameters.
Condition of first one will be ${a} and for be it will be the negation of ${a}.
Just use the "Body Data" tab. You can conditionally create the JSON string and then just "print" the variable in the body data using normal placeholders.
The easiest and fastest way of achieving what you want to do is to use the JMeter if controller (Add -> Logic controller -> If controller).
You add an if controller to the Thread Group that you're working on and place your expression that returns a boolean in Condition (default Javascript). As a child node for the if controller you place the HTTP Request sampler that you want to fire in case the if is successful.
Suppose you want to send a request if a property that you are passing to JMeter exists:
${__P(media)}.length > 0
The you add another if controller with a negated condition for what you just checked with another HTTP Request sampler.
You're done.

Resources