Second sampler runs in continous loop even when first sampler fails - jmeter

I have an http request sampler1 and extracting a 'JobID' value using regular expression extractor. Now, i have http request sampler2 to check a job status in the same thread group which uses 'JobID' from previous sampler using regular expression extractor. The sampler2 has a while loop controller with condition ${__javaScript("${Status}"!="Ready",)} which is to say keep executing the sampler until status is Ready.
The issue that i am facing is, when the first sampler fails, the second sampler just takes the variable name and keeps trying and never stops because of the while loop.
the second sampler http request gets formed like:
JobID=%24%JobID%7D&request=****
Is there a way to say stop executing the second sampler when first one fails. Any input on this would be of great help.

This is how JMeter works, each thread (virtual user) executes Samplers upside down (or according to the Logic Controllers)
If you want want to execute 2nd sampler only if first one is successful you need to put your While Controller along with the 2nd sampler under the If Controller and use ${JMeterThread.last_sample_ok} as the condition
Where ${JMeterThread.last_sample_ok} is a pre-defined variable holding the result of the previous Sampler

Related

How to run both request/sampler successfully

I am trying to run http samplers sequentially for multiple requests. Where the output of 1 API response is the input of next API request. My concern is when I run with 5 users (for. e.g), then at given point of time it first executes 1st API with 5 users then second API with 5 users, in this process the API where input is required gets lost. Please help me on this.Actually I have used transaction controller also but here not sequentially api run,so getting file not found exception bcause of first api output response parameter is not passed to second api as a input parameter
I need a solution, where all the samplers are first executed for first user, then for second thread all the samplers are executed and so on.
Each JMeter Thread (virtual user) executes Samplers upside down, if you have 2 samplers each user will always run 1st sampler then it will run 2nd sampler.
You can use __threadNum() function and ${__jm__Thread Group__idx} pre-defined variable in order to verify that the execution order is sequential.
If you want all the users to execute first sampler then all users to execute the second sampler - go for Synchronizing Timer
If you want to get to the reason of the failure try saving the responses using i.e. Simple Data Writer as it might be the case your "first" API fails silently and hence your correlation doesn't extract the value.

jmeter is not running script in the order it is written

In jmeter, I'm using nested loop controllers, along with some JSR223 postprocessors inside each loop
Here's the order the script is written:
Loop Controller
Loop Controller
http request
Endloop
JSR223 postprocessor
Endloop
I want the script to first run the http request (multiple times), then after that looping is complete, run the JSR223 postprocessor, then repeat all that.
Instead, what is happening is it enters into the first Loop Controller, then runs the JSR223 postprocessor, then runs the second nested Loop Controller.
Why? How do I get it to run the script in the order in which it's written from top to bottom and nested?
Change from using postprocessor , which is executed for every request in scope, to sampler which executed once
Some elements in the test trees are strictly hierarchical (Listeners, Config Elements, Post-Processors, Pre-Processors, Assertions, Timers), and some are primarily ordered (controllers, samplers). 
Another option is to add it under Sampler which will execute it omce after sampler
JSR223 PostProcessor is being executed after each Sampler in its Scope, in your case after each iteration of the HTTP Request sampler.
If you want to run it only once - either put Flow Control Action sampler at the place of the JSR223 PostProcessor and make the JSR223 PostProcessor a child of the Flow Control Action sampler.
Otherwise you can use JSR223 Sampler instead of the JSR223 PostProcessor, if you don't want the JSR223 Sampler to appear in test results - put SampleResult.setIgnore() function somewhere in your script.

How to filter out last sampler in While controller in JMeter?

My test plan is as follows:
Thread group
\_..other items
\_While controller (with blank condition)
\_Web socket single read sampler
\_..other items
My problem is, because I use blank condition, the While controller executes till the sampler errors out. So my question is, is there a way to filter out this last sampler? There are no other conditions I can use in the While controller as the number of times the child sampler has to be executed is not constant.
Thanks!
Add JSR223 PostProcessor as a child of the WebSocket Single Read Sampler
Put the following code into "Script" area:
if (!prev.isSuccessful()) {
prev.setIgnore()
}
In the above code prev stands for the parent SampleResult and the setIgnore() function tells JMeter to not to collect the result for the given Sampler.
More information on this and other JMeter API shortcuts: Top 8 JMeter Java Classes You Should Be Using with Groovy

JMeter 5.0 - Skip current iteration from pre-processor

My requirement is to ALWAYS validate the input test data before firing the main sampler with that. Given that, I am using throughput shaping timer, I do not want to process the input in another sampler before passing it to the main sampler inside an IF controller. (Since the input processing sampler gets counted against the throughput)
I am trying to set TestLogicalAction programmatically inside a pre-processor for this.
The below line is working properly if I use it inside an assertion.
SampleResult.setTestLogicalAction(TestLogicalAction.START_NEXT_ITERATION_OF_THREAD);
But a variant of the same line is NOT working inside a pre-processor
Attempt1:
ctx.getPreviousResult().setTestLogicalAction(TestLogicalAction.START_NEXT_ITERATION_OF_THREAD);
Attemp2:
ctx.setTestLogicalAction(TestLogicalAction.START_NEXT_ITERATION_OF_THREAD);
Both the attempts are not throwing any errors. But they are not skipping the sampler execution after the pre-processor. How can I achieve this inside a pre-processor?

Why the Sampler doesn't gets executed after correlating by the previous Sampler?

I have the following situation:
There are two Samplers.
I used the Regular Expression Extractor in Sampler No. 1 to extract a parameter from the URL, and used it in the URL of Sampler No. 2
The parameter is extracted successfully, I checked through Debug Sampler. But I see, the Sampler No. 2 is not executed.
No error/warning occurred. Simply, the 2nd Sampler is not executed. And If I do not correlate the 2nd Sampler, it gets executed.
Why, is it so. Any ideas ?
Check jmeter.log for errors and show the structure as text of your test plan using something like:
Test Plan
|
\--Thread Group
|
\---Sampler 1

Resources