Can any one explain about counter with simple example? - jmeter

I am new for Jmeter, any one please explain about counter with simple example and also please explain to set the test environment.
I have added a new Thread group and then add a counter(start=1, increment=1, Maximum= 5, Number of format=0, Reference name=null, and checked the Track counter check box).
Added a Http Request and a Listener.

In simple words,
Counter functionality is exactly similar to its name.
it's task is to create a counter initialized to a value and then iterate over it till a max value.
You can access it like a variable ${mycounter}
Usage:
It can be used in scenarios where sequential iteration over a range is required.
simplest example : my users have names like user1, user2......user10
I can use a counter named mycounter
start : 1
end : 10
increment : 1
Use it in req like user${mycounter}
Note : Press ctrl + h after selecting counter in jmeter for help.

Related

VB6 Timestamp / datediff()?

I have a series of steps say 1-10 and some of the steps repeat multiple times. I am able to record the time stamp do some simple calculation and write it into a text file at the steps where I want but the problem is when the same step repeats again it is recording it again. How can I record this timestamp only once at the start of the step and not record again when the step repeats?
Thank you!
You haven't provided many details so the answer might be not relevant. As an option, you can use a flag variables declared somewhere outside of your steps. For example for step one:
Private Step1Called As Boolean
Later, when you enter your step number 1 you can add something like this, where RecordTimeStamp is a function creating and manipulating your timestamp:
If Not Step1Called Then
RecordTimeStamp
Step1Called = True
End If

Reseting "Thread Context"

I would like to know if it is possible to reset the thread context (all of its variables) at the begining of a new iteration.
The problem that I am having is that the thread keeps all the variables (and its values) from its previous iterations and sometimes it things can get messy.
If I am not mistaken, on VisualStudio Performance tests you can specify the percentage of "new users" to indicate how many VirtualUsers are going to have its contexts reseted on their next test iteration.
Do we have something similar native on JMeter or do we need to write some code to do it?
Thanks in advance!
I'm not sure you really want/need it, but you can remove all JMeter variables using JSR223 script with remove method:
for (Map.Entry entry : vars.entrySet()) {
vars.put(entry.getKey(), null);
}
It depends on the type of variables you create and how you use them.
For ex:
Regular Expression Extractor
Here It creates a variable regex.var and if the response matches the expression it will have some value assigned to it. If the next iteration does not match the expression, It will still keep the previous iteration value. To avoid this problem, assign a default value or check the 'Use empty default value'. so that every iteration will basically reset the value.
User Designed Variables - Each and every thread will have its own copy of the variable and threads could be modifying its variable value throughout the entire duration of the test. If you want that to be reset for every iteration, it is completely your responsibility.
I think this could be helpful.
JMeter - Understanding Variables Scope

Logging and asserting the number of previously-unknown DOM elements

I'ts my first tme using Cypress and I almost finalized my first test. But to do so I need to assert against a unknown number. Let me explain:
When the test starts, a random number of elements is generated and I shouldn't have control on such a number (is a requirement). So, I'm trying to get such number in this way:
var previousElems = cy.get('.list-group-item').its('length');
I'm not really sure if I'm getting the right data, since I can not log it (the "cypress console" shows me "[Object]" when I print it). But let's say such line returns (5) to exemplify.
During the test, I simulate a user creating extra elements (2) and removing an (1) element. Let's say the user just creates one single extra element.
So, at the end os the test, I need to check if the number of eements with the same class are equals to (5+2-1) = (6) elements. I'm doing it in this way:
cy.get('.list-group-item').its('length').should('eq', (previousTasks + 1));
But I get the following message:
CypressError: Timed out retrying: expected 10 to equal '[object Object]1'
So, how can I log and assert this?
Thanks in advance,
PD: I also tryed:
var previousTasks = (Cypress.$("ul").children)? Cypress.$("ul").children.length : 0;
But it always returns a fixed number (2), even if I put a wait before to make sure all the items are fully loaded.
I also tryed the same with childNodes but it always return 0.
Your problem stems from the fact that Cypress test code is run all at once before the test starts. Commands are queued to be run later, and so storing variables as in your example will not work. This is why you keep getting objects instead of numbers; the object you're getting is called a chainer, and is used to allow you to chain commands off other commands, like so: cy.get('#someSelector').should('...');
Cypress has a way to get around this though; if you need to operate on some data directly, you can provide a lambda function using .then() that will be run in order with the rest of your commands. Here's a basic example that should work in your scenario:
cy.get('.list-group-item').its('length').then(previousCount => {
// Add two elements and remove one...
cy.get('.list-group-item').its('.length').should('eq', previousCount + 1);
});
If you haven't already, I strongly suggest reading the fantastic introduction to Cypress in the docs. This page on variables and aliases should also be useful in this case.

How to skip run time error in tibco?

I am new to tibco and I am working on tibco BW 5.X versions.
I have a scenario where I am working on multiple records coming in from a schema and I have to write a text file with only specific values out of those records.
Ex :
if this is the input:
<param>1</param>
<param>2</param>
<param>1</param>
<param>1</param>
I only have to write the param having values 1 and have to generate error for param having values 2 but after generating error the iteration that is currently going on should continue and must not stop.
I would be grateful if someone can help
I assume in case of the value "2" you want to invoke the "Generate Error" Activity to throw an error up to a calling process or client that some entry was not correct, right?
So if you want to make sure to process the whole list you should not throw the error in the loop group on the list as it will exit.
You can either:
Use 2 seperated lists
map the entries with value "1" into a good list that enter the loop and entries with value "2" into a bad list, that will if filled let you then invoke the "Generate Error" activity after the loop processing.
Append the entries with value "2" in your loop
Thereby after processing the loop you have these entries and if the list contains entries invoke the "Generate Error" activity.
Hope that helps
Cheers Seb
P.s.: if you upload your process it would be more clear to show ;)
You could create a output schema which contains only param1 values and use a mapper activity to perform corresponding transformation and xpath functions for filtering. If you try to implement this solution you can eliminate the chance of param2 values creeping into your output.

Jmeter - While Controller with Counter Config Element

I have a while controller that waits for a certain regular expression to appear in the response before logging the user out. However, due to timeouts with the previous request this will occasionally enter into an infinite loop, skewing the data. I'm looking to set this request so that it only sends 5 times before exiting the loop and logging the user out.
After searching for an answer it seems that either the ${__counter()} variable or Counter Config Element are the solution, but neither seem to be working as I would expect.
Here is what I've got so far:
While Controller (${__javaScript( "${DONE_A}" != "Thank you for your order" || ${counter} < 5;)}
Counter (set to 5, increment 1)
Constant Timer (2000 ms)
GET /checkout/confirmation
^RegExp Extractor (DONE)
Logout
I can see a couple of problems with your script:
During 1st iteration counter value is NaN, you need to either declare it via i.e. User Defined Variables or to add check for "Not a Number" into your condition
You cannot refer variables as ${counter} in __JavaScript function. If you need to address it, you need to surround the variable with quotation marks (like you do for your DONE_A variable. If you need to treat the variable like a numeric one - use i.e. parseInt() function
Given point 2, my expectation is what your While controller clause simply does not work, that's why you're getting an endless loop.
This one should be good for your scenario:
${__javaScript(isNaN(parseInt("${counter}")) || parseInt("${counter}") < 5 && "${DONE_A}" != "Thank you for your order",)}

Resources