Sampler name will be empty/blank in the second loop in "View Result Tree" - jmeter

When I execute the script with Loop count = 2
The sampler's names in the first loop will be displayed correctly in the "View Result Tree".
But the names for the same sampler's in the second loop will be empty/blank in the "View Result Tree", please check the screenshot below.

Your question doesn't provide sufficient level of details in order to be troubleshooted/reproduced.
If you're generating your sampler labels dynamically using JMeter Functions or Variables (like I did in the above demo) - double check their values at every step using Debug Sampler and View Results Tree listener combination, it might be the case they're getting overwritten/emptied somewhere somehow
Inspect jmeter.log file for any suspicious entries, if something goes wrong most probably you will be able to figure out the root cause or get the idea from there

I faced with same issue. The cause of the error is when the name is changed in HTTP Header Manager plugins, sampler names start to come undefined. This is a bug of JMeter.
The solution is very simple. If the default value:
HTTP Header Manager
is assigned to all HTTP Header Manager plugins in Jmx, it will be resolved.

Related

How to analyze answer to the specific request in Jmeter

Here is my scenario:
5 users log in to the website which purpose is to shorten url links
(like bilty.com or tiny.cc).
Each user inputs a unique link and gets shortened result.
What I need to do is - to get some kind of analysis of this "shorten" request.
Also, I need to:
see the output (the shortened link) in this analysis.
check if the link was created or not.
check if the shortened links are correct.
make sure that the shortened link actually leads to the same website
just like the corresponding link in the input.
EDIT: I deduced that it should be made via Response Assertion, but I can't figure out how exactly.
Approach1(Grey Out-1st Thread group):- Put two request in parallel. First is full and second is redirect. Check option redirect automatically in second http request which is redirecting. Now, put compare assertion and check. This takes lot of resource.
Approach2:-Put 2 HTTPs request in parallel. First is full HTTP request without any redirect and second HTTP request is for short url and having follow redirect option checked.
Then, use regex in both (two regex used) to fetch the URLs. Check option "apply on"-> sub-samples as show for short url sampler, if it is redirecting. Not required for sampler if there is no redirect. First sampler regex uses "apply on" as "Main Sample Only" as there is no redirect.
Last compare them in the JSR223 sampler to make last sample fail.
I have used JSR223 sampler. You can also choose to have other approach also for comparison.
Hope this helps.
Update:-
Assuming you have data in two columns in csv as shown below image. Go to bin>user.properties file and put sample_variables as two column names used in the csv. Please restart jmeter if already open after editing user.properties file.
Put the first parameter in the http sampler.
Put the assertion as dynamic using second variable from the csv.
Note:- Do check the options in assertion to get what is required in your scenario. Follow redirection and Redirect Automatically have difference which required different assertion "apply to":- Main Sample or Sub-Sample. Do check them, if required.
Please check if this helps.

Automate sending a request and saving the response

