Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jmeter JSON Path Assertion

Below is my JSON response data, I need to do assertion using the below response. I tried in many ways to write JSON path & Expected Value. Always assertion fails. What I want is please help to write the path and expected value for the below data

{
    "statusCode": 200,
    "statusMessage": "Success",
    "errorMessage": "",
    "responseData": {
        "id": 15,
        "userName": "[email protected]",
        "firstName": "tarento",
        "lastName": "test1",
        "phoneNumber": "1234567812",
        "email": "[email protected]",
        "password": "",
        "city": "",
        "agentList": [
            {
                "id": 37,
                "userName": "[email protected]",
                "firstName": "Sanjay",
                "lastName": "rahul",
                "phoneNumber": "7411269480",
                "email": "[email protected]",
                "password": "",
                "active": true
            },
            {
                "id": 68,
                "userName": "[email protected]",
                "firstName": "jinesh",
                "lastName": "sumedhan",
                "phoneNumber": "9400993826",
                "email": "[email protected]",
                "password": "",
                "active": true
            },
            {
                "id": 108,
                "userName": "[email protected]",
                "firstName": "Rahul",
                "lastName": "Antony",
                "phoneNumber": "9994590241",
                "email": "[email protected]",
                "password": "",
                "active": true
            },
            {
                "id": 304,
                "userName": "[email protected]",
                "firstName": "Agent",
                "lastName": "Agent",
                "phoneNumber": "9025699716",
                "email": "[email protected]",
                "password": "",
                "active": true
            }
        ],
        "roleName": "admin",
        "sessionKey": "435tnerLt9813942160478oDse46345635#1",
        "partner": {
            "id": 1,
            "name": "Tarento",
            "cityList": [
                "bangalore",
                "mumbai"
            ],
            "phone": "1234567812",
            "url": ""
        },
        "isActive": true,
        "isDeleted": false,
        "roleId": 1,
        "countryCode": "",
        "tags": [
            {
                "tagId": 1,
                "name": "all",
                "description": "this is default tag of all driver."
            },
            {
                "tagId": 2,
                "name": "airport",
                "description": ""
            },
            {
                "tagId": 3,
                "name": "street",
                "description": "any text message"
            },
            {
                "tagId": 255,
                "name": "night",
                "description": "night"
            }
        ]
    }
}

I received the following response

like image 401
Sreenivas Avatar asked Feb 25 '14 06:02

Sreenivas


People also ask

How JSON path assert in JMeter?

Open the JMeter and then add Thread Group to the Test Plan. And then, enter the server address and path details as below. Select Additionally Asset value option and enter $. in the Assert Json Path Exists.

What is JSON assertion?

The JSONPath Match assertion uses a JSONPath expression to select content from the target property and compare the result to the value you expect. The assertion passes if they are matching, otherwise it fails. This assertion applies only to requests and responses, bodies of which contain JSON data.

What is XPath assertion in JMeter?

The XPath Assertion allows an XPath evaluation against a Web server response to ensure the specified entity is present or an element attribute value matches expectations. For more information on how to use XPath for correlation, consult Using the XPath Extractor in JMeter.


Video Answer


1 Answers

For start following JSONPath Assertion will test your statusCode

$.statusCode

put 200 to Expected Value of JSONPath Assertion.

This one is for userName

$.responseData.userName

Easy, isn't it? See Parsing JSON guide for more useful examples and how-tos.

like image 166
Dmitri T Avatar answered Oct 18 '22 19:10

Dmitri T