Jmeter | if reponse has list it's getting null how to fix it? - jmeter

I am trying to do POST data and it's getting 200. but if in response JSON data has list [] like
{
"resno":"5600123",
"inquiry": [
{
"number": "1",
"organization": "",
"name": "Amarbold",
"collateralInfo2": "0",
"description": "dadtatadada"
},
{
"number": "1",
"organization": "",
"name": "Amarbold",
"collateralInfo2": "0",
"description": "dadtatadada"
}
]
}
this then i recieved this.
{"resno":"5600123","inquiry":null}
It's working fine in Postman.
how can i fix?

Given you send the same requests you should have the same responses, double check your request payload and headers using View Results Tree listener or maybe even better an external sniffer tool like Fiddler or Burp
Once you identify and eliminate the differences - you should get the same behaviour.
Be aware that it's also possible to record the Postman's request using JMeter's HTTP(S) Test Script Recorder, if you configure Postman to use JMeter as the proxy - JMeter will intercept the request and produce the relevant HTTP Request sampler and HTTP Header Manager. See How to Convert Your Postman API Tests to JMeter for Scaling article for more information.

Related

Jmeter 5.3 + Taurus 1.16. Correctly insert property from YAML file to HTTP request

My current test suite requires me to send some HTTP POST requests to API, some of which require specific objects to be posted via HTTP Request. I encountered some problems when trying to fetch those object from my YAML file when running Jmeter in Taurus.
I will attach part of my YAML file here for context (had to delete of change some properties for confidentiality):
jmeter:
properties:
number.of.users: 1000
rampup.period: 300
loop.count: 1
client.id: "23id"
array.of.clients: ["id1","id2","id3"]
ids: [1,2,3]
rq:
- "number": "7312sa1"
"signed": "2020-06-08T00:00:00.000+0000"
"crmClientId": "1-32D1P"
The problem is: when I try to pass string properties to my HTTP Request like that:
{
"id": 1986,
"jsonrpc": "2.0",
"method": "method",
"params":
{
${__P(rq,)}
}
}
all properties are wrapped in single quotation marks which causes request to receive error 400 in return because request after acquiring property is looking like this:
{
"id": 1986,
"jsonrpc": "2.0",
"method": "method",
"params":
{
'rq':
'number': '7312sa1'
'signed': '2020-06-08T00:00:00.000+0000'
'crmClientId': '1-32D1P'
}
}
Is there a way to pass string properties to request with double quotation marks or structure my YAML file in a way, which will construct request according to this example:
{
"id": 1986,
"jsonrpc": "2.0",
"method": "method",
"params":
{
rq:
"number": "7312sa1"
"signed": "2020-06-08T00:00:00.000+0000"
"crmClientId": "1-32D1P"
}
}
I tried using groovy replaceAll() method but it doesn't work with complex objects. My only solution as of right now is running some sort of groovy script in setUp thread and then acquire them is HTTP request via groovy jmeter function
You're sending a string representation of Python's dictionary, you need to send it as a simple string.
Check out YAML Multiline Strings and choose the most convenient option for you.
Example usage:
modules:
jmeter:
properties:
rq: >
\n"number": "7312sa1"\n
"signed": "2020-06-08T00:00:00.000+0000"\n
"crmClientId": "1-32D1P"\n
Taurus is presumably built to make testers and/or devops lives easier, it doesn't seem that it's your case, perhaps you should consider switching to JMeter without any wrappers instead?

extract http request response and proceed to next http request by using while controller

