Write a scenario
A scenario names the application under test, lists what to do to it and says how to check each step. Kasm Session Runtime validates the whole file before anything runs. An unknown field, an unknown action word or a second YAML document is rejected at load, before the session is touched.
A scripted scenario needs no model. Only observe: steps, expect: checks, the click_grounded action and the screen postcondition use one, and the tables mark them. With no model configured, the window and process probes decide the verdict and a judgement is recorded as not judged. Every field is in the scenario YAML reference.
Before you start
Section titled “Before you start”- A Kasm session with the runtime in it. See Enable the runtime on a workspace.
- The application’s window title or class, and the name its process runs under.
- For a browser: the browser started with a debugging port (see Browser steps).
Name the application
Section titled “Name the application”app: chromewindow: "Chrom" # substring of the window title or classprocess: "chrome" # substring of the process command linelaunch_timeout_s: 90 # default 60settle_s: 5 # default 5| Field | What it does |
|---|---|
app |
The application under test. Usually left out; KASM_RUNTIME_APP supplies it |
window |
Matched against window titles and classes. Defaults to app |
process |
Matched against process command lines. Defaults to app |
launch_timeout_s |
How long to wait for the window and process before the run is app-failed |
settle_s |
How long to wait after launch before the first check |
If the image does not start the application, add a launch: block. Its output goes to ~/.xsession-errors.
launch: cmd: "blender --python-expr ''" env: {BLENDER_USER_CONFIG: /tmp/cfg}Write the steps
Section titled “Write the steps”steps: holds at most 40 entries. Each has either an action or an observe. Choose each action from as high in the table as the application allows: in the upper rows the application or the author supplies the target, which makes the step cheaper and more reliable. The runtime records the backend that ran each step and, for clicks, where the coordinates came from. See How an action reaches an application.
| Action | What it does | Needs a model |
|---|---|---|
cdp_navigate "<url>" |
Loads a URL in the attached browser tab | No |
cdp_query "<selector>" |
Checks an element exists and reports its visibility and enabled state. Fails if absent | No |
cdp_click "<selector>" |
Clicks an element through the DOM | No |
cdp_click_described "<name>" |
Clicks the element with this accessible name, matched against the page’s interactive elements. Chromium only | No |
cdp_fill "<selector>" "<value>" |
Focuses the field and types the value one key per character. The report records the length, never the value | No |
cdp_wait "<js predicate>" [seconds] |
Waits for a JavaScript expression to be true. Fails with the page’s visible candidates if it never is | No |
cdp_url |
Records the page’s location.href |
No |
cdp_attach "<tab substring>" |
Switches to the tab whose URL or title contains this, ignoring case | No |
click_element "<name>", or click_element "<name>" in "<window>" |
Clicks a control the application publishes over AT-SPI, by name, optionally only in a window whose name contains <window> |
No |
set_text "<name>" "<text>", set_value "<name>" <number>, select "<name>" |
Fills a field, sets a slider or spin button, or chooses a list or tab item through the same interface, each read back afterwards | No |
key "<chord>" |
Presses a key chord: ctrl, alt, shift, super plus a key |
No |
type "<text>" |
Types text verbatim. $VAR and ${VAR} expand from the environment |
No |
click "<name>" |
Clicks a point declared in click_targets |
No |
click <fx> <fy> |
Clicks at fractions of the window, each from 0 to 1 | No |
click center |
Clicks the middle of the application’s window | No |
click_grounded "<description>" |
Asks the vision model where the described thing is, then clicks it. Requires expect: on the same step |
Yes |
wait <seconds> |
Waits | No |
wait_while "<name>" |
Holds while a condition declared in wait_conditions is true |
No |
shell "<name>" |
Runs a command declared in shell. Output is capped |
No |
spawn "<cmd>" |
Starts a tool | No |
kill "<pattern>" |
Stops processes whose command line matches this POSIX extended regular expression | No |
Quoted arguments are taken verbatim, with no backslash escapes. A CSS selector that needs a quote uses the single-quote form: a[title='x'].
click "<name>", wait_while and shell refer to names declared elsewhere in the file:
click_targets: # window fractions, authored with a screenshot in hand render-button: [0.5, 0.12]shell: list-renders: "ls ~/renders"wait_conditions: render-in-progress: kind: process # or growing, with path: match: "blender-render" timeout_s: 300 poll_s: 2 quiet_polls: 3When a native step and a browser tab are both in play, name the target on the step. Otherwise a key chord goes to whichever window has focus.
- action: key "ctrl+alt+t" target: window "Terminal"Browser steps
Section titled “Browser steps”Set cdp: true, or use any cdp_* action, which implies it. The runtime attaches to the browser at http://127.0.0.1:9222, so the browser must start with a debugging port on 9222. Set APP_ARGS on the session. The same steps work on Chromium-family browsers over the Chrome DevTools Protocol and on Firefox over WebDriver BiDi; a Firefox step’s report row names the backend bidi.
For Chrome:
--start-maximized --test-type --ignore-certificate-errors --remote-debugging-port=9222 --remote-debugging-address=127.0.0.1 --remote-allow-origins=* --user-data-dir=/home/kasm-user/.config/chrome-cdp-profile- Chrome 136 and later ignore
--remote-debugging-port, with no error, unless--user-data-diris set. APP_ARGSreplaces the image’s default arguments, so--start-maximizedis restated.- Navigate with
cdp_navigate. A URL on the command line goes to the running Chrome and drops the flags.
For Firefox, start it with --remote-debugging-port=9222 and write app: firefox, window: "Firefox", process: "firefox".
- Begin with
cdp_navigate. Firefox’s first page,about:home, refuses scripts, so every other step fails there. - Selector steps (
cdp_query,cdp_click,cdp_fill,cdp_wait,cdp_url) work.cdp_click_describeddoes not: WebDriver BiDi publishes no accessibility tree, so the step fails as an environment error and the run istest-error.
Accessibility steps
Section titled “Accessibility steps”For a desktop application, click_element, set_text, set_value and select act through the controls the application publishes, with no coordinates. expect_state then asks the application whether the control reached the state you intended, which closes the gap between “the application accepted the action” and “the intended thing happened”.
app: libreofficedesktop: truewindow: "LibreOffice"process: "soffice.bin"steps: - action: click_element "Writer Document" - action: wait 10 - action: type "A sentence to format." - action: key "ctrl+a" - action: click_element "Bold" expect_state: Bold checkeddesktop: true is used here because LibreOffice’s launcher process exits by design and its splash window shares the real window’s title, so window and process detection would misreport it. The run waits for the application to appear on the accessibility bus instead. The 04-atspi-libreoffice example in the toolkit has the full file.
atspi: false removes every accessibility probe and rejects click_element, set_text, set_value, select, expect_state and state postconditions at load.
Check each step
Section titled “Check each step”A step can carry checks. Use the strongest one the application offers.
| Check | What it asks | Needs a model |
|---|---|---|
post: with url, dom, state, window, no_window, process, no_process or file |
Waits up to timeout_s (default 10) for a fact the browser, the application or the system reports |
No |
expect_state: Bold checked |
Asks the application over AT-SPI whether a control is in a state. States: checked, enabled, expanded, focused, pressed, selected, sensitive, showing. Write not before the state to negate it |
No |
cdp_wait as the next step |
A JavaScript expression that must become true | No |
post: with screen |
The vision model judges a description true, once, on a settled screenshot | Yes |
expect: "<description>" |
The vision model judges the description true after the action | Yes |
observe: "<description>" as a step |
The vision model judges a fresh screenshot | Yes |
A post: entry sets exactly one kind. Plans and postconditions lists them all.
- action: cdp_click "button.login" post: - url: "#/dashboard" - dom: "document.getElementById('who').textContent === 'demo-user'" timeout_s: 15To fail the run when a known-fatal line appears in the log:
checks: log_fatal: ["EGL error", "GPU process crashed"]Keep secrets out of the file
Section titled “Keep secrets out of the file”Put credentials in environment variables named KASM_RUNTIME_SECRET_* and refer to them with $.
- action: cdp_fill "#password" "$KASM_RUNTIME_SECRET_PW"Values of KASM_RUNTIME_SECRET_* variables, and values filled from a $VAR reference, are replaced with [REDACTED] in everything the runtime writes. A password drawn on screen still appears in screenshots. See Secrets and evidence.
Run it
Section titled “Run it”Save the file into the session and run it as the session user from a terminal in the session, or through the Kasm API’s exec call.
export KASM_RUNTIME_APP=chromeexport KASM_RUNTIME_OUT=$HOME/outexport KASM_RUNTIME_DEADLINE_S=300export DISPLAY=:1kasm-session-runtime run scenario.yamlLeave KASM_RUNTIME_VISION_ENDPOINT unset for a model-free run. The exit code follows the verdict (0 for pass and pass-with-concerns, 1 for app-failed, 2 for test-error), and $KASM_RUNTIME_OUT/<name>/ holds the report. See Scenarios.
Load errors
Section titled “Load errors”A file that fails to load gives verdict test-error and exit code 2, with the message in summary.json and the report.
| Message | Fix |
|---|---|
unknown action "..." |
Use a word from the action table. The message lists the vocabulary |
needs either `action` or `observe` or has both `action` and `observe`; pick one |
Give the step exactly one |
click_grounded requires `expect:` |
Add expect: saying what the click should change |
click "..." references no declared target; add it to click_targets |
Declare the name, or write the fractions in the step |
fractions must be within 0..1 |
Fractions are of the window |
scenario has N steps; the maximum is 40 |
Split the scenario |
expect_state must end with a state name |
End with one of the listed states |
cdp_targets/cdp_waits are declared but the scenario does not enable cdp: true |
Add cdp: true |
Failures at run time
Section titled “Failures at run time”| Symptom | Cause |
|---|---|
Every cdp_* step fails because the browser’s debugging port is missing |
Chrome started without --user-data-dir and ignored the port |
Navigation lands on chrome-error://chromewebdata/ |
Kasm’s browser images block file:// by policy. Serve the page over loopback HTTP |
| A login times out although it worked | The page never changes document.title. Check location.hash or location.href with cdp_wait or a url postcondition |
no element matches "..." with a list of candidates |
The selector is stale. The candidates show what the page has now |