IF controller (radio button/counter) and Loop Controller in Jmeter - jmeter

I'd like to practice IF controller basically as follow:
TEST_PLAN
+Thread_group: (user: 3, ramp: 3, loop:2)
+Loop_Controller(loop:4)
++ HTTP request1: go to page_1
+IF_Controller1
++ HTTP request2: go to page_2
++ counter (config element)
+IF_Controller2
++ HTTP request3: click Back button
My condition "HTTP request 2" is only executed if loop (output "Loop_Controller" >4). How to do that ?
And, for IF_Controller2: it's will be executed after each of question on this page has checked (page has 5 questions, 1 question has 5 answer radio button.)
I also follow the Counter element and Counter functions, but don't know how to combine them?
and one more things: to use the variable in IF statement, they should be put on previous activities ? (in my case: IF controller: ${count}, thereby variable "count" should be put on HTTP request 1)
Thanks,

You need to place COUNTER as a child of Loop Controller, not If Controller. In this case you'll get the following scenario:
HTTP Request 1 (loop 1)
HTTP Request 1 (loop 2)
HTTP Request 1 (loop 3)
HTTP Request 1 (loop 4)
** HERE we're getting out of Loop Controller and go to 2nd Loop of Thread Group, If controller doesn't fire as counter value is 4 and condition is >4**
HTTP Request 1 (loop 5)
HTTP Request 1 (loop 6)
HTTP Request 1 (loop 7)
HTTP Request 1 (loop 8)
** HERE counter value is 8 and If controller condition is met so **
HTTP Request 2
Being child of If Controller counter isn't getting incremented
Counter Configuration:
Start: 1
Increment: 1
Reference Name: N
If Controller Configuration:
${N} > 4
See How to use JMeter's 'IF' Controller and get Pie guide for more details.

Related

How to assess the transaction response time with while loop / counter and fail it if it is not successful

I am uploading a file via API for which I do a ‘polling’ and have the following 2 steps / transactions:
HTTP request to upload it for which I get a temporary status response ‘uploading’
While loop with a counter until the response status changes to ‘success’ but not more than 10 times.
${__javaScript("${STATUS}" != "success" && ${counter} < 10,)}
Question-1: How do I measure the response time for step-2 as it varies (sometimes, file will be uploaded in 2 times and sometime in 8 times)?
Question-2: How to make step-2 fail when the status has not changed to success even after all 10 iterations/ attempts?
Please could someone help?
Thanks,
N
Put everything under Transaction Controller, it will measure duration of all the iterations.
You can go for JSR223 Assertion, example code would be something like:
if (vars.get('counter') == '9' && vars.get('STATUS') != 'success') {
AssertionResult.setFailureMessage(true)
AssertionResult.setFailureMessage('Status is ' + vars.get('STATUS') + ' after ' + vars.get('counter') + ' iterations')
}
put it as a child of the 2nd request and if after 10 iterations the status won't be success it will mark the sampler as failed.

JMeter - Hide failed requests on successful retry

I make retry logic with while loop. It will to be retry when response code is not 200.
Retry times is 3 times, if after 3 times still failure, give up.
However, even request is success after retry. The failed request does show in result tree and summary report.
Is it possible don't show failed request when success after retry in report. Only show request when after 3 time retry but still failure .
Now Situation
Request:
request(fail) -> request(fail) -> request(success)
Result tree:
request(fail)
request(fail)
request(success)
This is image I want.
Request:
request(fail) -> request(fail) -> request(success)
Result tree:
request(success)
Request:
request(fail) -> request(fail) -> request(fail)
Result tree:
request(fail)
Put your request under Loop Controller and give the number of loops as 3
Add JSR223 PostProcessor as a child of your request and put the following code into "Script" area
if (prev.getResponseCode() == '200') {
ctx.setTestLogicalAction(ctx.TestLogicalAction.BREAK_CURRENT_LOOP)
}
else {
if (vars.get('__jm__Loop Controller__idx') as int < 2) {
prev.setIgnore()
}
}
where:
prev stands for the previous response SampleResult
ctx stands for JMeterContext
and vars for JMeterVariables
More information on these JMeter API shorthands: Top 8 JMeter Java Classes You Should Be Using with Groovy

