I am using get request for getting json response. And it is dynamic. My response looks like this.
{
"data": [
{
"id": 1,
"name": "Jack",
"gender": "male"
},
{
"id": 2,
"name": "Jill",
"gender": "female"
}
]
}
Can I use id from this response and put that id in 'for loop' to execute delete method?
Given path 'profile/delete/id'
And if I can then how?
Yes, refer the docs: https://github.com/intuit/karate#data-driven-features
* def result = call read('delete.feature') response.data
And in delete.feature you will be able to refer to the id variable directly.
Related
I want to compare JSON response with DB data in JMeter. Below is Db table structure (Oracle database):
Table Structure
Below is the JSON
{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
{
"id": 7,
"email": "michael.lawson#reqres.in",
"first_name": "Michael",
"last_name": "Lawson",
"avatar": "https://reqres.in/img/faces/7-image.jpg"
},
{
"id": 8,
"email": "lindsay.ferguson#reqres.in",
"first_name": "Lindsay",
"last_name": "Ferguson",
"avatar": "https://reqres.in/img/faces/8-image.jpg"
},
{
"id": 9,
"email": "tobias.funke#reqres.in",
"first_name": "Tobias",
"last_name": "Funke",
"avatar": "https://reqres.in/img/faces/9-image.jpg"
},
{
"id": 10,
"email": "byron.fields#reqres.in",
"first_name": "Byron",
"last_name": "Fields",
"avatar": "https://reqres.in/img/faces/10-image.jpg"
},
{
"id": 11,
"email": "george.edwards#reqres.in",
"first_name": "George",
"last_name": "Edwards",
"avatar": "https://reqres.in/img/faces/11-image.jpg"
},
{
"id": 12,
"email": "rachel.howell#reqres.in",
"first_name": "Rachel",
"last_name": "Howell",
"avatar": "https://reqres.in/img/faces/12-image.jpg"
}
],
"support": {
"url": "https://reqres.in/#support-heading",
"text": "To keep ReqRes free, contributions towards server costs are appreciated!"
}
}
Below is the configuration I have made in JMeter
JDBC Request
JSON Extractor
Response Assertion
But I am getting null response:
Assertion Result
what mistake am I making?
I want to compare each cell data with JSON data. For example ID=7 with JSON and ID=9 with JSON and so on.
Is this possible to do this with any scripting language in JMeter, if yes please suggest the code for the same.
There are multiple problems with your setup:
You need to change your SQL query to SELECT ID from HHDIXI.Data, otherwise you will get LAST_NAME entries in the ID variable
You need to change your JSONPath query to $..data[*].id and set "Match No" to -1 otherwise you will get only first ID into idfromAPI variable
Use Debug Sampler and View Results Tree listener combination to see what variables are being generated by the HTTP and JDBC request samplers.
If you want to compare each ID from API to each ID from the DB in one shot the only option is JSR223 Assertion
Example code:
1.upto(vars.get('ID_#') as int, { index ->
def expected = vars.get('ID_' + index)
def actual = vars.get('idfromAPI_' + index)
if (expected != actual) {
AssertionResult.setFailure(true)
AssertionResult.setFailureMessage('Data mismatch, in the database: ' + expected + ', in the API: ' + actual)
}
})
and demo:
In my Strapi project, i'm trying to write a Graphql query that filters posts by an array of tags.
The post has to belong to all tags of the given array.
E.g. the post below would not meet the condition if given array is [1,2,3] but would pass the condition if array is [3,5].
Any help would be much appreciated
Example Post:
{
"id": "1",
"title": "Lorem Iopsum",
"created_at": "2021-02-19T22:53:19.204Z",
"tags": [
{
"id": "3",
"tag": "Porte De Gentily"
},
{
"id": "5",
"tag": "Bridges"
},
{
"id": "6",
"tag": "Towers"
}
]
}
I was trying something like:
query {
posts( where: {tags: {id_contains: [3,1]}}) {
title
tags{id},
created_at
}
}
You can do it something like this
query($ids:[ID]) {
posts( where: {tags: {id:$ids}}) {
title
tags{id},
created_at
}
}
And pass your ids as a query variable:
{
"ids": [1,5]
}
This is the data in fixture file called users.json
When we access this data from Cypress how can we access as it has multiple data in under same name.
[
{
"id": 1,
"name": "Jan Test",
"username": "JTest",
"email": "SJtest#testing.com",
},
{
"id": 2,
"name": "Mark well",
"username": "Mwell",
"email": "mwell#makv.com",
},
{
"id": 3,
"name": "Geet rwar",
"username": "Grwar",
"email": "grwar#mail.com"
}
]
I suggest using Array.prototype.find(). For example
cy.fixture('users.json')
.then(array => {
const userINeed = aray.find(element => element.id === 1)
})
In this code - the array is the data from the fixture, though it needs to be in the fixtures folder
I have the below response from Rest service. I need do capture the value of dSecurityGroup which is "TEST" and pass it to next request. Can yu help on this
"GenericResponse": {
"Service": {
"IdcService": "CHECKIN_UNIVERSAL",
"Document": {
"Field": [
{
"name": "xIPM_APP_1_9:isSetDefault",
"value": "1"
},
{
"name": "IdcService",
"value": "CHECKIN_UNIVERSAL"
},
{
"name": "dSecurityGroup",
"value": "TEST"
},
{
"name": "xIPM_APP_1_6:rule",
"value": "IpmApp_1_Fields_Hide"
},
{
"name": "dpTriggerField",
"value": "xIdcProfile"
},
]
}
}
}
Your JSON response is invalid. check with https://jsonformatter.curiousconcept.com/ and update the correct JSON
Your response is JSON therefore it doesn't make sense to use Regular Expression Extractor.
Consider using JSON Extractor instead, it allows using JsonPath queries which provide handy way to extract the "interesting" values from JSON responses.
In your case the relevant query would be something like:
$..[?(#.name == 'dSecurityGroup')].value
Demo:
More information: API Testing With JMeter and the JSON Extractor
I am trying to extract multiple values from a JSON response on my jmeter script. Below is sample of my response:
{
"startDate": "2018-12-10T15:36:34.400+0000",
"userId": "7211111-2fa90",
"createdBy": "TEST",
"note": {
"content": "Application Submitted "
},
"Type": "SUBMITTED"
},
"currentEventState": "CLOSED",
{
"Xxxx": "test",
"Loc": null,
"Zipcode": [],
"Locality": 82,
"Address": {
"Add": 12302,
"Add2": "place",
"Zip": {
"Phone": "home",
"Email": "test#test.com"
}
},
"state": "MD",
"Cost": "E "
},
"AppID": "cd8d98e6-c2a79",
"Status": "CLOSED",
}
I am trying to extract userid and AppID for the case if the TYPE is Submitted and Status is Closed.I tried using the Json extractor with $.[?(#.Type=="SUBMITTED")].[*].?(#.Status=="CLOSED").userid,APPID, but couldn't get the expected result. Could anyone guide me on this.
You need to use an inline predicate to combine 2 clausees and a semicolon in order to store results into 2 separate JMeter Variables.
Add JSON Extractor as a child of the request which returns above JSON
Configure it as follows:
Names of created variables: userid;appid
JSON Path Expressions: $..[?(#.Type=='SUBMITTED' && #.Status == 'CLOSED')].userId; $..[?(#.Type=='SUBMITTED' && #.Status == 'CLOSED')].AppID
Default values: NA;NA
Here is the demo of single expression working fine:
And here are extracted values reported by the Debug Sampler: