jmeter: how to use while loop inside a loop - loops

my JMeter plan is
-- Loop controller (set to 3)
-- while controller(set to "${Dataitems}" != "<EOF>")
-- using CSV for reading the data items
-- HTTP requests
now issue is that after completing the while loop , thread is getting stopped . I know this is controlled in CSV config "Stop thread on EOF" =true will make thread to stop. But my requirement is that after iterating through my csv , I want control to passed to outer loop which will run based on the variable i provide in my case 3 so all request will run for all the data items i provide in csv for three times.
To achieve i tried to set
"Stop thread on EOF" = false , then its started running lopp for intinte times
"Stop thread on EOF" = ${Var1} , where var1 was declared in test plan , but still loop was running infinite times
Can some provide an insight on how to handover control from while loop to outer loop?
Your help much appreciated.

As you know, While controller will keep running until the condition fails.
Unfortunately, in your case, you need to set below condition to reiterate the CSV file values.
'Recycle on EOF?' to TRUE
So, While controller will never exit as you can not use any condition there (to fulfill your requirement).
The only way I can think to make your requirement work is - to use 2 Loop Controllers.
(Outer) Loop Controller (set to 3 as you had said)
(Inner) Loop Controller (set to no of rows in CSV)
I get the output like this. My CSV file has 3 rows with the values A,B,C. They are called 3 times by the outer loop controller.
If you do not want to hard code the number in the loop controller, use a variable & find the no of rows using beanshell and set the value to the variable.

Related

Apache JMeter 5.5 - Need to use a specific range as Data value from a CSV file

I am currently using JMeter 5.5 and I have the below data set stored in a .csv file
BatchId
DocID_Start
DocID_End
1
1
93
2
94
1266
...
...
...
7
25313
45700
Each BatchID has 'n' number of Document ID ranging between DocID_Start and DocID_End.
I am trying to create a sampler that sends a POST Drop loop Call to the API ${url}/drop?documentIds=${DocID}
where DocID is any number between the DocID_Start and DocID_End.
I Created a the following testplan
GET Batch is working as expected and it is looping through each of the BatchID within the CSV file one by one but I could not get POST Drop Loop to go through the CSV and grab a different DocID_Start value. It will just keep reusing the first line for every user.
I've tried using Loop Counter and ticked off different checkboxes but i couldn't get it to work
With the default Sharing Mode of All threads CSV Data Set Config reads the next line from the CSV file on each iteration of each virtual user.
If you want to get a random number between DocID_Start and DocID_End - go for __Random() function:
${__Random(${DocID_Start},${DocID_End},)}
you can call this function as many times as you want under the Loop Controller.
If I misunderstood your question and you want to proceed to the next "Batch" under the Loop Controller - you need to move your CSV Data Set Config inside the Loop Controller as currently it proceeds to the next line on the new iteration of the Thread Group. JMeter Scoping Rules documentation chapter can shed some light on this.

Pentaho data integration loop count variable

I want a simple loop function to count the number of loop like below in java programming:
for (int i = 0; i <3; i++) {
count = count+1;
}
System.out.println(count);
I am doing it using Pentaho data integration. so I have 1 job contain 3 transformations in it, where first transformation set the number of loop (above example 3), then second transformation click "Execute every input row" for looping, and set variable inside the transformation using Javascript with getVariable() and setVariable() function. the last transformation just get variable and write log to show the count.
The problem is every loop in the transformation 2 will get variable as 0. so it end up result = 1, what I expect is 3.
added the project files here: file
We'll need more details to help you, don't you have a simple sample of what you are trying to accomplish?
You can pass variables to a transformation from the job, so I don't think you'll need the getVariable() and setVariable() methods, you can just use the configuration properties of the transformation to execute:
I prefer using parameters (next tab) better than arguments/variables, but that's my preference.
The problem is that, in t2 transformation, you are getting the variable and setting a new value for the same variable at the same time, which does not work in the same transformation. When you close the Set variable step you get this warning:
To avoid it you need to use two variables, one you set before executing the loop, and another set each time you execute the loop or after executing the loop with the last value.
I have modified your job to make it work, in t1 transformation, I have added a new field (rownum_seq) created with the Add sequence step, to know how much to add to variable cnt in each execution of the loop. I could have used your id field, but in case you don't have a similar field in your real world job, that's the step you need to achieve something similar. I have modified the variable name to make more clear what I'm doing, in t1 I set the value of variable var_cnt_before.
In t2 transformation, I read var_cnt_before, and set the value of var_cnt_after as the sum of var_cnt_before + rownum_seq, this means I'm changing the value of var_cnt_after each time t2 is executed.
In t3 transformation, I read var_cnt_after, which has the value of the last execution of t2.
You could also calculate var_cnt_after in t1 and not modify it in t2, using the Group by step to get the max value of rownum_seq, so you don't need to modify that variable each time you execute t2, depending on what you need to achieve you might need to use it or change in t2 or you just need the final value so you calculate it in t1.
This is the link to the modified job and transformations.