Jmeter : Print Thread properties in SMTP message body

In Message body, I want to display content like
Threads : 1
Rampup : 1
Loop : 2
Duration : 10 seconds
How could we print all the properties of thread in mail body?
You can get the values dynamically in the runtime by calling the relevant JMeterContext class methods from the __groovy() function like:
Threads: ${__groovy(ctx.getThreadGroup().getPropertyAsString('ThreadGroup.num_threads'),)}
Ramp Up: ${__groovy(ctx.getThreadGroup().getPropertyAsString('ThreadGroup.ramp_time'),)}
Loops: ${__groovy(ctx.getThreadGroup().getSamplerController().getPropertyAsString('LoopController.loops'),)}
Demo:
Assuming the following Thread Group definition:
You can get the required information with __groovy() function:
The function can be used literally anywhere in your script, for example in the SMTP Samplers message input field
You can enter text and JMeter Variables in to message body:
Add SMTP Sampler
Set up email settings: mail server host, port, login, password,..
Set up message body, use text and variables, for example:
Thread: ${__threadNum}.

Jmeter - Set status after few request have been sent

Can I resolve the following scenario by JMeter?:
Send request1
Insert response of request1 to request2
Send request2
Send request3
Compare response3 with responce1
If response3 = responce1 -> setResponseOK() for request2 ELSE Failed
Thanks in advance.
Suggestion to Resolve this situatuion
Send request 1
Capture the response of request 1 in var1(Using correlation-->depending up on your requirement)
Send request 3 first (as you don't need response of request 2 for input of req 3)
Capture response of request 3 in var2
Now hit Request 2 by passing the response of request 1 as an input which is store in var1
Apply beanshell post processor as a child of request 2
Now compare Respose of request 1 and 3 inside if condition:
if matches make the previous request (i.e. Request 2) pass, else fail
if(vars.get("var1").equals(vars.get("var2")))
{
prev.setSuccessful(true);
}
else
{
prev.setSuccessful(false);
}
Design your test as follows:
Request 1
Regular Expression Extractor to extract the whole response into a JMeter Variable configured as:
Reference Name: anything meaningful, i.e. response1
Regular Expression: (?s)(^.*)
Template: $1$
Request 2: use ${response1} where required
Request 3
Response Assertion configured like:
Pattern Matching Rules: Equals
Patterns to Test -> ${response1}
Reference material:
Regular Expressions
How to Use JMeter Assertions in Three Easy Steps

JMeter: doesn't increment counter value

I'm working on a load test for Eclipse RAP-based application in JMeter. I need to replace requestCounter in each http request with variable. Variable should be incremented by 1 in next requests.
Tried to use JMeter's __counter function ${__counter(FALSE)} for my ${COUNTER} variable:
1) in User Defined Variables (didn't increment counter http://screencast.com/t/5MP1ovdHJN5p),
2) in CSV Data Set (function body was inserted instead of number http://screencast.com/t/mUIaYF3Oc).
Replaced ${__counter(FALSE)} with ${__javaScript(${__counter(FALSE)})} - still no success.
3) Counter config element brings the same result as User Defined Variable - not incrementing value for next request.
Plan:
+Thread_group
+Counter config element/User Defined Variables/CSV Data Set
+Request group
++ HTTP request1: {"head":{"requestCounter":${COUNTER}} #should be 1
++ HTTP request2: {"head":{"requestCounter":${COUNTER}} #should be 2
++ HTTP request2: {"head":{"requestCounter":${COUNTER}} #should be 3
...
Any suggestions?
you don't need to update the request counter manually. For RAP 2.1+ we updated the Wiki with the current info about load testing:
https://wiki.eclipse.org/RAP/LoadTesting

Resources