Rest API testing nested json

331 views
Skip to first unread message

Nitin Agrawal

unread,
Dec 9, 2020, 11:04:00 PM12/9/20
to qaf-...@googlegroups.com
Hi,

I am currently using QAF for rest web services testing. can you please let me know how can i achieve below-

#1: How can I read the value from nested json response 
e.g. I want to read  "test2" value below response

example request Response as below:
{
"sender" : "dell",
"data": null,
"error": [
               {
                "code": "123",
                "message": "test1"
               },
               {
                "code": "456",
                "message": "test2"
               },
               {
                "code": "789",
                "message": "test3"
               }
           ]
}


#2: How Can I pass response of one json to request body of another json.

e.g. in below request body how can i pass json response of another request

example Request Body as below:
{
"sender" : "dell",
"data": null,
"error": [            
            <HERE need to pass json response of another request> 
           ]
}


Thanks & Regards,
Nitin

Amit Bhoraniya

unread,
Dec 9, 2020, 11:15:47 PM12/9/20
to qaf-...@googlegroups.com
Hi Nitin,

1. Use JsonPath to get message from the response body.
    Example:
       Then store response body 'error[1].message' into 'errorMessage'

2. Then use variables in your other subsequent request body.
    {
"sender" : "dell",
"data": null,
"error": [            
            "${errorMessage}"
           ]
    }

Regards,
Amit Bhoraniya

--
You received this message because you are subscribed to the Google Groups "qaf users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qaf-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qaf-users/CADWZ3GaOc8ywCY0BWAv7mBHZhRX8xSEPe9G-jG_YG3y2vk7-mw%40mail.gmail.com.

Nitin Agrawal

unread,
Dec 9, 2020, 11:30:26 PM12/9/20
to qaf users
Hi Amit,

Thanks. Will check on #1.
But, In #2 question i want to pass whole json object response1 in request2. example below.
How Can I do that?

 json response1:
{
"data": null,
"error": [
               {
                "code": "123",
                "message": "test1"
               },
               {
                "code": "456",
                "message": "test2"
               }
           ]
}

Json request2:
{
"name" : "raj",
"id": 2,
"more": [            
            <HERE need to pass whole  json response1: of another request> 
           ]
}

Regards,
Nitin

Amit Bhoraniya

unread,
Dec 10, 2020, 12:09:24 AM12/10/20
to qaf-...@googlegroups.com
Try with the solution below.

1. Use json path for the entire response body.
store response body '$' into 'errorMessage'

2. If the above solution doesn't work, then create your custom step like this and call it in your bdd step.

@QAFTestStep(description = "store last response into {variable} variable")
public void storeToVariable(String variable) throws Exception {
ConfigurationManager.getBundle()
.setProperty(variable, new RestTestBase().getResponse().getMessageBody());
}
store last response into 'errorMessage' variable.

Regards,
Amit Bhoraniya


Nitin Agrawal

unread,
Sep 24, 2021, 5:29:29 PM9/24/21
to qaf users


Hi,

I am currently using QAF for rest web services testing. can you please let me know how can i achieve below-

I have API which gives response and that need to save as xlsx file.
i.e. when I ran in postman then after running it then I download file via "save Response->Save to a file->then popup window open to save file at local"

Question: How can I achieve above via code?

Regards,
Nitin
 
 

cjayswal

unread,
Sep 28, 2021, 12:26:16 AM9/28/21
to qaf users
Refer answer to the same question.

શુક્રવાર, 24 સપ્ટેમ્બર, 2021ના રોજ 02:29:29 PM UTC-7 વાગ્યે nitin123...@gmail.com દ્વારા આમ લખવામાં આવ્યું હતું:
Reply all
Reply to author
Forward
0 new messages