I could see a random number calculated in the response as below
var rndnum = Math.floor(Math.random() * 11);
The subsequent request is expecting this rndnum to be passed. Unable to see the number generated in the response. If I just pass some random number, the response time is high and incorrect.
Any help?
You need to store the result in a JMeter variable using:
vars.put(‘rndnum’, ‘’+rndnum);
There are 2 options:
rndnum variable is present in the response. If so, you should be able to extract it using Regular Expression Extractor.
rndum variable is NOT present in the response. If so you are free to generate a random number between 0 and 10 via JMeter's __Random() function like:
${__Random(0,10,)}
Be aware that according to JMeter Documentation:
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
so my expectation is that you should go for point 2.
Related
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.
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.
I record and run the Jmeter script by keeping number of users = 1, in tread group.
Results tree output:
I increased the number of users to 3 and result tree output order changed.
Therefore my some of regular expression exacter logics get failed and resultant responses failed. How can I avoid this situation.
Is there way to manage result tree execution order.
If your regular expressions are under the requests and not at the same level as of HTTP requests then it should not be a problem.Every thread/vUser will run independently. But, in view results you will see request as and when executed by different threads and not in sequence.
As per JMeter Functions and Variables user manual chapter:
Variables are local to a thread
Each JMeter thread (virtual user) executes Samplers upside down (or according to the Logic Controllers). JMeter threads are absolutely independent from each other and each thread has its own variables.
So the problem must be somewhere else, inspect the state of the variables using Debug Sampler and the response data for /oauth calls - it might simply not contain the necessary token value.
Also there is a suspicious call to bundle.js, my expectation is that you should not be executing it directly. The good practices is to configure HTTP Request Defaults to download embedded resources and use parallel pool to be closer to what real browsers do.
See Web Testing with JMeter: How To Properly Handle Embedded Resources in HTML Responses article for more detailed explanation.
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.
So I have a REST API that I want to test with JMeter.
I have few different paths in the REST Service.
If we take an example of simple REST service that will calculate based on two values passed in request, I have four different paths
/add
/sub
/mul
/div
Now I want to test this with a 5000 requests but want to randomize the path and the values in request parameters in each request. Also if possible, want to get the results in 4 categories separately for each path.
Can someone please suggest the right combination of elements?
I am very new to JMeter and hence, expect a little elaborated answer. :)
The fastest and the easiest way is using __chooseRandom() function available via JMeter Plugins. The relevant configuration of the HTTP Request Sampler would be:
Path: /${__chooseRandom(add,sub,mul,div,path)} - get a random option and store it into ${path} JMeter Variable
Name: ${path} - change HTTP Request Sampler Label (for separate reporting)
You can install __chooseRandom() and other plugins Functions via JMeter Plugins Manager from the "Available Plugins" tab:
Be aware that your requests will be random hence your test scenario won't be repeatable so I would recommend considering using other test elements instead i.e. Throughput Controller or Switch Controller or Weighted Switch Controller.
See Running JMeter Samplers with Defined Percentage Probability article for above test elements configuration details.