Skip to content

Commit b673e8c

Browse files
authored
Merge pull request #1787 from Private1647/stage
Variables revamp
2 parents 1ceba11 + 77be105 commit b673e8c

File tree

8 files changed

+207
-38
lines changed

8 files changed

+207
-38
lines changed
140 KB
Loading
68.9 KB
Loading
175 KB
Loading
122 KB
Loading
108 KB
Loading

docs/kane-ai-using-variables.md

Lines changed: 102 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
id: kane-ai-using-variables
3-
title: KaneAI - Using Variables in Test Cases
3+
title: Variables in KaneAI
44
hide_title: false
55
sidebar_label: Variables
6-
description: Learn how to use variables in the KaneAI test cases
6+
description: Learn how to use variables in KaneAI test cases
77
keywords:
88
- lambdatest automation
99
- lambdatest kaneai
@@ -36,47 +36,126 @@ import {YOUR_LAMBDATEST_USERNAME, YOUR_LAMBDATEST_ACCESS_KEY} from "@site/src/co
3636
},{
3737
"@type": "ListItem",
3838
"position": 3,
39-
"name": "KaneAI Variables",
39+
"name": "Variables",
4040
"item": "https://www.lambdatest.com/support/docs/kane-ai-using-variables/"
4141
}]
4242
})
4343
}}
4444
></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.
4645

47-
## Why Use Variables?
46+
Variables are placeholders that store values, which can be reused across different parts of a test case. In automation, using variables helps make the tests more flexible, reusable, and maintainable. Instead of hardcoding values in test steps, you can define variables, assign them values, and reference them throughout your tests. This reduces redundancy and makes the tests easier to modify, especially when dealing with frequently changing parameters like URLs, credentials, or device configurations. Variables can be accessed directly from https://kaneai.lambdatest.com/variables.
47+
4848
Using variables enables you to:
4949
- Avoid repetitive entries in test cases.
5050
- Get values from within the application under test & store it in variable to validate the accuracy of data.
5151
- Increase the reusability and adaptability of test scripts, especially useful for parameters that might change frequently, such as URLs, credentials, or environmental settings.
5252

53-
## Variable Syntax
54-
To work with variables in KaneAI, you need to follow these syntax rules:
53+
## Types of variables
54+
- **String Variables**: Store simple text values. They can be used for things like usernames, or any textual data. String variables can be created via KaneAI or manually within the session.
55+
56+
- **JSON Variables**: Store structured data in the form of key-value pairs. JSON variables are especially useful for passing complex objects such as API responses. JSON variables are auto-generated from API calls and DB queries used in KaneAI and cannot be created manually.
57+
58+
## Scope of variables
59+
60+
### Local Variables
61+
Local variables can only be defined using natural language or used as a part of an operation when an instrcution is provided by the user. They are only accessible within the specific test case where they are defined. They help ensure that values are isolated and can be used temporarily within a specific context. A local variable can be converted to a global or an environment variable within the authoring session of KaneAI.
62+
63+
### Global Variables
64+
Global variables are accessible across multiple test cases within the entire organisation. They allow values to be reused in multiple places, enhancing consistency and reducing redundancy. Any variable which is converted from local to global has an option to persist value across sessions if the value changes within a session. More details about persist check are added below.
5565

56-
- Variables are defined using natural language such as "set new_variable as value".
57-
- Variable usage can be done using the `{{` prefix to list all existing variables.
58-
- Example: `{{username}}`, `{{phoneNumber}}`, `{{address}}`
66+
### Environment Variables
67+
Environment variables are variables that are typically set for a specific environment (e.g., staging, production). They are useful for managing values like URLs, or credentials that differ based on the environment in which the tests are being executed. Using environment variables you can execute your test on multiple environments easily. More details about environments are added below.
5968

60-
## Creating Variables
61-
To create a variable:
69+
## How to create & edit variables
70+
Variables can be created using the following three methods:
6271

63-
- Navigate to the "Write a Step" text field
64-
- Type your instruction in natural language such as: *Set username as John* and a variable `{{username}}` will be created with value John.
72+
### Using Slash "/" Command in authoring session
73+
You can define variables directly by using the `/` command in the step input and select "Add a variable" option. You are allowed to create _global_ and _environment_ variables using this approach and define their values.
74+
The value of variables can be edited by clicking on the variables listing icon on the top right.
75+
76+
<img loading="lazy" src={require('../assets/images/kane-ai/knowledge-base/variables/variable-listing-in-session.jpg').default} alt="Image" className="doc_img img_center"/>
77+
78+
### Using Natural Language in authoring session
79+
KaneAI allows you to create variables using natural language. For instance, you can write:
6580

