> For the complete documentation index, see [llms.txt](https://docs.drizz.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.drizz.dev/writing-tests/which-variable/store-and-set.md).

# Variables

`Store` captures what's on the screen. `SET` assigns a value already available to the script. Both last for one test run.

|                            |                                                                     |
| -------------------------- | ------------------------------------------------------------------- |
| **Platforms**              | Android · iOS                                                       |
| **`SET` right-hand sides** | `{{variable.path}}` · `API.<name>.…` · `screen(...)`                |
| **Reference later as**     | `{{var}}`, and `{{var.field}}` for a `screen(...)` object           |
| **Watch out**              | Writing the same name twice overwrites the first value, permanently |

## Prerequisites

* A test open in the desktop app editor
* The value visible on screen, for `Store` and `screen(...)`
* An API registered under `<name>`, for `SET <var> = API.<name>.…`

## The mechanism

{% tabs %}
{% tab title="SET" %}
Assigns a value the script already has.

```
SET city = "Bangalore"
SET total = {{order.amount}}
SET cart = API.shopease_cart.response
SET item_count = API.shopease_cart.response.items.length
SET promo = screen(the promo banner headline on the home screen)
```

**Use for:** a value fixed for this test, a value from an API step, or several related fields captured as one object.

`SET` accepts exactly four kinds of right-hand side. Anything else fails the step with an explicit error.

| # | Right-hand side      | Example                                                                                      | Use when                                        |
| - | -------------------- | -------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| 1 | A literal            | `SET city = "Bangalore"` · `SET qty = 3` · `SET body = { "key": "value" }`                   | The value is fixed for this test                |
| 2 | Another variable     | `SET total = {{order.amount}}`                                                               | The value is already in a variable              |
| 3 | An API reference     | `SET cart = API.shopease_cart.response` · `.request` · `.status_code` · plus any dotted path | The value comes from an API step                |
| 4 | A `screen(...)` read | `SET promo = screen(the promo banner headline)`                                              | Several related fields are needed as one object |

`SET`  accepts AI expressions.&#x20;

```
SET random_city = ai(pick a random city in India).
```

{% endtab %}
{% endtabs %}

## SET … = screen(...)

`screen(...)` returns an object indexable field by field, unlike `Store`, which returns one value.

```
SET product = screen(the product detail card. format={name: "", price: "", rating: ""}. price is the amount including the currency symbol)

Validate {{product.name}} is visible on the screen
Tap on Add to Cart
Wait Until 2 Seconds

Tap on Cart
Validate that {{product.name}} is visible in the cart
Validate that {{product.price}} is visible beside the item
```

A `screen(...)` read takes three parts:

| Part                | Purpose                                           | Example                                             |
| ------------------- | ------------------------------------------------- | --------------------------------------------------- |
| Surface description | Names the region of the screen to read            | `the product detail card`                           |
| `format={…}`        | The keys to return. `[]` marks a list-valued key  | `format={item_count: "", total: "", items: []}`     |
| Key hint            | Disambiguates any key whose meaning isn't obvious | `price is the amount including the currency symbol` |

```
SET cart_summary = screen(the cart summary panel. format={item_count: "", total: "", items: []}. items is the list of product names shown as rows)
```

## Overwrites are permanent

Variables are a single key/value store. Writing the same name twice replaces the first value, and the original is gone.

## Using and validating a stored value

Reference a stored value anywhere a value goes:

```
Type {{otp_initial}} in the OTP field
Type {{ref_code}} in the referral code box
Type {{order_id}} in the order search field
```

And validate it:

```
Validate that {{order_id}} is visible on the confirmation screen
Validate that {{total_after}} is greater than {{total_before}}
Validate that {{updated_stock}} equals {{current_stock}} plus 10
```

Numeric comparisons do real arithmetic — `greater than`, `less than`, `equals … plus …`. Directional comparisons survive price and tax changes; an exact expected number does not.

## A failed SET may not stop the test

A `SET` step that fails to evaluate can report as passed. The run continues with the variable unset, and later steps act on an empty value.

To catch it, add a validation after any `SET` the rest of the test depends on:

1. Write the `SET` step.

   ```
   SET product = screen(the product detail card. format={name: "", price: ""})
   ```
2. Validate one field of the result on the next line.

   ```
   Validate {{product.name}} is visible on the screen
   ```
3. Run the test and confirm the failure now lands on the `SET`, not three steps later.

## Common mistakes

<table data-search="false"><thead><tr><th>What you write</th><th>What happens</th></tr></thead><tbody><tr><td><code>Validate that order_id is visible</code></td><td>Looks for the literal text <code>order_id</code> on screen. Write <code>{{order_id}}</code></td></tr><tr><td><code>Store the order ID as id</code> when it's only in the backend</td><td>Vision AI reads pixels. It can't see values the app doesn't render</td></tr><tr><td><code>Store the price as p</code> then <code>Type p in the search field</code></td><td>Types the letter <code>p</code>. Reference it as <code>{{p}}</code></td></tr><tr><td>Storing a value that's scrolled off-screen</td><td>Nothing to read. Scroll to it first</td></tr></tbody></table>

## Next

* [Which variable do I use?](/writing-tests/which-variable.md)
* [API steps](/writing-tests/api-steps.md)
* [Validate](/writing-tests/tap/validate.md)

***

*Last updated: 6 August 2026*