There is a URL which I want to hit and save the response. The URL id needs to be incremented each time and save the response. For example -
First Get Request - http://google.com/getdata/?Id=1
First Response - one
Second Request - http://google.com/getdata/?Id=2
Second Response - two
and so on...
I want to hit the request with increment the id each time and save the response
I have tried using fiddler but unable to figure how to increment the id and save the response.
P.S. - I have to make around 6,00,000 hits
Since the 'Postman' tag is mentioned, I can help you regarding how to implement this in Postman.
Postman has a nice feature of using 'variables'.
You can use environment variables or globals.
Read more about these on their docs:
https://www.getpostman.com/docs/v6/postman/environments_and_globals/variables
You can use a global variable such as 'counter' and set it to 1 / whatever starting point you want.
Then you can modify your request like so :
http://google.com/getdata/?Id={{iteration}}
Now, in the Tests script of the request you can write the following script
let i = parseInt(pm.globals.get('iteration')) + 1;
pm.globals.set('iteration', i);
Also, to access the response you can use the following command in Test script:
console.log(pm.response); // Use pm.response as per your needs
Save the request in a collection.
Now load the Postman's Runner and select the collection.
Now you can put an iteration count of 6,00,000 and hit run!
Remember, heavy iterations will cause performance degradation.
In JMeter you need to click , Ctrl+0 and Ctrl+1 to create , Thread Group and HTTP Request
In Thread Group put the number of hits you need in Number of Threads (users)
In HTTP Request Put in Server Name or IP www.google.com and in Path /getdata/?Id=${__threadNum}
__threadNum will create increasing number from thread 1 to number of hits.
For small number of hits or debugging you can add View Results Tree to view request/response by clicking Ctrl+9 in Test Plan/Thread Group level.
To save the response use Post Processor, especially by adding Regular Expression Extractor below HTTP Request by clicking Ctrl+2.
Allows the user to extract values from a server response using a Perl-type regular expression. As a post-processor, this element will execute after each Sample request in its scope, applying the regular expression, extracting the requested values, generate the template string, and store the result into the given variable name.
Import to notice that for load testing you need to work with non GUI mode, which means call jmeter using command line as jmeter -n -t myTest.jmx
you will use Command-line mode (called Non-GUI mode) to run it for the Load Test.
Don't run load test using GUI mode !
For saving all responses to a one file see save response data or if you want to save file per thread/user you can add Save Responses to a file
Fiddler:
Open script editor (Control + r ) then add the following code inside OnBeforeResponse
static function OnBeforeResponse(oSession: Session) {
if(oSession.oRequest["X-SAVE-ME"] != "")
{
oSession.SaveResponseBody("C:\\tempfiddler\\" + oSession.SuggestedFilename);
}
}
Go to the "Composer" tab and include the header X-SAVE-ME with any value, in the URL, replace your ID with # (just like this: http://google.com/getdata/?Id=#) fiddler will now ask for the starting and ending value of ID before executing;
Please find the snapshot below for your scenario.
Scenario_Testplan
First, go to user properties and put "sample_variables = ID, Response_File_Name" or whatever the name you choose for the variables. Restart jmeter.
Create the below plan:-
CSV data set config to have incremental values and response file name
HTTP request will use ${ID}
Save response to a file will use ${Response_File_Name}
Hope this will help.
I would do this by command line, using a while loop with a curl to the URL, storing the body result on the standard output to a file. It would look something like this:
for i in {1..600000}; do curl "http://google.com/getdata/?id=$i" > body-result-id-$i; done
I couldn't test the line above because I don't have any access to a console right now, but I think it should work.
In Burp you can do this using the Intruder tool. First, capture a sample request in Burp. If you're unsure how to do this, please consult the getting started documentation.
Then right-click the request and selected "Send to Intruder".
In the Positions tab within Intruder, first click "Clear" then select the section you want to vary, and click "Add"
In the Payloads tab select the Payload type as "Numbers" and configure the range.
Click "Start attack"
For more information, consult the documentation.
One Another solution is that you can use Counter in jmeter. That you can find from below path
Thread Group > configElement > Counter.
Configure the Counter as per your need.
Give the Reference Name i for counter.
Use the variable in your request
For more information.

How to parameterized request if getting recorded script like this.? See details

How to parameterize request if I am getting something similar to the following for login POST request in body data tab.
"{\"msg\":\"method\",\"method\":\"login\",\"params\":[{\"user\":{\"username\":\"testuser\"},\"password\":{\"digest\":\"5811c74a581ffdb892ab9eddfb9cf2d21772a98332a59de6aa26989e01f84057\",\"algorithm\":\"sha-256\"}}],\"id\":\"7\"}"]
It's generally easy to correlate when we are getting in Parameters TAB, but in cases how we can proceed? For all further requests - it's the similar case.
I tried to switch to Parameters TAB, but it says that it can not be converted to that format.
So How we can proceed?
The same way, just substitute hard-coded (recorded) values with the relevant JMeter Variables directly in the request body like:
"{\"msg\":\"method\",\"method\":\"login\",\"params\":[{\"user\":{\"username\":\"${username}\"},\"password\":{\"digest\":\"${password}\",\"algorithm\":\"sha-256\"}}],\"id\":\"${id}\"}"]
The most commonly used for parameterization test element is CSV Data Set Config, however other options exist.

How to validate JMeter user defined variables?

