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
Related
I use JMeter in our product performance testing now.
I have a performace test scenario below:
Exract 1000 unique IDs from a request A.
Add the 1000 unique IDs to next request B as "form parameters". check the request B response time.
The request B is like:
Method: Post
URL: http://www.aaa.com/abc/def
Form parameters:
para1 : value1
para2 : value2
ID : ID1
ID : ID2
ID : ID3
......
ID : ID1000
I know this request isn't a Canonical usage of http request. but it is used in our product for years.
Now I get the 1000 unique IDs from request A with the help of "regular expression extractor",
My question is:
how to pass the variables to request B, and set the 1000 IDs as "form parameters" of request B?
Add JSR223 PreProcessor as a child of the HTTP Request sampler where you need to add 1000 parameters
Put the following code into "Script" area:
def data = new org.apache.jmeter.config.Arguments()
1.upto(vars.get('ID_matchNr') as int, index -> {
def parameter = new org.apache.jmeter.protocol.http.util.HTTPArgument('ID', vars.get('ID_' + index))
data.addArgument(parameter)
})
sampler.setArguments(data)
That's it, the JSR223 PreProcessor will read all the JMeter Variables which start with ID_1 and ending with ID_XXXX and add a corresponding parameter to the HTTP Request sampler
More information on Groovy scripting in JMeter context: Apache Groovy - Why and How You Should Use It
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
}
})
getproperty values passed from Thread Group 1 to Thread group2
Result from BeanShell assertion
Step 1- USing jdbc request to get data from database with 2 columns and multiple rows.
Step 2 - From ThreadGroup 1, Set property to the database results using ${__setProperty(StateCodeProperty,${stateDetails})};
Step 3 - Access in Thread Group 2 by get property using beanshell assertion- String result = (vars.get("${__property(StateCodeProperty)}")); I need help on how to separate the columns and use it in api call. –
In any case if you want to access the DB results in different Thread group then you can try to do something like this inside beanshell assertion (not sure though) -
ArrayList results = ${__property(StateCodeProperty)}; //it should return the object as an arraylist
for (int i; i < results.size(); i++) {
if (results.get(i).get("statecode").equals("NY")) { //iterating the results, 'statecode' is the name of your 1st column, similarly you can do for 'State'
//Do your comparisons or whatever you like here
}
}
Can we query the business network to show a list of transaction classes? and knowing transaction class name, can we query the required parameters to pass when invoking it?
Eg: BusinessNetworkA consist of 3 Transaction classes {TradeApples, BuyCar, RentHouse}
TradeApples requires price per kg as parameter
BuyCar requires Car VIN and price as parameters
Rent requires House Number and price as parameters
That can be easily done:
query getCupData {
description: "particular batch"
statement:
SELECT org.ibm.coffee.cupCoffee
WHERE (cupId == _$CupId )
}
Use TradeApple in place of cupCoffe and pricePerKg in place of cupId and _$CupId would be input variable and you can have any type of query between your variable.
PS: This should go in a separate file named queries.qry (Name is Important should be same)
Suppose I have a variable in the RequestParameter as StudentList list where StudentList is a class as follows:
class StudentList
{
List<Students> stud=new ArrayList<Students>();
}
and Students is a class having fields firstName,lastName etc.How to pass values to the list variable in Jmeter as a request parameter?
You can pass values to the list variable in Jmeter via CSV Data Set Config. Where you have to create first .CSV file with values and set the parameters in the HTTP request. Below are shared steps with screenshots of results.
Create an HTTP request under the Thread group and change the name to "Student"
Select CSV Data Set Config from Config Element under the same Thread Group
Create .CSV file with values related firstname and lastname and set the loop count in the Thread Group as 3 as there are 3 records available in CSV file
CSV File
Set Path in CSV Data Set Config under Filename and Set the variable name as
"firstname,lastname"
CSV Dat Set Config
Set the parameter in value with the $ sign as per the attached screenshot.
Request Parameter
Select View Result Tree from Listener under the same Thread Group
Save the Test plan and Run or Start.
Under the view result tree, when clicking on each request you will find firstname and last name under each request parameter.
Student 1
Student 2
Student 3