How to iterate a request dynamically for each user in JMeter

I need to iterate a request multiple times in JMeter for different users. The iteration number differs for each users. For example: I need to iterate a request 5 times for first user, 3 times for second user and only 1 time for 3rd user and so on. How can we do this and how the input can be fed to the same. Is it possible to say read first 5 line for first user and next 3 lines for second user in csv data set config.
You can define the desired loops count for each user in the CSV file or via JMeter Properties
You can read the desired line from the CSV file using __groovy() function like:
${__groovy(new File('test.csv').readLines().get(0),)} - read 1st line
${__groovy(new File('test.csv').readLines().get(1),)} - read 2nd line
etc.
Here is a solution for your problem. There could be many other solutions available in JMeter.
You can define the loop count associated with the users (threads) in a (User Parameters)enter link description here Pre-processor.
This panel allows you to specify a series of values for any User Variable. For each thread, the variable will be assigned one of the values from the series in sequence. If there are more threads than values, the values get re-used.
Then the requests can be placed within a Loop Controller
The User Parameters component shall be placed within a JSR223 Sampler to ensure the values are initiated before the loop controller is reached. Also the JSR223 Sampler shall be placed within a Once Only Controller to ensure the Sampler is executed only once.
Add SampleResult.setIgnore() in the JSR223 Sampler to avoid the sampler getting recorded into the test results.
Test plan structure
CSV Data Set Config more suitable for large numbers of parameters

Automation Anywhere Excel Loop

Does anyone know of an easy way to start an excel loop in Automation Anywhere at a row other than 1? (or two by using contains header option). I would like to start a loop at row 5 but everything I have tried thus far does not work.
Thanks in advance.
You can use the command - Go to Cell under Excel commands as explained below.
If you want to start from 5th row and 'A' column then before starting the excel loop:
Open spreadsheet
Select Go to Cell Command under excel commands
Select Specific Cell radio button
Provide the value of the Specific Cell as'A5'(which denotes 5th row and 'A' column)
Reference:
How to write data to excel file in a loop starting from a specific cell
Assign a loop count to a variable and if loop count is less than your desired row, continue the loop.
You can do this very easily using the "Continue" command. When you are looping in the excel using "Each row in an excel Dataset", make use of system variable "counter". Since you want to start from row 5, that means you will have to skip the first 3 lines as you have marked the contains header as yes. Use the condition "if counter < 4 then continue" which will skip the first 3 lines.
See below image for reference
There are couple of ways you can go about it,
♦defining counter would be one way to go about it.and loop starts after 5.
♦you can use specific cell to begin your task and use times for loop(rest of the rows) and can iterate to rest of the rows.
♦other is run a smaller task where it would copy all cell from row 5 to a new sheet and you can use generic excelloop to do the same task.
[this sheet can also be used to input something like "Success" and timestamp when loop finished that row to know its completed.]
Look at this. I can tell you about G1ANT as I have worked on that. Just change the value of from, your excel loop will start from that value only.
addon msoffice version 4.101.0.0
addon core version 4.101.0.0
addon language version 4.103.0.0
excel.open ♥environment⟦USERPROFILE⟧\Desktop\tlt.xlsx inbackgound true
for ♥n from 5 to 100 step 1
excel.getrow ♥n result ♥rowInput
dialog ♥rowInput
end
you cam use Excel Command.
Excel Command
1. Go to cell.
2. select your Excel Session
3. select specific Cells
If you use Excel command in Loop Command
you can use System variable "$Counter$"
And set Excel Command's select specific Cells to A$Counter$ / B$Counter$ etc.

SSIS: execute first task if condition met else skip to next

