Variables and dimensions
A variable holds something a request borrows: a host, a page size, a user name. A dimension is one axis those values vary along, such as the environment you point at, the region that serves it, or the kind of account you are signed in as. Declare the axis once and give each of its values the variables that belong to it, instead of keeping a copy of the whole set per environment.
Start with no axis at all. Values that are the same everywhere go in a vars block in environment.stamp, the file at the top of the workspace.
# environment.stamp
vars {
baseUrl = "https://jsonplaceholder.typicode.com"
pageSize = 10
}
Every file below it reads those names with {{ }}.
# posts.stamp
### List posts
GET {{baseUrl}}/posts?_limit={{pageSize}}
> assert status == 200
> assert body.length == pageSize
The two names are filled in when the request is sent, not when the file is saved. A value is an expression rather than a string: pageSize is the number 10, which is why the last line can compare it with the length of the list that came back. Quote text, write numbers bare.
Run the file and both assertions hold.
stamp run posts.stamp
→ GET https://jsonplaceholder.typicode.com/posts?_limit=10 posts.stamp › listPosts
200 OK 54 ms 3 KB
✓ status == 200
✓ body.length == pageSize
✓ 1 request, 2 assertions
One axis. The host is the first thing that differs between a laptop and a deployed API. Name the axis, then give each value its own block. A block with no conditions still applies everywhere.
# environment.stamp
dimension env = test, staging, prod
vars {
pageSize = 10
}
vars env=test {
baseUrl = localhost(3000)
}
vars env=staging|prod {
baseUrl = "https://jsonplaceholder.typicode.com"
}
localhost(3000) writes localhost:3000, and a URL with no scheme is sent over http. staging|prod matches either value, so one block serves both. The request file does not change at all: it still asks for {{baseUrl}}/posts, and which host that is depends on the value picked when it runs.
stamp run posts.stamp env=staging
→ GET https://jsonplaceholder.typicode.com/posts?_limit=10 posts.stamp › listPosts
200 OK 52 ms 3 KB
✓ status == 200
✓ body.length == pageSize
✓ 1 request, 2 assertions
A dimension you leave out uses its first value, so test is the default here, and stamp run posts.stamp on its own asks port 3000 of your own machine. With nothing listening there it says so and stops. This is what the wrong environment looks like, and it is worth meeting on purpose once:
stamp run posts.stamp
→ GET http://localhost:3000/posts?_limit=10 posts.stamp › listPosts
✗ could not connect to localhost
✗ 1 request, 1 failed
So put the value you use most often first. Writing env=* picks the first value as well; running over every value of an axis is what a test plan's matrix is for.
Two axes. Add a second dimension and nothing about the first changes. Each one is chosen separately, and every block whose conditions match contributes its variables.
# environment.stamp
dimension env = test, staging, prod
dimension userGroup = admin, member, guest
vars {
pageSize = 10
}
vars env=test {
baseUrl = localhost(3000)
}
vars env=staging|prod {
baseUrl = "https://jsonplaceholder.typicode.com"
}
vars userGroup=guest {
pageSize = 3
}
Choosing env=staging and userGroup=guest takes baseUrl from one block and pageSize from another, and the request asks the staging host for three posts. Three values on one axis and three on the other describe nine environments, in a file shorter than two of them written out longhand.
To see what a combination comes to before sending anything, ask for it. The right-hand column is the answer to "where did that value come from".
stamp env . env=staging userGroup=guest
Dimensions
env test | staging | prod
userGroup admin | member | guest
Variables
readJson readJson() files
readText readText() files
pageSize 3 environment.stamp vars userGroup=guest
baseUrl https://jsonplaceholder.typicode.com environment.stamp vars env=staging|prod
readJson and readText are the two file-reading helpers, always present. In the terminal the chosen value of each dimension is the one in colour; in the window the same answer is in the inspector, named per variable.
That is the whole idea. The rest of this section is for the day one axis stops being enough.
When two blocks set the same name. A block with more conditions wins over a broader one, and two blocks with the same number of conditions apply in the order they are written. So a general rule and its exception can sit in the same file, and the row that answers which one applied says so:
vars userGroup=guest {
pageSize = 3
}
vars env=prod, userGroup=guest {
pageSize = 1
}
stamp env . env=prod userGroup=guest
pageSize 1 environment.stamp vars env=prod, userGroup=guest
The chosen value is a variable too. env and region can be read like anything else, which is how a family of hosts collapses into one line:
dimension env = test, staging, prod
dimension region = latam, mena, apac, dach
vars env=staging|prod, region=latam {
baseUrl = "https://api." + env + ".latam.example.com"
}
An account per group. The other common axis is who is signed in. The values go in the same file, and a password belongs in secret(...) so it stays out of the output. See Secrets for where that value is written.
vars userGroup=admin {
username = "emilys"
password = secret("emilyspass")
}
vars userGroup=guest {
username = "sophiab"
password = secret("sophiabpass")
}
Smaller scopes. Not everything belongs to the workspace. A file and a single request can declare their own. @name = text is text with interpolation; let name = expression is computed once, the first time something reads it.
# at the top of a file, so every request in it has them
@acceptLanguage = en-GB
let runId = uuid()
### Create a post
@name createPost
@timeout 10s
POST {{baseUrl}}/posts
Accept-Language: {{acceptLanguage}}
X-Run-Id: {{runId}}
Content-Type: application/json
{ "title": "Release notes", "userId": 1 }
> assert status == 201
When the same name is set in more than one place, the lower row wins:
| the environment | every matching vars block |
| the file | @name and let before the first request |
| the session | values stored with set, and earlier responses by name |
| the request | @name and let inside it |
| the command line | -v name=value |
stamp run posts.stamp -v baseUrl=https://jsonplaceholder.typicode.com
A value given with -v arrives as text, so use it for hosts and names rather than for numbers an assertion compares.
In the app
- Click the selector in the row with the request's title. It names every dimension and the value in effect for it, and opens a list of all of them. A test plan and a load test carry the same selector, and the Environment menu holds the same values.
- Click a value to choose it. The list closes and the selector says what is now in effect. Any leaves that dimension unnarrowed, and once more than one combination is in play the foot of the list says how many the run comes to.
- Choose All Combinations…, from the foot of that list or from the Environment menu, for one table with a column per set of conditions and a row per variable. Editing a value there writes it back to
environment.stamp. Edit Dimensions…, beside it, is for the axes themselves. - Click Variables in the toolbar to open the inspector. In Effect for This Request lists every name with its value and the file and
varsblock that decided it, which is the same answerstamp envprints. - Set Stored in to Shared or This Mac before Add Variable, and the line under it names the file and the
varsblock the new variable goes into. - Choose Environment ▸ Reset Session (⇧⌘K) to forget the values runs have stored.
The window answers two questions the file cannot. The selector says which combination you are about to run without reading any vars blocks, and the inspector names the file each value came from for the request you have open, so a value that surprises you is traced in one look rather than by searching.



Next: Secrets for the values that must not be committed, Authentication for turning a user name and a password into a signed-in request, and Test plans for running one plan across every value of an axis.