Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Variable Extractor tab
    In variable extractor tab of a test case, you need to specify the JSON path in "Path" column.
  2. JSON Body Assertions
    In Assertions tab, you need to specify JSON Path for JSON Body assertions in "Property" column.

Note: We are using jsonPath version 0.8.5. Just remove the prefixes "$." in case of JSON object and "$" in case of top level JSON array while defining JSON path expressions in vREST.

Below are some examples on how to define the JSON Pathof most commonly used JSON path expressions.

  1. For JSON Object Data
    Below is the sample JSON Object for reference.

    Code Block
    languagejs
    linenumberstrue
    {
      "summary": "Sample Test Case ...",
      "method": "GET",
      "url": "http://localhost:3000/sample-test-case",
      "expectedResults": {
        "statusCode": 200,
        "headers": [
          {
            "value": "Mon, 27 Jul 2015 06:38:31 GMT",
            "name": "Date"
          },
          {
            "value": "application/json",
            "name": "Content-Type"
          }
        ]
      },
      "createdAt": "2015-02-09T08:22:18.000Z",
      "version.0": "Version 0",
      "version.1": "Version 1"
    }

     

    1. Top Level Property
      1. JSON Path Expression: method
      2. ValueGET
    2. Nested Property
      1. JSON Path ExpressionexpectedResults.statusCode
      2. Value: 200
    3. Nested Property inside an array
      1. JSON Path ExpressionexpectedResults.headers.0.name
      2. Value: Date
    4. When key also having a dot (Use Square Brackets)
      1. JSON Path :Expression ['version.0']
      2. Value: Version 1


  2. For JSON Array Data
    Below is the sample JSON Array for reference.

    Code Block
    languagejs
    linenumberstrue
    [
      {
        "summary": "Sample Test Case 1",
        "method": "GET",
        "url": "http://localhost:3000/sample-test-case1"
      },
      {
        "summary": "Sample Test Case 2",
        "method": "GET",
        "url": "http://localhost:3000/sample-test-case2"
      },
      {
        "summary": "Sample Test Case 3",
        "method": "GET",
        "url": "http://localhost:3000/sample-test-case3"
      }
    ]

     

    1. Nested property from Top level Array
      1. JSON Path Expression: [0].method
      2. Value: GET