JMeter If-Loop controller - jmeter

My Test Plan looks something like this:
Test Plan
-> Thread Group
-> Sampler 1
-> If condn()
-> Sampler 2
-> Loop controller
-> Sampler 3
I want the Loop controller to be triggered after the Sampler 2 is executed.
Now, this works perfectly for me when I try it on a Dummy application. But in the actual app, the control exits after Sampler 2.
I have looked into any possible re-directions but still haven't found a solution.
Any ideas?

This is how it works.
Check jmeter.log for any error (or activate Log Viewer) and also show Loop Controller GUI Content.

Related

JMETER - How can I pass 2 condition in a while loop on Jmeter

How can I pass 2 condition in a while loop on Jmeter. The conditions are
The request should run in loop till "Pass" response comes.
While loop should run only for 1 minute.
Condition 1 is working fine. However condition 2 is unable to implement.
I have tried running the While Loop inside a Runtime Controller. But the issue is, if the response "Pass" comes before 1 min, the rest of the test stops.
Tried other way round (Runtime inside While Loop) leading to numerous execution of the request, even after receiving "Pass" response.
Will appreciate any leads on this. Thanks
Add a JSR223 Sampler just before the While Controller and store the current time into a JMeter Variable using the following code:
SampleResult.setIgnore()
vars.putObject('whileLoopStart', System.currentTimeMillis())
Use the following __groovy() function as the While Controller's condition:
${__groovy(!vars.get('your_variable').equals('Pass') && ((System.currentTimeMillis() - vars.getObject('whileLoopStart')) < 60000),)}
This way the While Controller will run until:
either your_variable is not equal to Pass
or 60 seconds pass
whatever comes the first
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It
This could be another solution.
You can achieve the desired outcome with the following components.
Runtime Controller
If Controller
Flow Control Action
Set the Runtime (duration) in the Runtime Controller
Set the first condition you already have in While Controller in the If Controller
Click the Break Current Loop to exist from the Run Time controller

Organize Functional Test in Jmeter

I am using Jmeter to create an functional automation suite for our application under test (Right now this is only tool that i can think of which supports interaction with Active MQ , Database , Rest and SOAP API both which are our needs)
Down the line i will be having different test set and configuration files for the application under test.
Below is the process that i will follow to test:
1 Stop the application
2 Load a particular file
3 Start the application
4 Run the test test that match the loaded config
REPEAT THE SAME FOR OTHER CONFIGURATION.
Now every Test case comes with steps , liked.
1) Call a Rest API
2) Call a Rest API
3) Call DB
4) Validate the result from step 2
See the attached image for more details on how my i test case is organized.
Problem :
When the report is generated it is not generated on the thread group level but in sampler level , i.e. in the report i have lines , and there is no way to distinguish which TC (Or thread group) and Test Set they belong.
Can someone please suggest how do i achieve this ?
Please consider this is mind :
1 ) Down the line i will have multiple Test Set
2 ) I will also need to merge all this reports from multiple Test Set and create 1 single report that provides a clear picture of what failed / passed and probably the error message received.
Existing Report :
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
1565180794011,2067,DeactiveExistingActiveScenario,Non HTTP response code: org.apache.http.conn.HttpHostConnectException,"Non HTTP response message: Connect to localhost:1 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect",TC1_Probe_MbaWmcOutboundHappyFlowScenario 1-1,text,false,Test failed: code expected to contain /200/,2738,0,1,1,http://localhost:1/XXX/XXX/XXXX,0,0,2067
1565180796093,2007,ActiveMbaWmcOutboundHappyFlowScenario,Non HTTP response code: org.apache.http.conn.HttpHostConnectException,"Non HTTP response message: Connect to localhost:1 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect",parallel bzm - Parallel Controller,text,false,Test failed: text expected to contain /All 25 invocations validated successful./,3104,0,2,1,http://localhost:1/XXX/XXX/XXX?awaitSeconds=30,0,0,2007
1565180796092,2479,Call DB Procedure,200,OK,parallel bzm - Parallel Controller,text,true,,42,0,1,1,null,2478,0,390
Actual expected :
Probably the same report in a different format like
Test Set 1 :
TC1 :
Step 1:
Step 2:
Step 3:
TC2 :
Step 1:
Step 2:
Step 3:
Current Test Set Structure :
https://ibb.co/F4SVHxq
Two approach, i can think of:
Use transaction controller. Put all request of one test under 1 transaction controller. It will be shown in the report at the end. So, first steps then test case name at the end as shown below:-
Use dummy sampler for test set to produce the extra label as shown below:-
Here TC1 and TC2 are dummy sampler. Based on the above, you can use Test set and test cases labels according to your need. Test Set1--dummy, TC1--dummy,Step 1, Step 2 so on.
Considering, functional test with 1 thread.
Hope this helps.

