|
| 1 | +--- |
| 2 | +id: kane-ai-using-variables |
| 3 | +title: KaneAI - Using Variables in Test Cases |
| 4 | +hide_title: false |
| 5 | +sidebar_label: Variables Guide |
| 6 | +description: Learn how to use variables in the KaneAI test cases |
| 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-variables/ |
| 13 | +site_name: LambdaTest |
| 14 | +slug: kane-ai-using-variables/ |
| 15 | +--- |
| 16 | + |
| 17 | +import Tabs from '@theme/Tabs'; |
| 18 | +import TabItem from '@theme/TabItem'; |
| 19 | +import CodeBlock from '@theme/CodeBlock'; |
| 20 | +import {YOUR_LAMBDATEST_USERNAME, YOUR_LAMBDATEST_ACCESS_KEY} from "@site/src/component/keys"; |
| 21 | + |
| 22 | +<script type="application/ld+json" |
| 23 | + dangerouslySetInnerHTML={{ __html: JSON.stringify({ |
| 24 | + "@context": "https://schema.org", |
| 25 | + "@type": "BreadcrumbList", |
| 26 | + "itemListElement": [{ |
| 27 | + "@type": "ListItem", |
| 28 | + "position": 1, |
| 29 | + "name": "Home", |
| 30 | + "item": "https://www.lambdatest.com" |
| 31 | + },{ |
| 32 | + "@type": "ListItem", |
| 33 | + "position": 2, |
| 34 | + "name": "Support", |
| 35 | + "item": "https://www.lambdatest.com/support/docs/" |
| 36 | + },{ |
| 37 | + "@type": "ListItem", |
| 38 | + "position": 3, |
| 39 | + "name": "KaneAI Jira Integration", |
| 40 | + "item": "https://www.lambdatest.com/support/docs/kane-ai-using-variables/" |
| 41 | + }] |
| 42 | + }) |
| 43 | + }} |
| 44 | +></script> |
| 45 | +The new variable definition feature in KaneAI allows users to define reusable variables, assign them values, and use those values within test cases. This feature enhances flexibility, readability, and consistency across test cases, making it easier to maintain and modify them. |
| 46 | + |
| 47 | +## Why Use Variables? |
| 48 | +Using variables enables you to: |
| 49 | +- Avoid repetitive entries in test cases. |
| 50 | +- Update values in one place without needing to modify multiple test cases. |
| 51 | +- Increase the reusability and adaptability of test scripts, especially useful for parameters that might change frequently, such as URLs, credentials, or environmental settings. |
| 52 | + |
| 53 | +## Variable Syntax |
| 54 | +To work with variables in KaneAI, you need to follow these syntax rules: |
| 55 | + |
| 56 | +- Variables are defined using the `$` prefix |
| 57 | +- Variable names should follow the `$` symbol without any spaces |
| 58 | +- Example: `$username`, `$phoneNumber`, `$address` |
| 59 | + |
| 60 | +## Creating Variables |
| 61 | +To create a variable: |
| 62 | + |
| 63 | +- Navigate to the "Write a Step" text field |
| 64 | +- Type your instruction using the following format: *create a variable `$variableName`* |
| 65 | + |
| 66 | +Example: |
| 67 | +```bash |
| 68 | +create a variable $phoneNumber |
| 69 | +``` |
| 70 | + |
| 71 | +## Using Variables |
| 72 | +To use a previously created variable in any subsequent step or test case, reference the variable using the same `$` syntax. Format: *use the value of `$variableName`* |
| 73 | + |
| 74 | +Example: |
| 75 | +```bash |
| 76 | +use the value of $phoneNumber in the given text field |
| 77 | +``` |
| 78 | +<img loading="lazy" src={require('../assets/images/kane-ai/knowledge-base/variables/1.png').default} alt="kenai-jira integration" className="doc_img"/> |
| 79 | + |
| 80 | +## Best Practices |
| 81 | +### Naming Conventions |
| 82 | +- Use descriptive names for your variables |
| 83 | +- Avoid special characters except for the required $ prefix |
| 84 | +- Use camelCase for multi-word variable names |
| 85 | + |
| 86 | +### Variable Management |
| 87 | +- Create variables at the beginning of your test case when possible |
| 88 | +- Document the purpose of each variable in comments |
| 89 | +- Verify that variables are defined before using them |
0 commit comments