JMeter post-processor extracting javascript after evaluation from response body - jmeter

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.

Related

In Jmeter, A perquisite sampler request should be a part of transaction controller or not?

Usecase:
User searches a product and validates the response time
User validates response time in pagination functionality of searched result.
To check pagination, we need to search. Should this be part of second test or jmeter doesn't require previous request like UI, can we skip this and only test the pagination request?
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).
So if there are no dynamic parameters which store client state like ViewState or associated Cookies then you should be able to test the pagination without executing the "main" search request and only perform the correlation to see if there are more pages left, get the number of the current page, etc.
With regards to whether to put it under the Transaction Controller or not - it's totally up to you, Transaction Controller doesn't have any logic when it comes to "continuation" of the previous request, it just sums up the elapsed time of its children and reports the total amount taken.

jmeter load test getting dynamic values from array variable

I want handle the following url parameter dynamically in jmeter load testing
filters=%7B%22TIME_PERIOD_TYPE%22:%5B%22QTD%22%5D,%22COUNTRY%22:%5B%22%22%5D,%22TERRITORY%22:%5B%22PTPT_SL_FE_N_T01%22%5D,%22ACCOUNT_BRICK%22:%5B%22%22%5D,%22OVERALL_PRIORITY%22:%5B%22%22%5D,%22PRODUCT_PRIORITY_PRODUCT%22:%5B%22%22%5D,%22ACCOUNT_SPECIALTY%22:%5B%22%22%5D,%22ACCOUNT_TARGET_TYPE%22:%5B%22%22%5D,%22ACCOUNT_VISITABLE_TYPE%22:%5B%22%22%5D,%22ACCOUNT_SUB_TYPE%22:%5B%22%22%5D,%22HCO_SUB_TYPE%22:%5B%22%22%5D,%22ACCOUNT_MARKET_SEGMENT%22:%5B%22%22%5D%7D
Here are Jmeter sampler for filtering the value
How can I handle those values dynamically using corelation? Filter value can vary for menus
The options are in:
Correlate all the values one by one using the suitable Post-Processor
Get all input names/values from the previous response using i.e. CSS Selector Extractor and populate them in the next request using JSR223 PreProcessor and Groovy language.
Use a 3rd-party recording tool like BlazeMeter Proxy Recorder, it's capable of exporting recorded requests in "SmartJMX" mode with automatic detection and correlation of dynamic parameters, see How to Cut Your JMeter Scripting Time by 80% article for more details

How to handle Jmeter tests

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

jmeter - Unable to capture the random number generated using math.floor

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.

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.

Resources