Variables & templates
Capture a value & reuse itโ
Some flows need a value the app generates at runtime โ an application ID shown on one page, a confirmation number, a token โ fed into a later step (a search box, a URL, an assertion). A Capture step reads a value off the page during replay and stores it in a run-scoped variable you reference later as {{var.NAME}}.
Author a captureโ
While recording, click Capture in the toolbar (next to Assert) โ it turns blue โ then click the element holding the value.
A small menu lets you choose:
- Variable โ the name you'll reference later, e.g.
applicationId(auto-suggested from the element). - What to grab โ the three extraction kinds:
- Text โ the element's visible/accessible text. For labels, spans, headings, table cells.
- Input value โ an
<input>/<textarea>/<select>.value(or a checkbox/radio's checked state). - Attribute โ a named attribute such as
href,data-id, orvalue. For values that live in markup, not visible text.
- Extract (regex) โ optional. Pull just the part you want out of noisy text. If the pattern has a capture group, group 1 is used; otherwise the whole match. e.g.
APP-\d+turnsApplication ID: APP-7741intoAPP-7741.
Click Capture, and a capture step is recorded โ shown in the Events list as capture applicationId โ text .app-id (teal badge).
Reuse the captured valueโ
In any later input value, navigate URL, or assertion text, reference it as {{var.NAME}}. Open the + Template menu (or type {{) โ captured variables appear under a Captured category, so you click to insert; no need to type the var. prefix. The Edit drawer shows the last run's resolved value beneath the field.
The value is read fresh on every run โ only the instruction (selector + variable + kind) is saved in the .trq, never the value โ so it always reflects the current run's data. (The capture step must run before the step that uses it.)
Exampleโ
1. navigate https://app.example.com/journey/123
2. capture applicationId โ text .app-id (regex: APP-\d+)
3. navigate https://backoffice.example.com/search
4. input #search = {{var.applicationId}}
5. click .search-btn
6. assert text-equals {{var.applicationId}} on .result-id
On each run Trq reads the live id (e.g. APP-7742), types it into the back-office search, and asserts the result. Capture works across tabs and cross-origin iframes, and in Play, Resume, and Debug. If a value loads slowly, capture polls until it appears.
Value templatesโ
Any URL, input value, or assertion text accepts {{โฆ}} templates, resolved fresh each run. Type {{ for inline autocomplete, or use the + Template menu:
- reusable โ
{{uuid}},{{randomNumber}},{{randomString}},{{timestamp}}โ generated once per run and reused everywhere the same token appears (see below). - faker โ
{{faker.email}},{{faker.firstName}},{{faker.phone}},{{faker.uuid}}, โฆ - random โ
{{random.string(8)}},{{random.int(1,99)}},{{random.alpha(6)}} - date โ
{{date.iso}},{{date.now}},{{date.future(7)}} - env โ
{{env.MY_VAR}}(reads the environment at run time) - var โ
{{var.NAME}}โ a value grabbed earlier by a Capture step or an API request's Extract; appears under the Captured menu category.
The Edit drawer shows the last run's resolved value beneath each templated field.
Reusable values โ generate once, reuse across stepsโ
The faker / random / date tokens regenerate on every step, so you can't create something on one page and find it on another. The reusable tokens fix that: they generate a value once per run and return that same value wherever the identical token appears โ so you can name an entity in one step and search for it in a later step. A new value is generated on each Play/Resume (so reruns don't collide), stable within that run.
| Token | Value |
|---|---|
{{uuid}} | a v4 uuid |
{{uuid(8)}} | first 8 hex chars (dashes stripped) โ a short id; {{uuid(2,6)}} takes a substring |
{{randomNumber}} / {{randomNumber(1000,9999)}} | a random integer (default 6 digits) |
{{randomString}} / {{randomString(12)}} | random alphanumeric (default length 8) |
{{timestamp}} | run-start epoch milliseconds |
Add a :label for a second, distinct value: {{uuid:orderId}} and {{uuid:invoiceId}} generate two different uuids, each reused under its own name.
3. input #name = page-{{uuid(8)}} โ page-f03a19e0
4. click #create
โฆ
9. input #search = {{uuid(8)}} โ f03a19e0 (same value, same run)
{{uuid(8)}}is its own short id โ not the first 8 chars of{{uuid}}. For a stable handle reused in several places, use a named token consistently (e.g. always{{uuid:orderId}}).