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

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.

Related

I am not able to record place order activity and perform load testing on randomly generated URL

at the time of recording activity I am recording complete activity till place order, but when run the same action for 5 times, in result everytime its hitting same URL that has been generated while recording, but because of it place order not recording to my admin account.
In the majority of cases unfortunately you will not be able to successfully replay the recorded script because modern web applications widely use dynamic parameters for various reasons like client side state tracking or security reasons.
So you need to parameterize and/or correlate your test and replace recorded hard-coded values with either dynamic parameters which needs to be extracted from the previous response using a suitable JMeter Post-Processor or provide random values or use pre-defined values from i.e. external CSV file.
The easiest way of detecting dynamic parameters is recording your test one more time and comparing 2 recorded script - the parameters which will differ will require your attention.
You can also consider using an alternative recording solution which is capable of exporting recorded scripts in "SmartJMX" mode with automatic detection and correlation of the dynamic values, check out How to Cut Your JMeter Scripting Time by 80% article for more details.

Adding elements at runtime and executing a jmeter test plan

I am trying to build a jmeter testplan, where all the test values are sent from a csv datafile.I want to add assertions(provided in the datafile) to my HTTP Request at runtime and execute the test. The reason behind doing this is to keep the plan flexible according to the number of assertions. In my case, the assertions are getting added at the runtime; however they fail to get executed. May I know what should be done to get the components added and executed in the same flow?
For example: A part of plan looks like:
XYZ
--HTTP Sampler
-- Response Assertion1
-- Response Assertion2
-- JSON Extractor
where XYZ -->keyword based transaction controller(reusable component)
Everytime I have a request of type XYZ, this chunk of components will get executed. In my case, I do not want to place anything such as Assertions, pre/post processors, extractors in the test plan already. I want to generate these components at run time and execute them (as per my test requisites).
Issue: The problem here is that I cant load the components programmatically and execute them in the same flow. The reason being, the compiler does not know beforehand what all components it needs to execute, so it bypasses the newly added components.
So, I need some alternative solution to execute this.
You can add Response Assertion (or multiple) with Pattern to test filled with a variable as ${testAssert1} and set the variable by default as empty, for example
Put in User Defined Variables name testAssert1 with empty value.
Your assertion(s) will pass until you on run time set the variable with a different value, for example using User Parameters Pre Processor.

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.

How to decide which value to fetch?

I have jmeter script contains five transactions of which one transaction contains more than one dynamic values. And I want to know how to decide which value to fetch in order to pass it to further transaction?
You need to fetch those values which are required.
Record your scenario 2 times
Inspect request details using View Results Tree listener
Find request parameters (they may be in the request headers as well) which are different between 2 recordings
These are the dynamic parameters you need to correlate (extract from the previous response and pass to the next request)
Alternatively you can use a cloud-based JMeter scripts recording solution which is capable of exporting recorded scripts in "SmartJMX" mode with automatic correlation of all dynamic parameters so you won't have to worry about it. Check out How to Cut Your JMeter Scripting Time by 80% guide for details.

Developing JMeter test plan with results from multiple REST end points

Is this possible in JMeter to develop a test plan that will have result of first test (an ID) will be input of next test and so on in next test upto 4 tests because each test generates a unique ID and each of these IDs are dependent on each other. Each one is related as follows: submission ID > execution ID > both will generate completion ID with result pass or fail. These are REST API calls. I need to run concurrency users load testing. Finally I need measure latency, throughput from each test.
Between sampler requests, parse the api response using JSON post processor, assign it to ${variable_name} and use it in other requests.
It should look something like this.
Thread group
Userdefined variables
Http Sampler
Regex to get id
Http Sampler
Regex to get id
If you want to measure the response time of all the sampler have a simple controller as parent of all samplers
thank you for quick tip. I was able to get one step working by passing ID into a regular expression, but the same regular expression did not work for 3rd step. Let me give more details here. Basically first post command gives submission ID > I used that ID into regular expression > run a get command in next step with an URL something like '/../2ndStep/submissionId' > this is passed > I'm using the same regular expression in next get command with an URL something like '/../3rdStep/submissionId/executions'> this is supposed to give another executionId and it is failing for me. I'm not sure what I'm missing.
thank you all for suggesting working solution. But I need to do this different way to achieve the following requirement.
When I run POST command test on my REST API HTTP request using JMeter, it returns an ID in response. This ID will be used by other steps for completing the job. I'm currently passing ID into regular expression and using that in between the samplers of each step as it was suggested above and then measuring latency, but the GET steps which are dependent on that ID could take sometime to complete. So I can not put those GET steps into one thread because two of the steps are failing as they could take some time to complete. Is there a way to separate POST command from the remaining and start polling GET commands on the remaining steps automatically to remedy this. Bottom line is I need to measure latency of each step and throughput too. Please let me know if there is a way to achieve this in JMeter?
Thanks again,
Santana

Resources