i am trying to send http request using jMeter. in request parameter i have to send an array of json objects.
here is the piece of request i have created:
{
"parameter1": "value1",
"parameter2": "value2",
"event[event_location_suggestions_attributes]": [
{
"latitude" : 13,
"longitude" : 13,
"address" : "asdsds"
}
]
}
but the third parameter is not being sent with the request. i may be mistaking in the format for the third parameter. please help with this.
Is it doable?
Related
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
My Json Response is as below:
{
"id":2,
"parent_id":1,
"has_products":false,
"has_categories":true,
"image":"",
"image_thumbs":[ ],
"name":"Default Category",
"categories":[
{
"id":3,
"parent_id":2,
"has_products":false,
"has_categories":true,
"image":"https:\/\/storage.googleapis.com\/gcs-rezolve-commerce-engine-dev-media\/1%2F26%2Fcategory%2Fimages_7_.jpg?GoogleAccessId=rcedev#ferrous-layout-183111.iam.gserviceaccount.com&Expires=1515750870&Signature=BUVCdagE09Do%2B%2B6S9FXzmGUCJQP4QYHvoOuKOuLUQz9pJGwtwtkVF6h%2BuTzo5Jdqv%2F%2B4ACIw8WCWoT%2B8KQgNDpXA%2FCY2dkCDsfxb1VRXS0ff5dp4%2F2cq3WjE%2B8biudDXvhQvSWYx%2FyS%2FAYKkK%2FIXRqQ%2FlimDIYUR%2BRgdH6aEze4FNW5vCtGAHK%2BlscQ9GSFeG%2BN6KxMwFbjNpNNZT8KZ%2BLpdKbiHca%2Fk86TeYkmnvICdHpnaDqQJHGbofH%2BFPcbOWnjVCn9uD4gJQnfS4Y7a4OWdhG1q60Kr6KNpKmSOhOcD1P1NHFTn8SYI6GemGJPUXZ8Y3A40etORw1yfJC4M4Q%3D%3D",
"image_thumbs":[
],
"name":"Home Decors",
"categories":null
},
{
"id":4,
"parent_id":2,
"has_products":false,
"has_categories":true,
"image":"https:\/\/storage.googleapis.com\/gcs-rezolve-commerce-engine-dev-media\/1%2F26%2Fcategory%2F332034-jewelry.png?GoogleAccessId=rcedev#ferrous-layout-183111.iam.gserviceaccount.com&Expires=1515750870&Signature=OxdyQ6mYX5Shoz4pBf40MZr9I9PFdYUqD3Rihbn8EOpbj%2FekHSFiWGdUYZ1HeZmpB9mZ49qhKh3b0E25H%2FRPVvzv6MURzYOg4EfRa66KrjFAQVP5WbgC5dVzpKc2Nh8FWn4%2FgA70gQ1mE3Uh1KF62Tw2aFvlbughPM5ijC2j35xHTAYcnNhr2Pcx4%2B9%2BWVHecXCdvw%2Fy3CMrgmZGZFSfALNBsiSM8IKKtRXwqHqVRg9CwutbaVL5zDd0GbTdBhwZLlJxqAx9Z1RE4l78Rv3bA2BeLhk5OqX2ajU5YYEQC69tTm0Mq9jzNF7%2F9zhtwCsqDfiygmdMKs9D7vDqD0xD%2Fg%3D%3D",
"image_thumbs":[
"https:\/\/storage.googleapis.com\/gcs-rezolve-commerce-engine-dev-media\/1%2F26%2Fcategory%2F332034-jewelry_thumb_400x376.png?GoogleAccessId=rcedev#ferrous-layout-183111.iam.gserviceaccount.com&Expires=1515750870&Signature=bOX4Z8EZwHb80ZNWtJ%2BrTq5hkUMNkTMGrtjk%2BvEyJ9H0XSDUMsmZVgMjgZVprgc23oLBR2SCDGvLNJKkCij2GIX1X9HT7QCFt4uLgvFy%2FmATHDcI9AOL55P8ypv7GJHBeUU7jdJKl5o641Uvf2s22yTCZpJenIiJCzJyxGAN%2BRV%2FwyD0OXkcTYjgwpJ5zi6SK%2BOYY5EGfTqFQBEbuG9WUAvNgeY3fCFgWoRgrp2XuxM5meXlcT7WA%2FZzt6wougjimBQsdF03s04Kq3cR6jsiL6aZFjhQacToBtkLFF7xY30dQr%2FO0D3tgs57QJXdD45QPBX4dAhgV2fSo%2BDK4D1kwQ%3D%3D"
],
"name":"jewelry",
"categories":null
},
{
"id":10,
"parent_id":2,
"has_products":true,
"has_categories":false,
"image":"",
"image_thumbs":[
],
"name":"Ring Collection",
"categories":null
}
]
}
Can any one help me on this ?
Assuming that the value you want to extract is the id, then add a JSON Extractor with the below configurations:
Variable names : the name of the variable which will hold the value.
JSON Path expressions : $.categories[?(#.has_products == true)].id
Match Numbers : 1 // use -1 if you want to extract all id values which pass the condition.
Default values : NOT_FOUND
Reference:
advanced-usage-json-path-extractor-jmeter but use Core JMeter JSON Extractor instead of the plugin mentioned in blog
I have a json array coming from my api as response:
{
"data": [
{
"id": 1,
"name": "abc"
}
}
I am using laravel for api and laravel-codeception for testing.
public function getAll(ApiTester $I)
{
$I->sendGET($this->endpoint);
}
I have to test if the response contains only id and name key (not any other key) example this response should fail the test.
{
"data": [
{
"id": 1,
"name": "abc",
"email":"abc#xyz"
}
}
I have found $I->seeResponseContainsJson(), but it checks if JSON is present or not. It does not check if JSON response contains only specified keys.
Thanks.
Hi I am very new to use cherrypy as backend with fanytree as front end.
here is my fanytree side of the code:
source: {
url : '/test_data'
},
on the cherrypy side, I implemented function called test_data
#cherrypy.expose
#cherrypy.tools.json_out()
def test_data(self, **kwargs):
cherrypy.response.headers["Content-Type"] = "application/json"
return '[ {"title":"abc", "folder": true, "key": "1", "children":[ {"title":"b","key":"2"}] }]'
So I see the request comes to cherrypy as
'GET /test_data?_=some number...
On browser I see my return object back but it failed on check:
if (typeof data === "string") {
$.error("Ajax request returned a string (did you get the JSON dataType wrong?).");
}
I read somewhere that you need content-type to be json but I already have. What am I missing?
CherryPy JSON output tool, cherrypy.tools.json_out, takes care of MIME and turning your data into a JSON string. So if you use it the method should look like:
#cherrypy.expose
#cherrypy.tools.json_out()
def test_data(self, **kwargs):
return [{
"title" : "abc",
"folder" : True,
"key" : 1,
"children" : [{"title": "b", "key": 2}]
}]
Otherwise if you want to do it yourself it'll be:
import json
#cherrypy.expose
def test_data(self, **kwargs):
cherrypy.response.headers["Content-Type"] = "application/json"
return json.dumps([{
"title" : "abc",
"folder" : True,
"key" : 1,
"children" : [{"title": "b", "key": 2}]
}])
Then make sure you've restarted CherryPy app, and look in web developer tools or FireBug network tab to verify response headers and content.
The content type is ok, but the string you are returning is not valid json (for example the keys must be enclosed in double quotes).
I would recommend to prepare your data as list of dicts and then use 'json.dumps()' to convert to JSON.
(Maybe the json_out tool does the same but I would guess that even then you should return a list of dicts instead of a string.)
When I saw that the api has a call find_all_playlists I was assuming it would do just that; find the playlists. Sadly this call also gets every bit of information of every video inside the playlists.
Is there a way to just request all playlists and get a response like this:
{ "items": [
{
"id": 1721334541001,
"name" : "playlist 1"
},
{
"id": 1721334541002,
"name" : "playlist 2"
}
]
}
Hope someone has a solution for this.
Regards
- Drazen
You can specify the fields to be returned with the playlist_fields parameter.
http://api.brightcove.com/services/library?command=find_all_playlists&token=TOKEN&playlist_fields=id,name