|
| 1 | +--- |
| 2 | +id: kane-ai-using-json-variables |
| 3 | +title: KaneAI - Utilizing JSON Variables for Assertions |
| 4 | +hide_title: false |
| 5 | +sidebar_label: JSON Variables Guide |
| 6 | +description: Learn how to use JSON variables in the KaneAI test cases for assertions |
| 7 | +keywords: |
| 8 | + - lambdatest automation |
| 9 | + - lambdatest kaneai |
| 10 | + - kaneai scroll elements |
| 11 | + - kaneai sidebar scroll |
| 12 | +url: https://www.lambdatest.com/support/docs/kane-ai-using-json-variables/ |
| 13 | +site_name: LambdaTest |
| 14 | +slug: kane-ai-using-json-variables/ |
| 15 | +--- |
| 16 | + |
| 17 | +<script type="application/ld+json" |
| 18 | + dangerouslySetInnerHTML={{ __html: JSON.stringify({ |
| 19 | + "@context": "https://schema.org", |
| 20 | + "@type": "BreadcrumbList", |
| 21 | + "itemListElement": [{ |
| 22 | + "@type": "ListItem", |
| 23 | + "position": 1, |
| 24 | + "name": "Home", |
| 25 | + "item": "https://www.lambdatest.com" |
| 26 | + },{ |
| 27 | + "@type": "ListItem", |
| 28 | + "position": 2, |
| 29 | + "name": "Support", |
| 30 | + "item": "https://www.lambdatest.com/support/docs/" |
| 31 | + },{ |
| 32 | + "@type": "ListItem", |
| 33 | + "position": 3, |
| 34 | + "name": "KaneAI Jira Integration", |
| 35 | + "item": "https://www.lambdatest.com/support/docs/kane-ai-using-json-variables/" |
| 36 | + }] |
| 37 | + }) |
| 38 | + }} |
| 39 | +></script> |
| 40 | +This document outlines the process of using JSON variables in KaneAI to assert specific objects within an API response. The guide provides a step-by-step procedure for executing API calls, examining responses, and performing assertions on both status and body of the response. |
| 41 | + |
| 42 | +## Prerequisites |
| 43 | +- Access to KaneAI platform |
| 44 | +- Basic understanding of API testing |
| 45 | +- Familiarity with JSON structures |
| 46 | + |
| 47 | +## Step 1: Understanding JSON Variable Assertions |
| 48 | +In KaneAI, you can use JSON variables to perform detailed assertions on API responses. This allows you to validate specific objects and elements within the response structure. |
| 49 | + |
| 50 | +## Step 2: Initiating an API Call |
| 51 | +- Navigate to your desired API endpoint (e.g., a pet store website) |
| 52 | +- Configure the necessary API call parameters |
| 53 | +- Execute the API request |
| 54 | + |
| 55 | +### Example Workflow: |
| 56 | +- Select the appropriate HTTP method (GET, POST, etc.) |
| 57 | +- Add required headers |
| 58 | +- Input any necessary request body |
| 59 | +- Send the request |
| 60 | + |
| 61 | +<img loading="lazy" src={require('../assets/images/kane-ai/knowledge-base/variables/json-variable/image2.jpg').default} alt="Image" className="doc_img img_center"/> |
| 62 | + |
| 63 | +## Step 3: Accessing Response Variables |
| 64 | +After executing the API call, KaneAI automatically generates variables containing: |
| 65 | +- Response status code |
| 66 | +- Response body |
| 67 | +- Response headers |
| 68 | +- Other relevant metadata |
| 69 | + |
| 70 | +<img loading="lazy" src={require('../assets/images/kane-ai/knowledge-base/variables/json-variable/image3.jpg').default} alt="Image" className="doc_img img_center"/> |
| 71 | + |
| 72 | +## Step 4: Asserting Response Status |
| 73 | +To assert the response status: |
| 74 | + |
| 75 | +- Use double curly braces `{{` to access the variable list |
| 76 | +- Navigate using arrow keys to select the status variable |
| 77 | +- Define your expected status code |
| 78 | + |
| 79 | +<img loading="lazy" src={require('../assets/images/kane-ai/knowledge-base/variables/json-variable/image4.jpg').default} alt="Image" className="doc_img img_center"/> |
| 80 | + |
| 81 | +### Example: |
| 82 | +- Expected status: 200 |
| 83 | +- If actual status is 500, the assertion will fail |
| 84 | + |
| 85 | +<img loading="lazy" src={require('../assets/images/kane-ai/knowledge-base/variables/json-variable/image5.jpg').default} alt="Image" className="doc_img img_center"/> |
| 86 | + |
| 87 | +## Step 5: Asserting Response Body |
| 88 | +Navigate through the response body using the same double curly brace method: |
| 89 | +- Open the variable selection menu with `{{` |
| 90 | +- Browse to the specific JSON element you want to validate |
| 91 | +- Create an assertion for that element |
| 92 | + |
| 93 | +<img loading="lazy" src={require('../assets/images/kane-ai/knowledge-base/variables/json-variable/image6.jpg').default} alt="Image" className="doc_img img_center"/> |
| 94 | + |
| 95 | +### Example Validation: |
| 96 | +- Check if 'dogs' element exists in the response |
| 97 | +- Verify specific property values |
| 98 | +- Validate nested JSON structures |
| 99 | + |
| 100 | +<img loading="lazy" src={require('../assets/images/kane-ai/knowledge-base/variables/json-variable/image7.jpg').default} alt="Image" className="doc_img img_center"/> |
| 101 | + |
| 102 | +<br /> |
| 103 | + |
| 104 | +## Video Explanation |
| 105 | +<video class="right-side" width="100%" controls id="vid"> |
| 106 | +<source src= {require('../assets/images/kane-ai/knowledge-base/variables/json-variable.mp4').default} type="video/mp4" /> |
| 107 | +</video> |
0 commit comments