I have this path in jmeter:
ctn_v2/wr/?${sid}&${pid}&f&${messageNumber}&${streamId}&${streamMessageId}&${dataFlagType}&subsid=${subsId}
what I want to do is to send multiple post request with different parameters using HTTP request with Jmeter.
I am taking the parameters from JSON file which contain JSON array which each item in the JSON array has values which I want to send in a different post request.
I used JSON path extractor to extract the values as follows (taken from DEBUG post sampler):
messageNumber_0=[0,1,2,4,3,5,6,7,8]
messageNumber_1=0
messageNumber_2=1
messageNumber_3=2
messageNumber_4=4
messageNumber_5=3
messageNumber_6=5
messageNumber_7=6
messageNumber_8=7
messageNumber_9=8
messageNumber_matchNr=9
msgSize=10
pid=2
protocol=https
sid=1600385571504156
streamId=[0,1,1,0,0,0,0,0,0]
streamId_1=0
streamId_2=1
streamId_3=1
streamId_4=0
streamId_5=0
streamId_6=0
streamId_7=0
streamId_8=0
streamId_9=0
streamId_matchNr=9
streamMessageId=[0,0,1,2,1,3,4,5,6]
streamMessageId_1=0
streamMessageId_2=0
streamMessageId_3=1
streamMessageId_4=2
streamMessageId_5=1
streamMessageId_6=3
streamMessageId_7=4
streamMessageId_8=5
streamMessageId_9=6
I want to be able to send the 1st post request with messageNUmber_0, streamId_0, etc... I tried to use 'counter' to resolve it but it didn't work out.
You can organize your Test Plan as follows:
While Controller: condition ${__javaScript(${counter} < ${messageNumber_matchNr},)}
Counter: starting value 1, Increment 1, Reference Name: counter
HTTP Request
In the HTTP Request sampler you can refer respective item names as:
${__V(messageNumber_${counter})}
${__V(streamId_${counter})}
and ${__V(streamMessageId_${counter})}
Demo:
More information: Here’s What to Do to Combine Multiple JMeter Variables
Related
I have a SoapUI REST (i.e. non-SOAP) mock service that returns a response for a POST request.
The request and response both contain JSON content.
At the moment, I can get it to return a static response and that works fine, but I want some of the values in the response to be dynamically sourced from the request.
So if I have this request:
{
"the_request":{
"abc":"123",
}
How can I get the value of "abc" copied in the response?
Investigation has lead me to believe I can do this via including a variable in the response, something like:
Response:
{
"the_response":{
"value_from_request":"${#MockResponse#Request#the_request#abc}",
"other":"stuff",
}
And then implementing a script to populate the variable in the response, via the Script tab.
How can I then populate this with data from the request?
Currently SoapUI just generates an empty value
"value_from_request":"",
Tried using mockRequest.requestContent in the Script tab, but have not found how to obtain the "123" value from it.
OK, worked this out. So the response message can simply reference a variable in the requestContext like so:
Response:
{
"the_response":{
"value_from_request":"${the_value}",
"other":"stuff",
}
And a groovy script can be used to parse the JSON request content and populate "the_value" or whatever you like in the requestContext:
// Parse the JSON request.
def requestBody = new groovy.json.JsonSlurper().parseText(mockRequest.getRequestContent())
// Set up "the_value" from the request message.
requestContext.the_value = requestBody.the_request.abc
// Bit of logging so can see this in the "script log" tab.
log.info "Value extracted from request: ${requestContext.the_value}"
I think the script should be like this
def requestBody = new groovy.json.JsonSlurper().parseText(mockRequest.getRequestContent())
context.setProperty("the_value",requestBody.the_request.abc)
I have an endpoint that serves a ML model and I want to perform load testing on it. I'm using Jmeter 4.0 and its UI to construct a simple plan test. With 1 thread group that loops for a given duration and continuosly performs https requests.
How do I parse multiple test examples into the payload of a http request, one by one and in json format. These examples are contained in a json file called samples.json. The nested structure is the following:
{ "dataset": [
{"id": 1,
"in":[
{
"Feature1": 8.9
"Feature2":7.1
}],
"out": "Class1",
},
{"id": 2,
"in":[
{
"Feature1": 3.2
"Feature2":5.1
}],
"out": "Class1",
}]
}
IMPORTANT: I do not know the number of attributes a priori, so I need to retrieve them from the in key as that may change for other types of models, therefore I can't make use of harcoded jmeter variables, similar to what it's used in the CSV Config Set add-on, where they need to specify the variables names for each column of the csv file
I have no idea how you're gonna use the values from JSON in the HTTP Request sampler, however this is how you can parse your samples.json file and get in values from it in the JSR223 Sampler
new groovy.json.JsonSlurper().parse(new File('samples.json')).dataset.each { entry ->
entry.get('in').each { feature ->
feature.each { value ->
log.info(value.key + '=' + value.value)
}
}
}
The above code basically prints the keys and respective values into jmeter.log file
But you can easily amend it to store the values into JMeter Variables, write them into a CSV file, set HTTP Request sampler to use them on the fly, etc.
More information:
Groovy: Parsing and producing JSON
Apache Groovy - Why and How You Should Use It
Apache JMeter API
I am using Postman to test a microservice and I was wondering if you can do something like this.
have a collection with 2 GET request (request1, request2) that have
as one of the headers - userId
have a CSV file with two values for userId: test1, test2
run the collection using the CSV file like this: request1 uses the userId= test1 and request2 uses the parameter userId=test2
I know you can run the collection so that it iterates for each value in the CSV file through each request, but I would like to to map each request to a value in the CSV file. is this possible? If yes, how can you do that?
CSV files are only accepted as a iteration data files, so
is this possible to map each request to a value in the CSV file.
answer is: No, you can't.
You should give us more detailed question, but I feel that this link
will be helpful.
Also you can use JSON as datafile instead of CSV and make such construction:
Firstly, set environment variable "count" to 0.
JSON:
[
{
"UserIdHeadersValue":
[
"firstvalue",
"secondValue",
"thirdValue"
]
}
]
And in Scripts:
pre-request:
var count = parseInt(pm.variables.get("count"));
pm.variables.set("headerValue", data.UserIdHeaderValue[count]);
//you can put now that header value using {{headerValue}};
pm.environment.set("count", count+1);
I need to insert data into a SAP HANA database table via HTTP POST method. For example, I want to insert the following JSON object:
{"Id": "000034330", "Name":"Albert", "Type":"Customer"}
If I send just this object in the body of the HTTP POST request, it works fine. Although, instead of sending just one object at a time, I want to send an array of them. I tried the following format but it won't work:
{"entry":
[
{"Id": "000034330", "Name":"Albert", "Type":"Customer"},
{"Id": "000034331", "Name":"John", "Type":"Customer"}
]
}
Sending this format I get the following message as response:
The serialized resource has an missing value for member 'Id'
How should I format the JSON objects array?
You can use ajax call to update your hana database table.. following is the syntax for the ajax call
$.ajax({
'url':url,
'data':JSON.stringify(urObj),
'type':'POST',
'success': function (data){}
})
But you have to update your xsjs too as the data is included in header ...
I have a REST service which I am testing with SoapUI. The first step in my TestSuite returns the following Response (Json):
{
"mtMessageId": 52003685,
"status":
{
"value": 0,
"code": "OK",
"text": "Text message submitted"
},
"custMessageId": 123,
"custMessageRef": null
}
I want to 'Transfer' the value from the mtMessageId into the HTTP Get Request in the next step.
The request is formatted like "/SMS/{id}"
How do I transfer the value into the Request?
First of all you have to set the resource of your get method in your request with a property for example using /SMS/${#TestCase#id} in order to retrieve it from the first request.
Then add a groovy script testStep between your requests. An use the follow code to get the id from the json response of the first request and set as a property for the second request.
import groovy.json.*
// get the response from the first request using its name
def response = context.expand('${Request 1#Response}')
// parse it
def json = new JsonSlurper().parseText(response)
log.info json.mtMessageId
// get the json value an set it as property in testCase
context.testCase.setPropertyValue("id",json.mtMessageId.toString())
Note that you can use property transfer testStep to get the value from your request and set it as a property, however since SOAPUI converts all to xml I prefer to use a groovy script to work json.
Hope it helps,