Is there a way to add each session Id that is retrieved from a Loop Controller to a list and assign it to a property for use in the following thread group? Below I used a couple of Dummy Sampler to explain my requirement.
I had 3 users stored in a list to retrieve 3 session ids in the setUp Thread Group.
JSR223 PreProcessor
List usernames = Arrays.asList('Peter', 'Alex', 'Mary');
props.put('accounts', usernames);
I was able to read a username from this property to get a session id in the response accordingly per iteration in the Loop Controller.
"sessionId": "this_is_my_session_id-${__groovy(props.get('accounts').get(${__jm__LoopController__idx} % 3),)}-${__jm__LoopController__idx} "
I parsed the 3 session ids out by a JSR223 PostProcessor
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
def jsonSlurper = new JsonSlurper();
def response = jsonSlurper.parseText(prev.getResponseDataAsString());
def json = JsonOutput.toJson(response.sessionId)
def sessionId = new JsonSlurper().parseText(json)
log.info('The session id is:' + sessionId)
ArrayList<String> sessionIds = new ArrayList<String>();
props.put("sessionIds", sessionIds.add(sessionId))
I needed to add these 3 session ids to a list and assign it to a property so that I can use one session id inside the property per VU/thread in the following Thread Group. But it didn't work as expected. It threw error saying No such property: sessionIds
${__groovy(props.get(sessionIds).get(${__jm__UseSession__idx} % 3),)}
We don't know what do you "expect"
Most probably the problem is here:
props.put("sessionIds", sessionIds.add(sessionId))
Collection.add() function returns a boolean value so it puts true to the sessionIds property instead of the real value of the ArrayList.
So I believe you need to change it to something like:
sessionIds.add(sessionId)
props.put("sessionIds", sessionIds)
if you're going to run the JSR223 Test Element in the loop you can also reconsider the way you're initializing the sessionIds and implement the following logic:
If sessionIds property exists - read its value
If it doesn't exist - create a new ArrayList
Something like:
ArrayList<String> sessionIds = props.get("sessionIds") ?: new ArrayList<String>()
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?
Below is the Table:
Customer ID Customer number
1 ABC123
null DEF123
JSON variable name is, CustomerDetail:
In my scenario I want to check if Customer ID is not null then in JSON, Customer ID should display against CustomerDetails. That means CustomerDetails: "1"
If Customer ID is null then in JSON Customer number should display against CustomerDetails. That means CustomerDetails: "DEF123"
How Can I perform this validation in JMeter using JSR223 assertion.
Question: For CutomerDetails (In JSON)- if CustomerID is not null then display its value otherwise display value for customer number. In below provided code how can I fetch value of both the column from Db and then compare them?
Your question is unclear, if you configure your JDBC Request sampler as follows:
it will generate the following JMeter Variables
CustomerID_1=1
CustomerID_2=null
CustomerID_#=2
CustomerNumber_1=ABC123
CustomerNumber_2=DEF123
CustomerNumber_#=2
In the JSR223 Assertion you can use vars shorthand for JMeterVariables class instance in order to access variable values like:
1.upto(vars.get('CustomerID_#') as int, { index ->
if (vars.get('CustomerID_' + index) == 'null') {
//do something
} else {
//do something else
}
})
This is how the test plan looks :
Thread group
Bean shell sampler
For each Controller
Graphql request
In the previous thread I extracted 2 attributes which are id and price. Now this id and price are unique for each case.
I extracted these 2 attributes from the json response and stored in a text file separated by colon. Sample below (id : price)
123-456-789 : 45.5
889-332-121 : 60
I need to run the above thread for each such combination i.e. id and price need to be passed at run time to the variable section of graphql request.Using for each controller I am able to pass each of the Ids but how do I pass the corresponding price ?
If you have JMeter Variables like:
id_1=123-456-789
id_2=889-332-121
price_1=45.5
price_2=60
The id you can get from the ForEach Controller configured like:
And refer it as ${id} under the ForEach Controller
With regards to the "price" you will need to use __V() and __intSum() functions combination like:
${__V(price_${__intSum(${__jm__ForEach Controller__idx},1,)},)}
Demo:
More information: Here’s What to Do to Combine Multiple JMeter Variables
in below script i am trying to access user defined variable and modify the data and passing the value to post data using the variable "data".But after modifying the data it is not being sent to http request.
String temp = vars.get("${json}"); //access UDV data
temp = temp.replaceAll("__"," ");
vars.put("data",temp); //pass the data to another udv "data"
Please let me know whether there is any mistake in my above script
If you have an User Defined Variable called json which is created like:
then you need to change your code like:
String temp = vars.get("json")
or alternatively use "Parameters" section of the JSR223 Test Element:
you are accessing the variable incorrectly
String temp = vars.get("${json}"); //access UDV data is wrong
String temp = vars.get("json"); //access UDV data
refer here for more details
I have HTTP request whose response is below
{
"DATA": {
"G_1": {
"OR_ID": "100400",
"LEGAL_ENTITY": "TEST",
"BUSINESS_UNIT": "TEST BU"
},
"G_2": {
"OR_ID": "100500",
"LEGAL_ENTITY": "Test1 ",
"BUSINESS_UNIT": "Test1 "
},
"G_2": {
"OR_ID": "100100",
"LEGAL_ENTITY": "TEST3 ",
"BUSINESS_UNIT": "Test3"
}
}
I need to get OR_ID from the above response, which I am able to do it using Regular exp extractor.
There is Input CSV file which has multiple rows. For the CSV file, i need to check the OR_ID exists or not in column 2, if exists then I have to take columns 5 and 7 and pass it to my next post request in the body. In CSV the same OR_ID repeated, so i need repeat post request for all the repeated values of OR_ID in csv. CSV file has no header.
441919244,100010,QUTRN,TEST Inc.,100100,TEST,VCG and A, INC,USD,3409.0900,O,ICO-VCG-0140,2019-10-31,52 945,USD,USD,359409.0900,359409.0900,359409.0900,Processed,93901372,File,2019111NG52.csv,
441919028,100400,QUQED,TEST MEDICAL EDUCATION INC.,100020,QUINC,TEST INC.,USD,12.340,O,ICO-INC-8718,2019-10-31,52 729,USD,USD,12.3400,12.3400,12.3400,Processed,93901372,,File,20191113NG52.csv,
Can you please help.
Assuming that you can extract the OR_ID from the JSON response following solution could be useful.
In the CSV Data Set Config Element or Random CSV Data Set Config plugin read the CSV file assign the variable names to the respective columns
variable names = C1,OR_ID,C3,C4,C5,C6,C7,C8,C9
Add a While Controller as a parent to the CSV Data Set config elements and the HTTP Request where you want to send data from the CSV file.
${__jexl3("${OR_ID}"!="EOF")}
This will check EOF in the column 2 of the CSV file. Hence please add
,EOF,,
as the last line of the CSV file.
Add IF controller to the HTTP Request with following condition
${__jexl3("${OR_ID}"=="${OR_ID_J}")}
OR_ID_J is the OR_ID picked from the JASON response.
Use ${C5} and ${C7} in the places where you want to insert the data from the CSV file.
Reset the OR_ID to "" using a JSSR223 Sampler with following
vars.put("OR_ID", "");
Sample Test Plan is available in GitHub