I am using soapui with groovy for automation api test and I post a request REST, here is my response:
{`enter code here`
"firstname": "aaa",
"lastname": "bbb",
"address": "test",
"city": "city",
"country": "country",
"default": "false",
"id": "326"
}, {
"firstname": "ddd",
"lastname": "eee",
"address": "test",
"city": "city",
"country": "country",
"default": "True",
"id": "67"
}, {
"firstname": "hhh",
"lastname": "yyy",
"address": "test",
"city": "city",
"country": "country",
"default": "false",
"id": "345"
}, {
"firstname": "ooo",
"lastname": "hh",
"address": "test",
"city": "city",
"country": "country",
"default": "false",
"id": "3211"
},
I want to recover the id of the user who has a default "true"
Firstly, the response you posted is not valid json.
Should be something like this:
[
{
"firstname": "aaa",
"lastname": "bbb",
"address": "test",
"city": "city",
"country": "country",
"default": "false",
"id": "326"
},
{
"firstname": "ddd",
"lastname": "eee",
"address": "test",
"city": "city",
"country": "country",
"default": "True",
"id": "67"
},
{
"firstname": "hhh",
"lastname": "yyy",
"address": "test",
"city": "city",
"country": "country",
"default": "false",
"id": "345"
},
{
"firstname": "ooo",
"lastname": "hh",
"address": "test",
"city": "city",
"country": "country",
"default": "false",
"id": "3211"
}
]
If you're just interested in the groovy script, here it is:
package json
import com.eviware.soapui.support.XmlHolder
import groovy.json.*
//define the location of the JSON response
def response = context.expand('${post_json_data#Response}').toString()
//parse response as json
def json_response = new JsonSlurper().parseText(response)
//iterate on the list with if condition
json_response.eachWithIndex {
item, index ->
if(item.default == 'True') {
log.info "index: ${index}"
log.info "Item default value: ${item.default}"
log.info "Item id value : ${item.id}"
}
}
Related
Is there a mongoose function in order to find a field value and the amount of times it exists in the document.
For example:
"Info": {
"fullName": "full name",
"address": "address",
"city": "city",
"pcode": "PostCode",
"dob": "01/01/2022",
"bin": "411111"
},
"Info": {
"fullName": "full name",
"address": "address",
"city": "city",
"pcode": "PostCode",
"dob": "01/01/2022",
"bin": "411111"
},
"Info": {
"fullName": "full name",
"address": "address",
"city": "city",
"pcode": "PostCode",
"dob": "01/01/2022",
"bin": "411111"
},
"Info": {
"fullName": "full name",
"address": "address",
"city": "city",
"pcode": "PostCode",
"dob": "01/01/2022",
"bin": "400000"
},
I need the function to return something like:
bin: 411111, count: 3
bin: 400000, count: 1
You can use the following aggregation pipeline to achieve exactly what you want:
.aggregate([
{
$group: {
_id: "$Info.bin",
count: {
$sum: 1
}
}
}
])
I am starting out with Postman. I made a simple GET request and got a response. At the end of the response, is "count=14". I am trying to understand what count means here?
I thought the number of records in the response is 14, but its only 10. So what does count=14 mean? Thankyou for your response!
This is the response I got:
{
"records": [
{
"id": "074df210-e1fb-4298-9407-d97881dc1af2",
"fullName": "Abcd",
"email": "janedoe#gmail.com",
"phone": "112-112-112"
},
{
"id": "4f0835d7-7c02-43da-86c7-77a03b4",
"fullName": "John Doe",
"email": "johndoe#gmail.com",
"phone": "1234-234"
},
{
"id": "a9e8cfb6-f62a-4a8e-84a5-df30",
"fullName": "Kitty Doe",
"email": "kittydoe#gmail.com",
"phone": "123-493-892"
},
{
"id": "319bdb34-e1c1-4e86-192",
"fullName": "Lovely Doe",
"email": "lovelydoe#gmail.com",
"phone": "089-829-3898"
},
{
"id": "1dfe5bba-e14b-4e9d-b90c",
"fullName": "Memory Doe",
"email": "memorydoe#gmail.com",
"phone": "273-872-8398"
},
{
"id": "61f466d5-ec00-76ccb88fff5e",
"fullName": "asdas",
"email": "asdas#gmail.com",
"phone": "123-123-9231"
},
{
"id": "f77b8e1d-70f2-4d44-b243-e61eac2a41a0",
"fullName": "asdasda",
"email": "asdasda#gmail.com",
"phone": "123-123-1291"
},
{
"id": "7d071c9e-fce6-4732-bed3-c18412a962c1",
"fullName": "Monday",
"email": "monday#gmail.com",
"phone": "123-129-1231"
},
{
"id": "5a1d1e9d-7396-41e3-aa96-864b",
"fullName": "Tuesday",
"email": "tuesday#gmail.com",
"phone": "123-241-2534"
},
{
"id": "f5da56d1-9fc2861e6da3",
"fullName": "Wednesday",
"email": "wednesday#gmail.com",
"phone": "129-121-1212"
}
],
"count": 14
}
https://github.com/intuit/karate/issues/554
I have a multirow JSON, I would like to iterate for each row using Scenario outline
It is working if I call by the row number, i am using a dynamic JSON file
Data.json
[
{
"address": {
"addressLine1": "ttes",
"addressLine2": "Test"
},
"name": {
"firstName": "TEST",
"lastName": "TEST"
},
"phone": {
"phoneExtension": "1234",
"phoneNumber": "999999999"
},
"email": {
"emailAddress": "TEST#TEST.com"
}
},
{
"address": {
"addressLine1": "ttes1",
"addressLine2": "Test1"
},
"name": {
"firstName": "TEST1",
"lastName": "TEST1"
},
"phone": {
"phoneExtension": "1234",
"phoneNumber": "999999999"
},
"email": {
"emailAddress": "TEST#TEST1.com"
}
}]
Working if
Feature: Read from File
Background:
* def Testdata = read('Data.json')
Scenario Outline: [1] Test with multiple records on JSON
Given url_stg
And path 'test','test'
And request Testdata[0]
When method POST
Examples:
|Testdata |
Working for Testdata[0]. I have dynamic json, I am looking for a way to iterate through the json autoamtically.
My request body should be one row from JSON like :
{
"address": {
"addressLine1": "ttes1",
"addressLine2": "Test1",
},
"name": {
"firstName": "TEST1",
"lastName": "TEST1",
},
"phone": {
"phoneExtension": "1234",
"phoneNumber": "999999999",
},
"email": {
"emailAddress": "TEST#TEST1.com"
}
This will be easier in the next version, see this ticket: https://github.com/intuit/karate/issues/717#issuecomment-489339287
So if you can build from source and test that would help.
For now you have to do this:
And request { address: <address>, name: <name>, phone: <phone>, email: <email> }
How to use scenario outline to iterate for a JSON which is more than single cell
https://github.com/intuit/karate#the-cucumber-way
Data.json
[{
"address": {
"addressLine1": "ttes",
"addressLine2": "Test",
"addressLine3": "Test",
"addressType": "business",
"city": "TEST",
"company": "TEST",
"country": "TEST",
"state": "TEST",
"postalCode": "XXXX"
},
"name": {
"firstName": "TEST",
"lastName": "TEST",
"middleInit": "T",
"title": "Mr."
},
"phone": {
"phoneExtension": "1234",
"phoneNumber": "999999999",
"phoneType": "mobile"
},
"email": {
"emailAddress": "TEST#TEST.com"
}
},
{
"address": {
"addressLine1": "ttes1",
"addressLine2": "Test1",
"addressLine3": "Test1",
"addressType": "business",
"city": "TEST1",
"company": "TEST1",
"country": "TEST1",
"state": "TEST1",
"postalCode": "XXXX"
},
"name": {
"firstName": "TEST1",
"lastName": "TEST1",
"middleInit": "T",
"title": "Mr."
},
"phone": {
"phoneExtension": "1234",
"phoneNumber": "999999999",
"phoneType": "mobile"
},
"email": {
"emailAddress": "TEST#TEST1.com"
}
}]
====
Feature: Read from File
Background:
* def Testdata = read('Data.json')
Scenario Outline: [1] Test with multiple records on JSON
Given url_stg
And path 'test','test'
And request Testdata
When method POST
Examples:
|Testdata |
Please refer it in this documentation as it very straight forward for your case.
dynamic-scenario-outline
refer to this answer for different ways of providing data to Scenario Outline:
https://stackoverflow.com/a/56135752/8615449
I created a job which extracts json datas from a webservice. It works on my PC but not when I export it on my dev. server (Ubuntu Server x64). please help me on this.
ERROR
"Caused by: sun.org.mozilla.javascript.EvaluatorException: Encountered
code generation error while compiling script: generated bytecode for
method exceeds 64K limit. (#1)"
JSON format
"[{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": xxxxx
},
"phoneNumber": [
{
"type": "home",
"number": "xxx xxx-xxxx"
},
{
"type": "fax",
"number": "xxx xxx-xxxx"
}
]
},
{
"firstName": "John",
"lastName": "david",
"age": 28,
"address": {
"streetAddress": "23 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": xxxxx
},
"phoneNumber": [
{
"type": "home",
"number": "xxx xxx-xxxx"
},
{
"type": "fax",
"number": "xxx xxx-xxxx"
}
]
},
{
"firstName": "Jondy",
"lastName": "rodes",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "Kenucky",
"state": "KY",
"postalCode": xxxxx
},
"phoneNumber": [
{
"type": "home",
"number": "xxx xxx-xxxx"
},
{
"type": "fax",
"number": "xxx xxx-xxxx"
}
]
}]"
See this forum post here:
http://forums.pentaho.com/showthread.php?89304-Job-runs-fine-in-Spoon-but-not-in-Kettle-Exceeds-64K-in-Json-Input-step
The suggestion seems to be to use the javascript step then turn off the optimisation option.
64k limit problem with jvm lower versions. Upgrade your java to 1.7 version. Problem will be solve.