How a cleanup companion runs
A cleanup companion is a test case linked to another test case. When the linked test runs, the companion runs after it, and after every test in the run that depends on the linked test, directly or through other tests.- It runs when the tests fail. A failed test doesn’t stop its companion.
- It doesn’t wait for unrelated tests. A test in the same run that doesn’t depend on the linked test can still be running when the companion calls back.
- It runs once per copy of the linked test. If you link one companion to three tests, it runs three times. If a test depends on two tests that share a prerequisite, Peeps runs each path as its own copy, and each copy of the linked test gets its own companion.
- It starts in a new browser if the linked test failed. A companion that only calls a URL doesn’t need a browser session either way.
- A stopped run may not call back. If someone cancels the run, it hits a hard time limit, or the machine running it stops, the companion may not run.
- Link the companion to a test that every other test in the run depends on, such as the test that signs in.
- Keep the tests below it free of diamonds, where one test depends on two tests that share a prerequisite.
- Make your endpoint safe to call twice, and have your system take the resource back on its own after a timeout.
Write the callback test
1
Store the token in your environment
In Peeps, open Settings and select Environments under Project. In the environment your tests run in, add a variable for your endpoint’s token, such as
POOL_TOKEN, with the type API key. Peeps stores it encrypted.2
Create the test case
Create a test case, for example “Return device to pool”, and set its Test type to Cleanup. A cleanup test only runs as a companion. A test of any other type also runs on its own when a selection that includes it runs, and would call back in the middle of the run.
3
Give it a script
The script calls your URL:Peeps replaces each
{{NAME}} with that environment variable’s value when the run starts. The values come from the environment as it is set in Peeps: the request that started the run can’t add any. See what a call can’t do yet. Your coding agent can add and publish a script you wrote: see add a script you wrote.4
Publish the script
Without a published script, the callback never happens. In a run of several tests, Peeps skips the companion. A run of only its linked test is refused.
Test recordings can include the requests a test makes. Use a token that can only do this one call.
Link it
You need the Contributor role or above.1
Open the test to link it to
Open the test case that should trigger the callback, for example the test every other test depends on.
2
Choose the companion
In the Cleanup companion panel, next to the steps, open Select a cleanup test case… and pick your callback test.
3
Apply the change
Click Preview change to see what it affects, then Apply change. The link applies to future runs.