As you can see on the herewith image, I'm trying to debug Http requests. So in order to do that I've attached an Listener and a debug post-processor.
The problem is that while my http request's response code is 401, debug post-processor shows me an 200!!
Moreover, in a If Controller I've written this condition: ${JMeterThread.last_sample_ok} == false, and the code under it, is never reached!
Any ideas?
On the Sampler Result tab you see the result related to Debug PostProcessor itself. I.e. in this case it tells you that Debug PostProcessor finished successfully with the Response code=200 and Size in bytes = 1516
Then on Request tab it will show you the configuration of the Debug PostProcessor.
Now if you look at the Response Data tab, this is where you see what Debug PostProcessor actually returned. The thing is it has no ability to show the result of the parent sampler, only its configuration. So as a poster mentioned above, you cannot use it to look at result of the parent sampler. And frankly you don't need to, since you can see the result of any sampler by clicking on it in the View Results Tree, and selecting Sampler Result / Response Data.
The Debug Sampler (and the Debug Post-Processor) doesn't do what I think you think it does.
It isn't debugging in the sense that you might be used to: it won't let you set a breakpoint and step by step through it. Instead, it gives you a list of all of the variables and their values in the "Response Data" tab. This lets you make sure that the variables that you're using are what you think they are.
Because that request- the Debug Request- succeeded, that's what's giving you the 200 response.
A 401 response makes it seem like your Access Tokens aren't being set correctly. I'd check the Debug Sampler and compare the Variables in there to what you're expecting.
Related
All, I need additional assistance. I have tried researching and was using this following resource guide. https://www.blazemeter.com/blog/using-while-controller-jmeter
Problem
I need to Implement a way to wait for a specific Response from the server and record the time it takes from the start of the request to the end where I get a response of Complete in Jmeter. I have been looking at while controller and researching it.
Problem#1
If I add a while controller, my request failed because its adding multiple token. If I leave it without the while controller then it only gets 1 bearer token and it is able to submit a get request and get the response appropriately. I am suspecting there is a pre-procession somewhere else in my script that doing this...
Uses beanshell preprocesser to grab the token
sampler.getHeaderManager().add(new Header("Authorization","Bearer " + vars.get("BEARER")));
Problem #2
I have a GET Request to check the status of the request. Response in the BODY comes back as this json
"{"Status": "RECEIVED", "DllUrl": "", "Message": " "}"
I need it to continue checking for the status of COMPLETE……..also may need to check for failed as well
Was looking at regular Expression extractor to get the status and only stop until it finds COMPLETE status. That way I can measure time start and end time for completion. Any help and guidance will be helpful.
You're adding a header and not removing the previous one therefore it adds another header on each iteration.
In fact you don't need to do any scripting for this, you can just define the header in the HTTP Header Manager:
With regards to extracting this Status value, it's better to do it using JSON Extractor configured like:
Once done you can use the following __jexl3() function to "wait" till the operation finishes:
${__jexl3("${status}" != "COMPLETE",)}
The services I'm trying to test, will work on long pooling method.
They won't give results in first response.
When I run my API script I am not getting full response in first time.
How can I wait in this case for the remaining portion of response to be received?
I want to use values from this response into next call..
In the above screen my response should wait when complete:True
As far as I understand your requirement you need to repeat the Gethotels request until complete attribute becomes true.
In order to accomplish this:
Add a JSON Extractor as a child of the Gethotels request and set it up as follows:
Put your Gethotels request under the While Controller and use the following __jexl3() function as the condition:
${__jexl3("${complete}" != "true",)}
That's it, While Controller loop the Gethotels request until complete becomes true
I want to save the request and response of the sample into a text file, if response assertion is failed.
Here I can save the request and response it to a text file. But I am struck where,
how to check the whether response assertion is passed or failed for the respective sample.
How to validate the is current "Http Request" sample is passed or failed?
Thanks In advance.
Add Beanshell Listener as a child of your HTTP Request sampler which has Assertion(s)
Put the following code into "Script" area:
import org.apache.jmeter.assertions.AssertionResult;
for (AssertionResult assertionResult : sampleResult.getAssertionResults()) {
if (assertionResult.isFailure()) {
//do what you need here
}
}
As Listeners are executed after assertions the listener will have information regarding all assertion results therefore you will be able to conditionally store request/response details into a file.
Be aware that starting from JMeter version 3.0 the Groovy scripting engine is being shipped with JMeter so consider switching to JSR223 Listener and replacing all your Beanshell Test Elements with the JSR223 equivalents, performancewise it would be much better.
Using Jmeter 2.12, what could cause the cookies to fail to reset during a JMeter Loop Controller? I've tried everything I can think of, but each time through the loop, one of the cookies from a previous login still remains. It doesn't seem to actually clear the cookies.
Here is how I put together my loop:
Thread Group 1
-- Loop Controller (3x)
-- Simple Controller
-- HTTP Header Manager
-- HTTP Cookie Manger (with 'Clear cookies each iteration?' enabled)
-- BeanShell sampler - with code that tries to clear all cookies
-- HTTP /login (gets cookies and auth headers)
-- ... various HTTP Samplers ...
-- HTTP /logout
I tried adding a Beanshell sampler with this code (as shown above) but it doesn't seem to do anything:
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.HeaderManager;
CookieManager cManager = sampler.getCookieManager();
cManager.clear();
HeaderManager hManager = sampler.getHeaderManager();
hManager.clear();
Ok, I figured out the problem. Even though the 'HTTP Cookie Manager' has an option called 'Clear cookies each iteration', the 'iteration' it speaks of does not include a Loop Controller. What it refers to is the 'Thread Group' iterations/loops only. This was not clear and I wasted half a day until I figured this out. Wouldn't have been confusing if the checkbox said 'Clear cookies each Thread Group iteration' instead. Very disappointing.
Loop Controller doesn't increment iteration. You can test it by evaluating vars.getIteration() Beanshell code line. Iteration is being incremented on Thread Group level. To override this you can call vars.incIteration() method in any Beanshell-enabled Test Element (Sampler, Pre/Post Processor, Assertion, etc.)
You Beanshell code for clearing cookies actually does nothing as cManager instance isn't being passed back to the sampler. You need to modify your code as follows:
CookieManager cManager = sampler.getCookieManager();
cManager.clear();
sampler.setCookieManager(cManager);
So sampler could have that "cManager" instance with cleared cookies
See How to use BeanShell: JMeter's favorite built-in component guide for more information on Beanshell scripting in Apache JMeter.
I am designing a load test in JMeter.
With the current application that we have whenever a HTTP request is sent, the web server will very occasionally send back a page with a message. To get around this we just have to reload the page. This page could come up for literally any HTTP request.
Is there any way to design a test in JMeter where when a sampler fails, the sampler simply retries?
I'm not sure how I can get a Beanshell sampler to resend a HTTP request.
It is possible via additional Beanshell Assertion
You can re-run arbitrary sampler from the Beanshell Assertion as simple as
ctx.getCurrentSampler().sample(null);
Add a Beanshell Assertion after all other assertions. It matters as assertions are being executed upside-down.
Put the following code into Beanshell Assertion's "Script" area (just change "message" to what your server returns on error.
import org.apache.jmeter.samplers.SampleResult;
if (new String(ResponseData).equals("message")) {
SampleResult result = ctx.getCurrentSampler().sample(null);
if (result.getResponseDataAsString().equals("message")) {
Failure = true;
} else {
SampleResult.setSuccessful(true);
}
}
You'll have only one result recorded.
If assertion passes 1st time - it'll be successful
If assertion fails 1st time and passes 2nd time - it'll be successful
If assertion fails 2 times - it'll be recorded as failed.
For extended information on Beanshell scripting check out How to use BeanShell: JMeter's favorite built-in component guide.
Create such hierarchy:
Thread Group (1 user, 1 second ramp-up, forever)
-While Controller (empty condition = forever)
--Counter (start – 1, increment – 1, reference name – counter)
--HTTP request
---Timer (I prefer constant Timer, responseble for pause betwee retrying)
---BeanShell Post Processor
BeanShell Post Processor should contains(pseudo code):
if(Integer.parseInt(vars.get("counter")>5)
{
prev.setSuccessful(false);
prev.setStopTestNow(true);
}
if(successCondition)
{
prev.setStopTest(true);
}
There is no direct way to achieve it, but I think you can use While controller in conjuction with Regex extractor to resend the failed requests.
Logical flow could be,
1. HTTP request
2. Regex extractor post processor - check response contains failure extract value in msg variable, default is success
3. While controller - run till msg=failure, default value of msg is success
Example screenshot,
Let me know if this works.