JMeter - Looping - jmeter

I have the following script with 1 thread and 2 iterations.
Debug in Switch is not called. The second Google in the first iteration and the second Yahoo in the second iteration are not executed. Why?
Thank you for the help.
I added the image of Switch Controller.
Google and Yahoo are Simple Controllers with one HTTP Request Sampler.

Remove spaces in the Domains.csv file in the second column. As of now action= Google is checked instead of action=Google. so the behaviour.
Domains.csv
domain_1,domain_2
Google,Google
Yahoo,Yahoo
Note: As you are using Switch Controller, it executes only matching element inside of it.
Debug Sampler in Switch element will never be matched as you are looking for either Google or Yahoo.
As Edi Prayitno mentioned, you can keep it inside the Simple Controller, if you want to execute Debug Sampler in Switch every time.

Based on the help of Switch Controller above, you put the Switch Value = ${action}. It means you filled the Switch Value with the name of the subordinate element. When ${action} name = Google, it will execute subordinate element = Google. When ${action} = Yahoo, it will execute subordinate element name = Yahoo.That means Debug in Switch will be never be called.
If you want to put debug step inside of Switch Controller, you can re-arrange your test as below:
I hope that helps you.

Related

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

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.

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.

Why is 'while controller' not working in 'loop controller'?

I need to implement this use case.
I have to use a while controller test fragment in a loop controller and then run a request. After that, I need to run another request which is in a while loop. It should repeat 2 times.
Loop set to =2.
It runs successfully the first time, but the second time it just skips the while controller request.
While Controller can be "skipped" only in case when the "Condition" is (or becomes) false so maybe your test fragment is setting some variable to false or increments a counter to some specific value.
I would recommend adding a Debug Sampler as a last request in the Test Fragment and put the same expression you use in the While Controller condition as its label. Run your test and check the label using View Results Tree listener. If it's false - find a way to make it true, otherwise your fragment won't be executed second time.
See Using the While Controller in JMeter article to learn more about implementing "While" loops in JMeter tests.
It worked by setting newValue to variable.
Added BeanShell post processor and added code like
vars.put("Id_job","newValue");

While controller don't stop Jmeter

I am encountering a problem with "While Controller":
This is what I do:
Thread Group
-user defined variables (I have assigned 'nikitaShalom' to {})
-while controller (the following condition: ${__javascript(eval("'${nikitaShalom}' != '${str}'")})
-Http request (my request)
- JSON path extractor (to extract the value I will use in my while controller)
I have pre-defined nikitaShalom to be {} as I said after the extraction it should get 'userArrivedNode' then I am comparing it to str variable which predefined to 'userArrivedNode' I can see that the while controller keeps going it does not stop even if I get the condition right. why is this?
Can you give me any reference about it?
Thanks!
OK, I found the answer for this problem, all has to be done is to change javascript to javaScript with captial 'S'.
Thnaks!

Resources