How to handle Jmeter tests - jmeter

Measuring the load time of an ( web-based application)
When a user clicks on a link, the web-based Application sends a Request to the server
I have tried to take the above post request and loop it under While loop controller with a condition.
But the while loops just loops forever.

There are following possible origins for these requestId dynamic variable:
It may be present in response URL as the result of a redirection
It may be present in response headers
It may be present in response body
It is generated on the client side (browser) using JavaScript
In first 3 cases you need to correlate the value using a suitable post-processor, in 4th case you need to replicate the JavaScript code which is generating the value using JSR223 PreProcessor and Groovy language
We cannot comment anything on your While Controller issue apart from very obvious statement that the While Controller will execute its child(ren) until the variable or function which you put in the "Condition" are resolves to true, the evaluation result including any nested variables can be observed using i.e. Debug Sampler

Related

Jmeter does not expand variables when itself stressed

My Jmeter test plan is setting a token variable using a Regular Expression Extractor (a Post-Processor element), but upon a while this variable is not expanded in its value and as consequent ${token} is sent to the REST API under actual test.
I added Constant Delay Timer elements in between each request a user (thread) sends and it seems to overcome the problem to a great extend but not entirely. I still get some Bad Request from the API side.
I provide a screen capture
And a second screen capture showing the full test plan (or a large portion of it)
Can someone please explain why this happening and somehow resolve it ?
It might be the case your Regular Expression Extractor fails to find the value therefore it falls back to the default (undefined) value of ${token}
My expectation is that under the load your application cannot properly respond, to wit response doesn't contain the token. You can double check it using Debug Sampler and View Results Tree listener combination.
You can temporarily enable saving of response data by adding the next lines to user.properties file:
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data=true
and next time you run your test in command-line non-GUI mode JMeter will keep response data for all samplers. You should be able to examine the responses and add a Response Assertion to ensure that the token is present in the POST LOGIN sampler response data

How do I record a script in JMeter which adds a record in a website?

Currently, I am recording a script in jmeter by which I am adding a record in a website , but a problem is that while recording a script I am able to add a record in a website, but once recording has been done and after that if I will run a script again then, a script is not adding a record in a website.
can you please help me with this?
In the absolute majority of cases you will not be able to replay the recorded script without performing correlation.
Modern web applications widely use dynamic parameters for session management or CSRF protection so once you record your test you get "hardcoded" values and they need to be dynamic.
Assuming all above my expectation is that your test doesn't add record due to failed login or something like that. Inspect requests and responses using View Results Tree listener - this will allow you to identify which exact step is failing.
The process of implementing the correlation looks as follows:
Identify the element which looks to be dynamic either manually inspecting request parameters and look for "suspicious" patterns or record your test one more time and compare the recorded scripts looking for the parameters which differ
Inspect previous response and extract the dynamic value using a suitable post-processor. For HTML response times the best option is CSS Selector Extractor. It will allow you to extract the dynamic parameter value and store in into a JMeter Variable
Replace hardcoded recorded value with the variable from the step 2
Repeat for all dynamic parameters
Don't forget to add HTTP Cookie Manager to your Test Plan.

JMeter post-processor extracting javascript after evaluation from response body

The response body from a POST contains the following javascript:
var now = new Date();
document.location.href="/wwtb/entry.cgi?id=148e2743ad01572d55265c96ae91dc6c&uid=qastudent&fromlogin=1&ts=" + now.getTime();
I need to extract the value of ts after it's evaluated so that I can pass it as a parameter in my next GET.
As per JMeter project main page:
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
Therefore you will not be able to extract the value "after it's evaluated" because it will never get evaluated.
JMeter's equivalent of Date.getTime() function is __time() function so if you put the following construction anywhere in your Test Plan:
/wwtb/entry.cgi?id=148e2743ad01572d55265c96ae91dc6c&uid=qastudent&fromlogin=1&ts=${__time()}
The ${__time()} bit will become substituted with the current timestamp in the runtime:
Check out Apache JMeter Functions - An Introduction article to get familiarized with JMeter Functions concept.

Jmeter record and play scripts for performance testing

I want to do a performance test of a website so i am creating a script that mimics user behaviour. I am using blazemeter to record those scripts and upload it in jmeter. I have two questions:
1) Do the results of a record and play script vary when run on another machine or a different time ?
2) I am getting a 400 bad request error in one of the steps of the recorded script.
What should i do ?
Is there any other way to test the web pages other than record and play ?
The chance of getting a good load test from recording is minimal as modern web applications widely use dynamic HTTP Cookies HTTP Request Parameters for different reasons (security, tracking client state, etc)
So after recording your test scenario "skeleton" most likely you will need to perform so called correlation - the process of
detecting dynamic parameters
extracting them using JMeter Post Processors and storing into JMeter Variables
and reusing the variables where required
Detecting parameters is quite simple: just record your test 2 times and compare request defaults: if you see differences - you will need to perform the correlation.
Extracting dynamic parameters is a bigger story, choosing the right extractor depends on response type, for example:
for HTML response types use CSS/JQuery Extractor
for XML/XHTML and in some cases HTML use XPath Extractor
for JSON - JSON Extractor
for anything else - Regular Expression Extractor which works with any text (including all above response types)
Also be aware that there is a solution allowing to perform JMeter correlation in an automated manner so you won't to detect and handle the dynamic parameter manually, check out How to Cut Your JMeter Scripting Time by 80% article for more details.

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.

Resources