Fetching Random User defined variable in jmeter - jmeter

I have user defined variable like this.
url_1
url_2
url_3
.
.
.
url_n
In HTTP Request sampler i have to randomly select any one of these URL's .So in server name textbox i am trying this ${url_${__Random(1,7)}} But it is not fetching the variable. How can i fetch the value of that variable.
I am also getting the following error.
java.net.URISyntaxException: Illegal character in authority at index 7: http://${url_${__Random(1,7)}}/ at java.net.URI$Parser.fail

Use __V() function like:
${__V(url_${__Random(1,7,)})}
As per function documentation:
For example, if one has variables A1,A2 and N=1:
${A1} - works OK
${A${N}} - does not work (nested variable reference)
${__V(A${N})} - works OK. A${N} becomes A1, and the __V function returns the value of A1
If you need more information: Here’s What to Do to Combine Multiple JMeter Variables

Related

JMeter how to select randomely from a extracted set of values

I have a requirement to use randome url from a url list I extract from a json response.
Say I extract them in this mannser
imageUrls_1=https://blah01.com
imageUrls_2=https://blah02.com
imageUrls_3=https://blah03.com
imageUrls_4=https://blah04.com
imageURLs_matchNr=4
In a following JSSR223 sampler I was able to generate a variable called "url" with one of the url names selected randomely
("imageUrls_1","imageUrls_2",etc)
I was thinking to use them in my HTTP request to get the correcponding url as follows. ${${url}}. But soon found out its not giving me anything other than "${${url}}" :(.
JMeter Is it possible to place a varibale inside a varible name?
Basically I need to use one of the extracted urls randomely in my HTTP request.
The easiest way is going for __V() and __Random() functions combination like:
${__V(imageUrls_${__Random(1,${imageURLs_matchNr},)},)}
Demo:
More information: Here’s What to Do to Combine Multiple JMeter Variables
Use __V function
${__V(url)}
The V (variable) function returns the result of evaluating a variable name expression.

jmeter - Looping based on DB query - use db data as variables

Based on this thread: jmeter - Looping based on DB query, i managed to get counter to the Loop controller, and and working fine.
Now i need updated version, where DB query returns 2 variables, so i can use them as parameters for the call.
url secret
https://test1.com/ 1234
https://test2.com/ 1234
https://test3.com/ 1234
And to be able to use them in:
As:
But, when i tried to use them as: ${url_#}, ${key_#} test is not working.
Is there other any way how can i use those 2 variables fetched from DB query, and the looping logic to be respected?
Any help is appreciated!
You need to use the following test elements combination:
${__jm__Loop Controller__idx} pre-defined variable to get the current Loop Controller's iteration number
__intSum() function to add 1 to the iteration number (it's zero-based)
__V() function to put everything together
The combination would be:
${__V(url_${__intSum(${__jm__Loop Controller__idx},1,)},)}
Demo:
More information: Here’s What to Do to Combine Multiple JMeter Variables
I found my answer. what help me was: ${__V(url_${__counter(,)})} variable together with counter function.

Jmeter variables value is not getting set after each loop

I am using the loop controller to loop an array & give HTTP request for each value. But in some cases, variable values are set with current value from the array
It might be the case the array simply doesn't have the variable matching the current loop index, double check the JMeter Variables which are in scope for each loop using Debug Sampler and View Results Tree listener combination.
I cannot reproduce your issue using the following simple setup:
JMeter Variables defined:
The variables referenced using __V() and __intSum() functions combination like:
${__V(var_${__intSum(${__jm__Loop Controller__idx},1,)})}
See Here’s What to Do to Combine Multiple JMeter Variables for the clarification of the syntax used.
If you just need to iterate JMeter Variables it might be easier to go for the ForEach Controller:

Using JsonExtractor Value in Jmeter

I have like 3 JsonExtractors in a single thread. How do i use the value extracted from the first to the third ?
The first JsonExtractor extracts 'winSpoke' value from the response json and i am storing in as
Names of created variables: WinSpoke
The third JsonExtractor will extract 'payLevelDetails' value based on the previous WinSpoke value and i am storing in as
Names of created variables: PayLevelDetails
Json Path expressions: $.payLevels[${WinSpoke}]
However i am getting error as -
JSONPostProcessor: Error processing JSON content in Pay Level Details
JSON Extractor, message: Could not parse token starting at position
11. Expected ?, ', 0-9, *
Can someone help me in pointing where i might have gone wrong ?
Your setup should work just fine given you have ${WinSpoke} variable defined, you can double check its value using Debug Sampler and View Results Tree listener combination
Also be aware that PostProcessors are being executed upside down so make sure that the JSON Extractor which extracts your WinSpoke variable is above the one which is referencing the variable.

How to submit different value in same field for each user

I have a scenario in which user logon into system and submit some entry , but as system does not allow to submit duplicate records , i need to change on of filed value .
How this can be done , an sample code will be much more helpfull.
You have a number of options, feel free to choose the one which suits you best:
__threadNum() function - returns current user number, i.e. 1 for first user, 2 for second, etc.
__Random() function - returns a random number in the given range
__time() function - returns current timestamp in the different formats
__UUID() function - returns random (type 4) UUID structure - probably the most "unique" option
You can use functions anywhere in your test plan, i.e. directly as a parameter value.
See the following references:
Function helper dialog - a tool which helps to generate correct JMeter Function Syntax
JMeter Functions and Variables
How to Use JMeter Functions
you can map columns of a csv file with CSV_Data_Set_Config by setting variables names to : user,pwd...
after that you can use them to logon like this '${user}'

Resources