I want to use while controller to keep sending GET HTTP Request and only proceed to next POST HTTP Request when the GET response "model_name": "Model-Test-20220221-0001"
POST HTTP Request - paramter model_name = Model-Test-${variable}-${counter}
While Controller
GET HTTP Request. sample GET response at below
Json Extractor
POST HTTP Request only when While Controller found the exact model_name.
JSON Extractor:
Names of created variable: modelname
Json path expressions: I have tried this but failed
$..valid_model_list[?(#.model_name = ${Model-Test-${variable}-${counter}})]
This is sample HTTP Request response:
{
"message": "success",
"valid_model_list": [
{
"meta_data": {
"corpus_list": [
"test1"
],
"id": "0c36effa244b4f6596d10f9e675303e1",
"sample_rate": 16000,
"split_ratio": {
"test": 40,
"train": 60
},
"model_name": "Model-Test-20220221-0001",
"status": "ok"
},
{
"meta_data": {
"corpus_list": [
"test1"
],
"id": "0c36effa244b4f6596d10f9e675303e1",
"sample_rate": 16000,
"split_ratio": {
"test": 40,
"train": 60
},
"model_name": "Model-Test-20220221-0002",
"status": "ok"
}
}
]
}
}
We're "unsure" as well as we don't know what you're trying to achieve.
JSON Extractor can extract values from the response, it's not possible to use it to extract values from the request, moreover you should "know" what you're sending in the request and extracting values from the response is the essential part of the correlation process
If you're looking for a JSONPath expression extracting the model_name attribute value you're supposed to provide full JSON. There is a Deep Scan operator so you should be able to use something like:
$..model_name
but if there are more than 1 matches you might need to limit the output with Filter Operators
More information:
JsonPath Getting Started
API Testing With JMeter and the JSON Extractor

Jmeter - How to extract value from the request (not response) using RegEx

I have JSON request as following:
{
"type": "SIGNUP",
"data": {
"userAccountInfo": {
"email": "ta0620050706#gmail.com",
"password": "qweQwe123!"
},
"userAddressInfo": {
"country": "United States"
},
"userPersonalInfo": {
"firstName": "test",
"lastName": "test"
}
}
}
How can extract ta0620050706#gmail.com from the following request, considering the value of the email is always dinamic?
Any help is appreciated!
If you're talking about HTTP Request sampler and the above JSON is in the "Body Data" tab like:
You can extract the email by adding a JSR223 PreProcessor and using the following code there:
vars.put('email', new groovy.json.JsonSlurper().parseText(sampler.getArguments().getArgument(0).getValue()).data.userAccountInfo.email)
It will extract the value you're looking for and store it into ${email} JMeter Variable
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

Azure Logic App throwing 302 Redirect Error having Server=BIG IP in Response Header for HTTP

I am getting Redirect 302 error for HTTP Request in Logic App. I am calling OneIdentityServer to get access token. Then I am calling Rest API passing access token as Header for key Authorization. I am getting 302 Redirect error in response with headers information like Server = BIG IP, Location= /my.policy
The same above request when triggered through Postman or SOAPUI is working fine, I am getting successful response. But the same is failing in Azure Logic App.
I have also implemented the above scenario in function app as well. It is working file when I run the function app code from visual studio using Postman. But when I test the same function app after publishing it to Azure portal, it is giving same error.
It seems like I have the same issue as you. I found one-way that did not work for me but maybe you could give it a shot if it fits your needs?
The solution that I found in a blogpost was first to add the action "Switch" to the logic app flow and then configure Switch to run after the HTTP is both successful and has failed.
Secondly, the Switch action should trigger on the output of the statuscode from the HTTP request.
If the statuscode equals 302 you should make another HTTP request but with URI being the output of the location header from the first HTTP request. This made my logic app result in statuscode 200 but the response for my logic app was that I needed to login to get access to the API.
But maybe it could be worth giving this solution a shot for your logic app?
Here's the link of the blogpost if you need deeper instructions: http://www.alessandromoura.com.br/2018/11/21/dealing-with-http-302-in-logic-apps/
Do you still have issues with this? Here is a screenshot of my http action: HTTP Action that is working.
I have put my URL in an variable since it changing for each pagination. I also found out that to use the authentication token from the first HTTP request I needed to parse the body to be able to access the token, here is the schema I used to parse the HTTP body from the request where you get access token:
{
"properties": {
"access_token": {
"type": "string"
},
"expires_in": {
"type": "string"
},
"expires_on": {
"type": "string"
},
"ext_expires_in": {
"type": "string"
},
"not_before": {
"type": "string"
},
"resource": {
"type": "string"
},
"token_type": {
"type": "string"
}
},
"type": "object"
}

Google Speech API: the requested URL was not found on this server

I am attempting some simple tests on the Google Speech API, and when my server makes a request to this url (below), I get the 404. that's an error response. Not sure why.
https://speech.googleapis.com/v1/speech:recognize?key=[MY_API_KEY]
The body of my request looks like this:
{
"config": {
"languageCode": "en-US",
"encoding": "LINEAR16",
"sampleRateHertz": 16000,
"enableWordTimeOffsets": true,
"speechContexts": [{
"phrases": ["Some", "Helpful", "Phrases"]
}]
},
"audio":{
"uri":"gs://mydomain.com/my_file.mp3"
}
}
And here is the response:
As you can see, that is a valid resource path, unless I'm totally mistaken about something (I'm sure I am): https://cloud.google.com/speech-to-text/docs/reference/rest/v1/speech/recognize
Update 1:, Whenever I try this with the Google API explorer tool, I get this quota exceeded message (even though I have not yet issued a successful request to the API).
{
"error": {
"code": 429,
"message": "Quota exceeded for quota metric 'speech.googleapis.com/default_requests' and limit 'DefaultRequestsPerMinutePerProject' of service 'speech.googleapis.com' for consumer '[MY_API_KEY]'.",
"status": "RESOURCE_EXHAUSTED",
"details": [
{
"#type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developer console API key",
"url": "https://console.developers.google.com/project/[my_project_id]/apiui/credential"
}
]
}
]
}
}
Update 2: Interestingly, I was able to get some 200 ok's using the Restlet client, but even in those cases, the response body is empty (see screenshot below)
I have made a test by using the exact URL and Body content you added to the post, however, I was able to execute the API call correctly.
I noticed that if I add some extra character to the URL, it fails with the same 400 error since it doesn't exist. I would suggest you to verify that the URL of your request doesn't contain a typo and that the client you use is executing the API call correctly. Also, ensure that your calling code is not encoding the url, which could cause issues given the colon : that appears in the url.
I recommend you to perform this test by using the Try this API tool directly or Restlet client which are the ones that I used to replicate this scenario.

Resources