66-
Example:
6781
```bash
6882
Set username as John
6983
```
84+
This will automatically create a _local_ variable {{username}} with the value "John".
85+
For such _local_ variables, only the scope of the variable can be changed to a global with an option to enable the persist check which ensures that the value when updated in one session or test execution gets persistes across sessions and test executions.
86+
87+
88+
### Via UI from Variables page
89+
By visiting the [variables page](https://kaneai.lambdatest.com/variables), you can click on "Create new" option and add relevant details and scope. You can list of all global and environment variables on this page.
90+
You can edit the session value for the variables here which will lead to updation of the value in all new test executions and sessions for that variable.
7091

71-
## Using Variables
72-
To use a previously created variable in any subsequent step or test case, reference the variable using the same `{{` syntax. This will list down all existing variables for this test. Format: *use the value of `{{variableName}}`*
92+
## How to leverage variables during authoring
93+
Variables can be used to enhance your test cases, making them more dynamic.
94+
95+
### Syntax for Assertions
96+
Variable usage can be done using the `{{` prefix to list all existing variables in the KaneAI session input box. When making assertions in your test case, you can use variables for inputing a value or as part of the assertion logic.
97+
98+
<img loading="lazy" src={require('../assets/images/kane-ai/knowledge-base/variables/syntax.jpg').default} alt="Image" className="doc_img img_center"/>
99+
100+
#### String variables example:
73101

74-
Example:
75102
```bash
76-
use the value of {{phoneNumber}} in the given text field
103+
Enter {{username}} in user input field
77104
```
105+
This will input the value of the username variable in the user input field.
106+
107+
```bash
108+
assert {{username}} contains 'John'
109+
```
110+
This will assert if the username variable contains the value "John".
111+
112+
#### JSON variables example:
113+
JSON variables are generated from the response of an API used via the slash command or from the DB query output. We can use JSON variables to reach a particular object which might be inside the JSON hierarchy via the UI when the `{{` prefix is used in the input box inside the KaneAI session. For instance, we can assert that the email field inside the API variable response matches "john.doe@example.com".
114+
115+
```bash
116+
assert {{api_variable.response.email}} is 'john.doe@example.com'
117+
```
118+
Here is a video to further explain the JSON variables usage:
119+
<video class="right-side" width="100%" controls id="vid">
120+
<source src= {require('../assets/images/kane-ai/knowledge-base/variables/json-variable.mp4').default} type="video/mp4" />
121+
</video>
122+
123+
## Persist Value in Variables
124+
125+
Persist value check is a mechanism used to ensure that variables retain their values across multiple test executions. This is important for situations where a variable’s value should be preserved between test cases and test executions to ensure consistency. For example, if you fetch a value from the AUT in a test while authoring, you may want to persist it for the other test cases even during test executions.
126+
127+
:::tip
128+
The persist check option becomes available only when you change a variable's scope from local to global.
129+
:::
130+
131+
<img loading="lazy" src={require('../assets/images/kane-ai/knowledge-base/variables/persist-value.jpg').default} alt="Image" className="doc_img img_center"/>
132+
133+
## Environments
134+
135+
### What are Environments?
136+
Environments in KaneAI refer to the different configurations under which the tests are executed. Environments typically represent different stages of deployment (e.g., development, staging, production). Each environment can have its own set of variables tailored to the respective deployment scenario.
137+
138+
<img loading="lazy" src={require('../assets/images/kane-ai/knowledge-base/variables/environment.jpg').default} alt="Image" className="doc_img img_center"/>
139+
140+
### How to Use Environments During Test Runs
141+
Once a test case is authored using environment variables, it can then be executed in any environment as long as the variables used in the test case, exist in the requested environment.
142+
143+
**UI**: While executing a test run or scheduling one, you can choose which environment they want to execute a test run on. All the test cases inside a test run can be executed on a single environment only at a point of time.
144+
145+
<img loading="lazy" src={require('../assets/images/kane-ai/knowledge-base/variables/test-run-environment.jpg').default} alt="Image" className="doc_img img_center"/>
146+
147+
**API**: You can pass environment name programmatically when initiating test runs via the API. This allows you to automate the execution of tests in different environments without manual intervention. For instance,
148+
149+
```bash
150+
curl --location 'https://test-manager-api.lambdatest.com/api/atm/v1/hyperexecute' \
151+
--header 'Content-Type: application/json' \
152+
--header 'Authorization: Basic <Base64Auth>' \
153+
--data '{
154+
"test_run_id": "YOUR_TEST_RUN_ID", #enter test run id
155+
"concurrency": 1,
156+
"environment": "staging" #Optional
157+
```
158+
159+
This will run the test case in the "staging" environment.
160+
78161
79-
## Best Practices
80-
### Naming Conventions
81-
- Use descriptive names for your variables
82-
- Use camelCase or underscore for multi-word variable names
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
id: kaneai-variables-and-parameters
3+
title: Variables & Parameters in KaneAI
4+
hide_title: false
5+
sidebar_label: Variables & Parameters
6+
description: Details and information about variables & parameters in KaneAI
7+
keywords:
8+
- kaneai
9+
- variables
10+
- parameters
11+
- secrets
12+
- smart variables
13+
- environments
14+
url: https://www.lambdatest.com/support/docs/kaneai-variables-and-parameters/
15+
site_name: Variables & Parameters in KaneAI
16+
slug: kaneai-variables-and-parameters/
17+
---
18+
19+
<script type="application/ld+json"
20+
dangerouslySetInnerHTML={{ __html: JSON.stringify({
21+
"@context": "https://schema.org",
22+
"@type": "BreadcrumbList",
23+
"itemListElement": [{
24+
"@type": "ListItem",
25+
"position": 1,
26+
"name": "Home",
27+
"item": "https://www.lambdatest.com"
28+
},{
29+
"@type": "ListItem",
30+
"position": 2,
31+
"name": "Support",
32+
"item": "https://www.lambdatest.com/support/docs/"
33+
},{
34+
"@type": "ListItem",
35+
"position": 3,
36+
"name": "Variables & Parameters",
37+
"item": "https://www.lambdatest.com/support/docs/kaneai-variables-and-parameters"
38+
}]
39+
})
40+
}}
41+
></script>
42+
43+
In KaneAI, one of the core principles of effective test automation is the ability to manage dynamic data efficiently. Testing often requires input that changes frequently or is context-dependent, such as URLs, credentials, or specific device configurations. KaneAI offers a set of powerful tools—variables, secrets, smart variables, parameters and datasets—to simplify the process of managing and using dynamic data in your test cases. Each of these options offers unique functionality that helps you keep your tests flexible, secure, and scalable.
44+
45+
:::tip
46+
All variables and parameters in KaneAI can be access from https://kaneai.lambdatest.com/variables
47+
:::
48+
49+
<!-- ### Core Features -->
50+
<div className="support_main">
51+
52+
<a href = "/support/docs/kane-ai-using-variables/">
53+
<div className="support_inners">
54+
<h3>Variables</h3>
55+
<p>Placeholders that store dynamic values, enabling reuse and reducing redundancy in test cases.</p>
56+
</div>
57+
</a>
58+
59+
<a href="/support/docs/kane-ai-secrets/">
60+
<div className="support_inners">
61+
<h3>Secrets</h3>
62+
<p>Securely stored sensitive data (e.g., passwords) that are used in tests without exposing them in the code.</p>
63+
</div>
64+
</a>
65+
66+
<a href="/support/docs/hyperexecute-artifacts-url/">
67+
<div className="support_inners">
68+
<h3>Smart Variables</h3>
69+
<p>Context-aware variables that automatically pull data in real-time during test execution.</p>
70+
</div>
71+
</a>
72+
73+
<a href = "/support/docs/kane-ai-using-parameters/">
74+
<div className="support_inners">
75+
<h3>Parameters</h3>
76+
<p>Values passed into test cases at runtime to customize test execution for different configurations or environments.</p>
77+
</div>
78+
</a>
79+
80+
<a href="/support/docs/kane-ai-using-datasets/">
81+
<div className="support_inners">
82+
<h3>Datasets</h3>
83+
<p>Collections of test data used in a test, allowing for data-driven testing by running the same test with different inputs.</p>
84+
</div>
85+
</a>
86+
87+

sidebars.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,22 @@ module.exports = {
11671167
"test-runs-configurations",
11681168
],
11691169
},
1170+
{
1171+
type: "category",
1172+
collapsed: true,
1173+
label: "Variables and Parameters",
1174+
link: {
1175+
type: "doc",
1176+
id: "kaneai-variables-and-parameters",
1177+
},
1178+
items: [
1179+
"kane-ai-using-variables",
1180+
"kane-ai-secrets",
1181+
"kane-ai-smart-variables",
1182+
"kane-ai-using-parameters",
1183+
"kane-ai-using-datasets",
1184+
],
1185+
},
11701186
{
11711187
type: "category",
11721188
collapsed: true,
@@ -1178,23 +1194,10 @@ module.exports = {
11781194
"kane-ai-scroll-in-feature",
11791195
"kane-ai-jira-integration",
11801196
"kane-ai-api-testing",
1181-
"kaneai-network-throttling",
1182-
{
1183-
type: "category",
1184-
collapsed: true,
1185-
label: "Variables and Parameters",
1186-
items: [
1187-
"kane-ai-using-variables",
1188-
"kane-ai-using-json-variables",
1189-
"kane-ai-using-parameters",
1190-
"kane-ai-using-datasets",
1191-
],
1192-
},
1197+
"kaneai-network-throttling",
11931198
"kane-ai-modules",
1194-
"kane-ai-secrets",
1195-
"kane-ai-smart-variables",
1196-
"kaneai-upload-and-download-files",
11971199
"kaneai-modules-versions-and-enhancement",
1200+
"kaneai-upload-and-download-files",
11981201
"kane-ai-assertions",
11991202
"kaneai-dynamic-url-replacement",
12001203
"kaneai-chrome-options",

0 commit comments

Comments
 (0)