I have to perform load test using JMeter on POST REST API which send JSON data in the request body as follows
{
id="",
name="abc",
age="34"
}
I want to use UUID feature in JMeter to auto generate UUID for the value of "id" which should be unique for every record created in the backend.
The value for "id" should be unique for every Thread executed in that Thread Group in JMeter.
Just use __UUID function
{
id="${__UUID}",
name="abc",
age="34"
}
If you're looking to learn jmeter correctly, this book will help you.
Related
I am new to JMeter, I want to retrieve from the request sample (it is on websocket-request-response-sampler).
The request body:
ws://localhost:8080/connect
{
"uid": "JBM1",
"agent_name": "performance_test_1"
}
I want to retrieve the agent name. Tried with normal JSSR223 post processer, not working. Any help ?
If you're tried with "normal" JSR223 Post Processor you're supposed to share your "normal" code you used and the "normal" jmeter.log file contents
I believe "normal" code should normally look like:
new groovy.json.JsonSlurper().parseText(sampler.getPropertyAsString('requestData'))[0].get('agent_name')
Demo:
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It
I have not done anything extra then #Dmitri rather few modifications, but please try it.
def requestBody = sampler.getPropertyAsString('requestData');
def jsonFormat = new groovy.json.JsonSlurper().parseText(requestBody)
def key = 'agent_name'
def agentName= jsonFormat."$key"
log.info("AgentName"+ agentName)
vars.put('AgentNameFurther',agentName)
I'm using JMeter for load test, and mocking external service using wiremock.
I'm using JSON files to mimic the responses from those external service,
one of the
{
"response":"459ada78-842b-4229-b9d8-4dcdb52aa738"
}
It is very simple response with only 1 UUID field, the problem is on my side this is must be unique everytime i call the service
Is there any way to regenerate that id from the mock file or using some kind of placeholder instead of static value
Use JMeter's __UUID function
${__UUID()}
will return UUIDs with this format : c69e0dd1-ac6b-4f2b-8d59-5d4e8743eecd
I am testing an API using JMeter.
But if I have sent multiple requests it's not working because of user_id show duplicate.
In the Test plan, I add a variable and define value.
Using BeanShell PostProcessor I try to make generate random value.
But all time as I define value not update the random value.
{
"user": {
"user_id": 100113,
"rest_id": 4589445,
"rest_name": "chetan",
}
}
Using HTTP header manager and HTTP Request.
In HTTP Request body I passed this JSON
For a single request, it's working fine.
But if I have sent multiple requests it's not working because of user_id show duplicate.
how can I change every time user_id with the help of JMeter?
Right now I am doing manually. Every time I have to change user_id.
Use this random function ${__RandomString(6,1236547890,)}. It will generate random value of 6 digit each time.
For more details visit below link:
https://jmeter.apache.org/usermanual/functions.html
Use CSV Data sec config to parameterize user id. Input userids in csv then pass the column name of the csv in the json as "user_id": ${USERIDFROMCSV}
For more info on csv data set config use, check link:-
https://guide.blazemeter.com/hc/en-us/articles/206733689-Using-CSV-DATA-SET-CONFIG
Also, there are functions which can be used like Random,RandomString. For more information check:-
https://jmeter.apache.org/usermanual/functions.html
From response need to extract the licensetype and corresponding id (based on licensetype, id changes - ex: licensetype 'full', there can be 20 ids associated, licensetype 'half' can be 100 ids associated). This extracted info needs to be passed to next 'POST' request by passing licensetype and ids as shown in the screenshot.
How to extract this kind of combination using JMeter and pass it to next HTTP API request? I can extract each one like licensetype and ids separately using RegEx or JSON path extractor however I need to specify the combination in the next request. Please guide.
General recommendation: use JSR223 PreProcessor and Groovy language to construct the JSON Payload programmatically using JsonBuilder class. Previously extracted IDs can be accessed using vars shorthand which stands for JMeterVariables class instance.
References:
Parsing and producing JSON
Groovy Is the New Black
I need to know how to log an error when a JDBC request returns no data from DB in Jmeter.
I have got:
JDBC request
Query:
SELECT names
FROM customers
Variable names:
namesCustomers
Then I have got a BeanShell postProcessor with script:
import org.apache.jmeter.util.JMeterUtils;
JMeterUtils.setProperty("namesCustomer", vars.get("namesCustomer_1"));
And finally a simple controller called "set variables" which calls an external file with the following code:
vars.put("namesCustomer",JMeterUtils.getProperty("namesCustomer"));
The problem is that in another SOAP request I am using the variable namesCustomer_1, and if no data is returned from DB this request fails. I need to log an error when the JDBC returns no data.
If I add to the post processor:
log.error("Error example");
I see the error logged in jmeter.log when this request is ran. I need something like:
if(JMeterUtils.setProperty("namesCustomer", vars.get("namesCustomer_1")).toString().length()==0){
log.error("DB returned no results")
}
Any Ideas on how to log an error when the JDBC request returns no data?
It can be done a little bit easier. If JMeter Variable is not set, it'll be null, not empty string.
So I would suggest amending your code as follows:
String namesCustomer = vars.get("namesCustomer_1");
if (namesCustomer == null) {
log.error("namesCustomer_1 variable is not set");
} else {
props.put("namesCustomer", namesCustomer);
}
props is a shorthand to access current set of JMeter Properties, there is no need to use JMeterUtils.setProperty() method.
See How to use BeanShell: JMeter's favorite built-in component guide for more details on Beanshell scripting in Apache JMeter and a kind of Beanshell cookbook.