User Defined Value (Date) is changing within Jmeter test plan - jmeter

I have user defined variable for date: Date1 | 31-Jul-2018.
Now I am using this variable within my test plan, and on each iteration, I will be decrementing the date too for which I have code in JSR223 processor but that gets executed at the end of first iteration.
The issue I am facing is that in the beginning of the test plan, date is being displayed correctly within my SQL query, but then towards the end of the test plan when I need to use the date again, Date value has changed and showing some random value like - '03-Jul-0208'. Just an fyi - we haven't reached the Date decrement code yet when i start getting this random value.
Test plan structure:
I have no idea why this is happening.

Just FYI you have reached the Date decrement code as soon as you executed JDBC_SelectDCNfromTemp sampler first time.
JSR223 PostProcessor is being executed after each Sampler in its scope so most probably the error is in your code which you're unwilling to share.

Related

How to update the array values from existing based on the condition and again pass same array with updated array element

We are using for each control to iterate an array based on matchNr count. First time My application is sending all reports call to server together , next time after 10 sec delay again my application sending the same reports calls which are not get completed in first time and so on.
Ex. suppose application is having 10 reports then first time 10 requests goes, then again same request goes by eliminating the completed one (this request count should be less or equal to earlier one)
Note:
Application is having different report count for each users. we can not put fix reports to all users.
Request is same here, only application is adding report name in the body part of the request.
We are trying to simulate chrome behavior with Jmeter during load test.
Array is having the total report count[image1]
request is same only parameter is getting change for each request[image2]
ForEach Controller doesn't execute its children "together"
We are not telepathic enough to guess how does you "array" look like and how exactly you want to "update" it
If you have JMeter Variables in form of:
foo_1=something
foo_2=something else
....
foo_matchNr=number of matches
and want to update the variables with some "new" values there are 2 options:
Set Variables Action sampler (can be installed using JMeter Plugins Manager)
Or any suitable JSR223 Test Element, any of them has vars shorthand for JMeterVariables class instance providing read/write capabilities for JMeter Variables in current thread's scope.

Jmeter-While controller is not exiting from loop

I have JDBC request which has modified_date which will populate with value depends on payload size. For small payload it will populate the date and time value immediately, for large size it will take from 10 to 30 minutes.
I have added JSSR223 post processor for JDBC request and i am capturing the modified_date and saving in variable "modified". I have added while controller with ${__javaScript(vars.get("Modified"))=="null"} and added same JDBC request with constant timer.
So the while controller keeps looping and it is not stopping or exiting after the value is populated for modified_date. Can you please help.
As per documentation
Variables, functions (and properties) are all case-sensitive.
So Modified and modified are different beasts, you need to mind the case and change the While Controller's condition to ${__javaScript(vars.get("Modified"))=="null"}
Also you don't need any scripting in order to save JDBC Request sampler result into a variable, just define it under "Variable names" section:
and given your query returns a single result you will have it in ${modified_1} JMeter Variable.
More information: Debugging JDBC Sampler Results in JMeter

JMeter - Why is my variable being re-evaluated midway through my test?

I posted this question originally in a much more complicated way, but I've reproduced the issue more simply now so I'm extensively editing my post.
I have a simple Test Plan to exercise an API.
The first thing it does is create a session with a simple HTTP POST. We then extract the session ID from the response using the JSON Path Extractor plugin:
This reads the newly created session's ID into a variable called id_JSON, and subsequent PUT requests use the session ID in their path, i.e. /api/sessions/${id_JSON}/account.
This generally works well, but I have noticed that intermittently, id_JSON will suddenly have the default value NOT_FOUND. Samples will fail and when I look at the request, I can see that it was trying to hit /api/sessions/NOT_FOUND/account instead of a valid ID. What's really confusing me right now is that this will happen after requests have already successfully referenced ${id_JSON} and generated a valid path. It seems like this should be impossible, unless the value of id_JSON was being dynamically checked or looked up repeatedly - otherwise how is it coming up with a different value from one request to the next?
It seems that if any Sample fails, for any reason, subsequent requests in the same thread iteration all fail with id_JSON having the default value NOT_FOUND.
Do I need to declare or manage the variable id_JSON in any special way to ensure that it will get the value of the session ID and retain it throughout the thread iteration, until the next iteration overwrites it with the next session ID?
The Extractor is a Post Processor, meaning it is applied after each sampler. So in you case it will run on the First Get and the 4 Puts.
So what you are noticing is absolutely regular, and if a Sampler fails, the extractor will fail to extract the ID and put NOT_FOUND in value.
If you are sure it does not change, then just put the Post Processor as a child of the first HTTP Request called "Create Session", it will then only run for it and the variable will not change anymore.
You can read more on this at:
http://jmeter.apache.org/usermanual/test_plan.html#scoping_rules
"Go to next loop iteration" operates on Thread Group level.
Using any nested loop controllers doesn't increment global iteration counter. You can test it with either:
${__BeanShell(vars.getIteration();)} function - if you use vanilla JMeter
iterationNum function - if you use JMeter Plugins
So if you move your "looping" on Thread Group level and remove nester Loop Controller(s) (or set their loop count to 1) your approach should work as you expect it to do.

how to use jmeter functions in loop controller

My test plan is below
!TestPlan
ThreadGroup
LoopController1
Sampler1
BeanShellPostProcessor
Listener
LoopController2
Sampler2
As part of Beanshellpostprocessor, i am putting count value to a variable
props.put("noOfRecords",vars.get("msg_#"));
Now this value i am placing on 2nd loopcontroller as ${__P(noOfRecords,0)}
This setup is failing for iterations where we don't have any records. So the previous "${__P(noOfRecords,0)}" value is considered while running the Loop2.
Is there any other way we can achieve the dynamic loop counter?
You can use variables or properties in the Loop Controller to change the loop count at run time.
If the Property/Variable is set correctly by the Beanshell postprocessor in your test, It should work. That is, you need to set the value to 0 explicitly when there is no record. Otherwise Properties (which are not destroyed until you close JMeter) might use the previous value.

Jmeter increment a variable after loop

I have a test that loops as suggested here:
Is it possible to loop a test in JMeter?
I have a Thread Group with 100 users and a loop count of 5.
A Runtime Controller to run for 30 seconds.
Now when the Runtime Controller finishes I would like to increment a variable that I can read inside my BeanShell sampler in my test. At the end of the test this variable should be equal to the loop count.
Ok figured it out!
I used a Counter element and set it to "Track counter independently for each user".
The variable increments only after each loop.
Also very important the Counter has to be under Thread Group but not inside the Runtime Controller.
Since you use Beanshell you can access current loop number as simple as
vars.getIteration();
See JMeterVariables class JavaDoc to see what else could be done using it, How to use BeanShell: JMeter's favorite built-in component guide for advanced information on Beanshell scripting in Apache JMeter and remember that the method will work only on Thread Group level, the value won't increment inside Loop Controller

Resources