How to get the exact loading time of website in jmeter

Just wanna know if this scenario is possible in jmeter:
I will create a website using docker image then i will have to check the exact accessibility time(from creating up to launching/checking the site). Once the requirement is met, the timer will stop and it will give me the exact time on when it is actually up. Also, in the view result tree, i only want to get the last successful status. The View Result Tree will only show the last successful status and will disregard the failed status. This is the sample of my thread that i am using: enter image description here
If you really want to discard non-successful results you can do this using JSR223 Assertion and the following Groovy code:
if (!prev.isSuccessful()) {
prev.setIgnore()
}
where prev is a shorthand for parent SampleResult and setIgnore() function tells the listener to ignore the result in case of failure.
More information: Scripting JMeter Assertions in Groovy - A Tutorial

onTestComplete function

Basically the first script runs correctly on the Web (Action 1) . This inputted information is transferred from the web to a terminal emulator (backend non QTP related). → Done
A second action is then used on the terminal emulator to complete/test information.
So in effect, there are two scripts:
Action 1 for the web,
Action 2 for the emulator
The script for the terminal emulator also runs fine.
So the problem is this:
I don't want to call the Action 2 until Action 1 is complete (simple I arrange the actions in order they are to fire). → Done
However, I want the Action 2 to run off the datasheet from Action 1. I don't want to have to copy all the information manually from Action 1 to Action 2. Usually this is simple, as I can use the setRow(), getRow() methods. But the Action 2 datasheet is blank (as Action 1 has all the data). I can't run the Action 2, because there are no literation to run (again the datasheet in Action 2 is blank). QTP just reverts back to Action 1, because it thinks as there are now entries on Action 2, then Action 2 is complete.
All I want to do is associate Action 2 directly with the datasheet in Action 1. I don't want to simply extend the code to Action 1, because users will be moving consistently between Action 1 and Action 2.
So in a nut shell, is there
a code to copy all datasheet contents from Action 1 to Action 2 (but do this only once, not on every iteration) so that Action two can run on what ever row I choose from?
a simple way to associate the code of Action 2 to the Datasheet data of Action 1?
a way to use a library function file rather than action to run the datasheet information associated with Action 1?
Consider using Datatable.ImportSheet and programmatically import your test data.
Please note that, you will have to change your current row for every iteration. It should be on the start of your test... Something like
If DataTable.GetRowCount > DataTable.GetCurrentRow Then
DataTable.SetCurrentRow = DataTable.GetCurrentRow + 1
End If
I used similar to the above. Using the datatable.getCurrentRow method allowed me to access the correct row on the second spreadsheet

Beanshell script launched once (start and end of test plan) in JMeter

Good afternoon !
I will try to explain you clearly my problem.
The context
I have a JMeter TestPlan which send HTTP requests to a server. I have a Beanshell script to assert each different case of error returned.
302 response code -> OK
200 response code -> ?
In each error 200, I check the response data string to see if it is an error or a correct case. (User error like User don't have correct rights is OK, but Server is unavailable is ERROR and both have 200 as response code.)
Here is my test plan :
The goal
As I have several errors returned by only one assertion script, I am not able to differenciate each error, except by uncollaspe the assertion in a ViewResultTree. But I disable it when launching my test, and I will launch my TestPlan remotely.
I had the idea to manually count each error. All my samples goes in my Assertion script, and goes to the correct if block according to their content. I increment some variables (JMeter.properties in fact) in each block.
int test = Integer.parseInt(props.getProperty("302"));
test++;
props.setProperty("302", ""+test);
I want to display all those variables in a JFrame at the end of my testplan like this :
The problem
My problem is that I don't know how to launch a Beanshell script before and after the TestPlan.
I want a first script to be started before any sample is send, just to initialize all my properties variables to 0 (else, they keep the value of the last TestPlan).
And, I want a second one to display my Frame with all the variables after the test plan is finished. (Currently it is a JFrame but it will not stay like this.)
Tested solutions
1) For my first script, I set a Counter (JMeter > Config Element > Counter) in the beginning of my test plan to 0.
I use it to check if my test already started of not with an If Controller :
I have a Pre-Processor Beanshell with props.set("302","0"); where "302" is my property to count all 302 response code.
It correctly works but I want to know if there is a proper way to do this.
2) Then, for my second script, I tried to use ${JMeterThread.last_sample_ok} in an If Controller aswell but it doesn't work like I expected. If I put it after my sample, it start after all OK assertion, and if I put it at the end of the test plan, it is never called.
How can I run my beanshell script once, after all my threads are stopped (i.e. all sample finished) ?
Thank you in advance, I hope you understood everything !
JMeter SetUp thread group and TearDown thread group are meant for exactly this.
Add your beanshell component to the setUp thread group to do some setup activities before your actual test starts. Similarly the tearDown thread group runs after your test execution is complete.

Resources