I am getting to know SSIS, I apologize if the question is too simple.
I got a set of tasks inside a foreach-loop-container.
The first task needs only to get executed on condition that a certain user variable is not null or empty.
Otherwise, the flow should skip the first task and continue to the second one.
How would I go about realizing this (in detail) ?
Issue 1: There are two ways to interpret your logic: "...a certain user variable is not null or empty":
The (Variable is Not Null) OR the (Variable is Empty).
The (Variable is Not Null) OR the (Variable is Not Empty).
It's all about the object(s?) of the word "not". The differences are subtle but will impact when the first task in the Foreach loop executes. For demonstration purposes, I am assuming you intend #1.
Issue 2: The first task can no longer be first. In order to accomplish what you desire using SSIS inside the BIDS environment, you need to place another task ahead of the task formerly known as "the first task". This is so you can set a Precedence Constraint on the former first task from the new first task.
It is possible to accomplish what you desire by designing your SSIS dynamically from managed code, but I don't think this issue warrants the overhead associated with that design choice.
I like using an empty Sequence Container as an "Anchor" task - a task that exists solely to serve as the starting endpoint of a Precedence Constraint. I heavily document them as such. I don't want anyone deleting the "unnecessary empty container" and roaming the halls for days shaking their heads and repeating "Andy, Andy, Andy..." but I digress.
In the example below, I have two precedence constraints leaving the empty Sequence Container. One goes to the task that may be skipped and the other to the task following the task that can sometimes be skipped. A third precedence constraint is required between the task that can sometimes be skipped and the task following. It is important to note this third precedence constraint must be edited and the Multiple Constraints option set to OR. This allows the task following to execute when either of the mutually exclusive previous paths are taken. By default, this is set to AND and will require both paths to execute. By definition, that will not - cannot - happen with mutually exclusive paths.
I test the value of an SSIS String variable named #MyVar to see if it's Null or Empty. I used the Expression Only Evaluation Option for the constraints leaving the empty Sequence Container. The expressions vary but establish the mutual exclusivity of the expression. My Foreach Loop Container looks like this:
I hope this helps.
:{>
The best thing can be to use the 'Disable Property' in expressions and giving the expression as per the condition. Just search how to use the disable property.
How about a simple solution instead of some of the more complex ones that have already been given. For the task you want to conditionally skip, add an expression to the disabled property. Any expression that produces a true or false result will work, so for the question example you could use:
ISNULL(#[User::MY_VAR]) || #[User::MY_VAR]==""
The only downside is that it may not as visible as some of the other solutions but it is far easier to implement.
I would create a For Loop Container around the task that needs the condition with the following conditions (#iis the loop counter, #foo is your user variable that you want to test):
InitExpression: #i=0
EvalExpression: #i<1 && !ISNULL(#Foo) && #Foo!=""
AssignExpression: #i=#i+1
there is no need to create a "script"
I think the best (and simpler) approach is to add a blank script task inside your loop container before your "first task", drag the green arrow from it to your "first task" (which obviously will become the second) and use the precedence constraint to do the check.
To do that, double click the arrow, select "expression" on the "evaluation operation" and write your expression. After hitting OK the arrow will become blue indicating that it isnt a simple precedence constraint, it has a expression assigned to it.
Hopefully I didn't misunderstand the question but a possible solution can be as written below.
I created a sample ForEach loop. The loop itself is an item enumerator. It enumerates the numbers 1, 2, 3. The acutal value is stored in a variable called LoopVariable.
There is another variable named FirstShouldRun which is a Boolean variable showing the first task in the foreach loop should be runned or not. I set this variable's EvaluateAsExpression property to true, and its expression is (#[User::LoopVariable] % 2) == 0. I would like to demonstrate with this that every second time the first task should be started.
The two tasks do nothing much but display a MessageBox showing the task has been started.
I started the package and first and the third time the first task didn't started. In the second loop the MessageBox (showing "First started") appeared.
After that you should set FirstShouldRun variable as you like.
As I mentioned in my first comment to the OP, this solution is based on the idea of Amos Wood written in another answer.
That's a bit tricky.
You have to create a Script Task and check if your variable is not null in there.
So first you have the script task in which you will have the following code in your Main() function:
public void Main()
{
if (Dts.Variables["User::yourVariable"].Value != null)
{
Dts.TaskResult = (int)ScriptResults.Failure;
}
else
{
Dts.TaskResult = (int)ScriptResults.Success;
}
}
Then you create two connections from your script task, one to the task that needs to be executed when your variable is not null, and one to the next task (or to another script, if you need to check again, if the variable is not null).
Then you right-click on the (green) arrow of your first connection and select "Failure". Right-click the connection to the next task / script and set it to "Completion".
It should then look something like this:
That's it.

Resources