I'm new to JMeter, I want to validate a JMeter test input variables defined as part of "User Defined Parameters". Let's say I have a variable "sessions" and my tester should pass input values in between 0 to 30 for sessions, if tester passes other than this range the test should not go further and should throw an error with appropriate message.
Is it possible with any kind of JMeter controllers/assertions/... without writing code for validation?
I am not sure is there any efficient/direct way of doing this. but I achieved your requirement as follows:
Add Setup Thread Group (before any other ThreadGroup). select radio button Stop Test Now in Action to be taken after a Sample error
Add Debug Sampler to the Setup Thread Group.
Add Response Assertion (RA) to the Debug Sampler.
In RA, Select JMeter Variable in Apply to section.
In RA, select Matches in Pattern Matching Rules section.
In RA, add the regex ^[0-9]$|^0[1-9]$|^1[0-9]$|^2[0-9]$|^30$ in Pattern to test text area.
Test will be stopped if you provide sessions value other than 0-30 in User Defined Variables, as Setup Thread Group is configured to Stop Test Now on Sample error.
Note1: Added View Results Tree Listener for confirmation whether the test is continued and also to check the error message. View Results Tree is added only for visual confirmation, must be removed during the load test, does not effect the actual logic.
Note2: I am not aware of any component, which can show custom message/alert to the user. so, used View Results Tree. We should remove this command during load testing. I added here for visual confirmation purpose. If not present also, Test will be stopped on wrong value for sessions, i.e., other than 0-30
Note3: We need a Sampler component in order to apply an Assertion. so, added Debug Sampler. Debug Sampler just reports all the JMeter variable values at the point of its execution.
Image references:
Setup Thread Group:
Response Assertion:
View Results Tree:
You cannot achieve such validation in GUI without amending JMeter source code but you can check the variable range using scripting.
For example, add a JSR223 Sampler as a child of the first request and put the following code into "Script" area:
import org.apache.commons.lang3.Range;
int sessions = Integer.parseInt(vars.get("sessions"));
String errorMessage = "Provided sessions number is not between 1 and 30, stopping test";
if (!Range.between(1, 30).contains(sessions)) {
log.info(errorMessage);
SampleResult.setSuccessful(false);
SampleResult.setResponseMessage(errorMessage);
SampleResult.setStopTest(true);
}
Demo:
Make sure you are using Groovy as a language (the option should be default as per JMeter 3.1, if you are using earlier JMeter version for some reason - you will have to choose groovy from the "Language" dropdown)

JMeter treating "${COOKIE_[cookiename]}" as a string

I have looked at numerous examples of setting properties from cookies, and they all seem to be indicate that using a BeanShell PostProcessor, I should be able to do the following, given a cookie named 'FOO'.
props.put( "fooCookie", "${COOKIE_FOO}" );
However, when I try to write that value to the console, as you see here...
print( props.get( "fooCookie" ) );
... the value is always the string ${COOKIE_FOO} as if the dollar/curly bracket notation is not being parsed.
I feel like I must be missing something painfully obvious here, but after several hours of fighting this, I am bringing it to the experts. Any advice would be appreciated.
EDIT: Adding a bit more detail. This is the layout of my test plan
Test Plan
User Defined Variables
HTTP Cookie Manager
HTTP Request Defaults
Login Thread (setup)
[page request - login POST]
HTTP Header Manager
BeanShell PostProcessor
[more page requests]
And I do indeed have CookieManager.save.cookies=true set in the jmeter.bat file that I am launching it with.
Do you have HTTP Cookie Manager in your test plan? If not, you need to have that.
You also need to set the CookieManager.save.cookies=true in the jmeter.properties file which you can find in JMETER_HOME/bin folder.
${COOKIE_FOO} will return the actual cookie value.
Check that your ${COOKIE_FOO} variable is really set using Debug Sampler and View Results Tree listener combination. Your code is OK so my expectation is that the variable is not set.
Those who suggest using Beanshell where it is possible to handle the situation using JMeter built-in test elements should probably consider quitting IT. There are:
__setProperty() function to put something to JMeter Properties
__P() and/or __property() function to read something from them
See How to Use Variables in Different Thread Groups guide for real-life example.

Resources