CLI Guide¶
This section describes the available commands for the Optics Framework CLI. The command you run is optics; the package you install is optics-framework (e.g. pip install optics-framework).
First run¶
Run optics with no arguments to see a welcome screen and the golden path:
It points you at optics quickstart (guided setup), optics doctor (environment check), and optics --help. The first run also writes a marker at ~/.optics/.onboarded so the greeting introduces itself only once; delete that file to see the first-run greeting again. If ~/.optics/ isn't writable (read-only HOME, containers, CI), set OPTICS_HOME to a directory that is — the marker lands there instead.
Guided Setup: optics quickstart¶
New to Optics? One command walks you from nothing to a runnable project:
It combines the commands below into one guided flow — welcome banner, engine install (setup), project scaffold (init), config Q&A (configure), and a doctor verification — then prints next steps tailored to your choices. See the Getting Started Guide for what each stage sets up.
Setup: install engine backends¶
The core install ships without drivers, OCR, or LLM backends — they are optional extras. optics setup installs them by name (the names match the config.yaml source keys, e.g. appium, easyocr, google-vision), pinned to your installed Optics version.
List installable engines:
Interactive picker (TUI):
Install by name:
This is equivalent to pip install "optics-framework[appium,easyocr]". See Installation for the full extras table and the external tooling (Appium server, adb, browsers) each engine needs.
Pin a specific version by appending a specifier to any engine (handy for reproducible CI):
The version applies to the engine's main package and is intersected with the extra's supported range, so an out-of-range pin fails loudly instead of silently downgrading. A malformed specifier (e.g. appium=6.1.2 with a single =), two conflicting versions for the same engine, or a specifier on a bundle (e.g. all==1.0) are all rejected up front with a clear error.
After a successful install, Optics prints the recommended next steps (optics init → optics configure → optics doctor).
Executing Test Cases¶
Run test cases from a project folder. The runner discovers test cases (and modules, elements, config) from that folder:
optics execute <folder_path> [--runner <runner_name>] [--use-printer | --no-use-printer]
[--include <test_case> ...] [--exclude <test_case> ...]
Options:
<folder_path>: Path to the project directory. The runner discovers test cases, modules, elements, andconfig.yamlby content, so either the sample subdir layout (test_cases/,modules/,test_data/) or flat CSVs work.--runner <runner_name>: Test runner to use. Supported:test_runner(default),pytest.--use-printer(default): Enable live result printer.--no-use-printer: Disable live result printer.--include <test_case> ...: Run only the named test cases. See Selecting test cases.--exclude <test_case> ...: Skip the named test cases. See Selecting test cases.
Preflight check: before running anything, optics execute verifies the enabled driver's backend is actually reachable — the Appium server (plus at least one attached Android device via adb) for Appium projects, or the remote WebDriver URL for Selenium projects. If something is missing it stops with the exact fix (e.g. "Start one in another terminal: appium") and a non-zero exit code instead of running tests that cannot reach a target. Set OPTICS_SKIP_PREFLIGHT=1 to bypass this check.
Failure details: when any step fails, a Failure details panel is printed below the summary with each failing step and its reason; unknown steps include a Did you mean '…'? suggestion when a close keyword match exists.
Selecting test cases¶
Run a subset of a project's test cases without editing any file:
# Only these test cases
optics execute ./my_project --include "Login Test" "Checkout Test"
# Everything except these
optics execute ./my_project --exclude "Legacy Flow"
# Wildcards, and both flags together: every login test except the slow one
optics execute ./my_project --include "login*" --exclude "Login Slow"
- Names are matched case-insensitively against the
test_casecolumn, and runs of whitespace count as a single space, so"login TEST"selectsLogin Test. A name must match the whole test case name; it is not a substring search. - Wildcards:
*matches any run of characters and?matches exactly one. Every other character, including[,]and., is literal. - Several names: give several names after one flag (
--include A B), repeat the flag (--include A --include B), or both. Put the project folder before the flags (or end the flag's list with--), otherwise the folder is read as another test case name. - Combining:
--includenarrows the set first, then--excluderemoves test cases from it. - Setup and teardown are always kept. Suite setup/teardown and per-test setup/teardown test cases are kept for whichever tests are selected, and they cannot be selected or excluded by name.
- Overrides config.yaml: when either flag is given, the
include/excludelists inconfig.yamlare ignored for that run. Without flags,config.yamlapplies as before. - Typos fail fast: a name that matches no test case stops the run with exit code
3before any device or browser session starts, with aDid you mean '…'?suggestion and the list of available test cases. A selection that leaves nothing to run is rejected the same way.
The same flags work with optics dry_run, so you can check a selection before running it.
Exit codes¶
optics execute and optics dry_run exit with:
| Code | Meaning |
|---|---|
0 | Every test case passed. |
1 | A test case failed, or the run could not start: a config or environment variable error, missing test files, an unreachable driver, or a credentials file that is not valid. |
2 | The command line is not valid, for example an unknown flag or no project folder. |
3 | The test selection is not valid: a name in --include/--exclude (or in include/exclude in config.yaml) matches no test case, or nothing is left to run. Also any other value that is not valid (a ValueError). |
130 | Stopped with Ctrl-C (SIGINT). |
143 | Stopped with SIGTERM. |
When the run cannot start, stderr shows a Cannot start panel titled with the error code, for example Cannot start: E0501. Other errors print <code>: <message>. See Error Handling for the codes.
Results¶
A run writes its results to execution_output/ in the project folder, or to execution_output_path when the config sets it:
junit_output.xml: the JUnit report, written once when the run ends, also when it is stopped with Ctrl-C or SIGTERM. A run has one<testsuite>with one<testcase>per test case, including suite setup and teardown. Each<testcase>has akind(suite_setup,setup,test,teardownorsuite_teardown), atimestamp(its start) and atime(its duration in seconds). A<failure>or<error>has acodewith the error code, such asE0201, when the failure has one. Each module is a<kw type="setup">and each keyword a<kw>inside it, withstatus,starttime,endtimeandelapsed; a failed one also has amessageand acode. The modules and keywords a failure or a stop kept from running havestatus="NOT_RUN". Each per-test setup and teardown is a test case of its own, named after the test it wraps, such asSetup (Login Test). The suitenameand everyclassnameare thenameinconfig.yaml, whichoptics initwrites, so the report keeps it in any folder the project is unpacked into. Without aname, they are the project folder's name. The suiteidis the session id.junit_output_<session_id>.xmlinstead, only when two sessions in one process share the output folder (the Python SDK oroptics serve).optics executeandoptics dry_runalways writejunit_output.xml.<time>-failure_<test case>.jpgand<time>-failure_<test case>.xml(.htmlfor a web page): the screen and page source when a test case fails.<time>-end_of_run.jpgandpage_sources_log.xml(.htmlfor a web page): the final screen, read before the suite teardown.detected_errors_<session_id>.jsonwhen an on-screen error matches it.- Other screenshots,
failed_steps_elements.json,interactable_elements.json, andlogs.jsonwhenjson_log: true.
| Outcome | Exit | junit_output.xml | Sample |
|---|---|---|---|
| All test cases passed | 0 | Every <testcase> has status="PASS". | passed.xml |
| A test case failed | 1 | That <testcase> has status="FAIL" and a <failure> with the reason. Its modules and keywords after the failed one are NOT_RUN. | failed.xml |
| An on-screen error matched the final screen | 1 | An on-screen-error-detection <testcase> with one <failure> per match. | on_screen_error.xml |
| The suite setup failed | 1 | Suite Setup has a <failure>. Each other test case, except the suite teardown, has status="NOT_RUN" and a <skipped> whose message starts with Suite setup failed:. The suite teardown runs. | suite_setup_failed.xml |
| A per-test setup failed | 1 | Setup (<test>) has a <failure>. Its test has status="NOT_RUN" and a <skipped> whose message starts with Setup failed:. Its teardown runs. | setup_failed.xml |
| Config or environment variable error | 1 | Not written: the run stops before a session starts. | |
| Test selection error | 3 | Not written: the run stops before a session starts. | |
| The Appium or Selenium server is not reachable, or no Android device is attached | 1 | Each test case has status="ERROR" and an <error> that names the problem, with its code, such as E0102. Its modules and keywords are NOT_RUN. | |
| Other error while the session starts, such as a credentials file that is not valid | 1 | <testsuites/> with no test cases. | |
| The driver session is lost during the run, such as when the Appium server stops | 1 | The test case that was running and each later one have status="ERROR" and an <error> with E0106. | |
| Stopped with Ctrl-C | 130 | Test cases that finished keep their results. The one that was running has status="ERROR" and an <error> with code="E0706"; its keyword that was running is ERROR with the same code, and the rest are NOT_RUN. Later test cases and the suite teardown do not run: each is a <testcase status="NOT_RUN"> with a <skipped>. | interrupted.xml |
| Stopped with SIGTERM | 143 | The same as Ctrl-C. | stopped.xml |
| Killed with SIGKILL | 137 (shell) or -9 (subprocess) | Not written: the process ends at once. |
The samples are real reports from optics execute on a Playwright project named checkout_suite.
Initializing a New Project¶
Use the following command to initialize a new project:
Arguments and options:
<project_name>: Name of the project (positional). It names the project folder and is written asnameinconfig.yaml, which names the JUnit report.--name <project_name>still works but is deprecated.--path <directory>: Directory to create the project in (default: current directory).--template <sample_name>: Copy files from a predefined sample. See Templates below. Omitted interactively, you get a picker; with no TTY, a blank project is scaffolded.--force: Overwrite an existing project directory if it exists.--git-init: Initialize a Git repository in the project.
After scaffolding, Optics prints the next steps (optics configure, then optics dry_run). Blank projects (no --template) also get a pointer to where the first steps go — test_cases/test_cases.csv — and to optics list for every available step.
Templates¶
Use --template <name> to copy a sample layout and assets from optics_framework/samples/. Available template names include:
contact— Android Contacts sample (Appium)clock— Android Clock sample (Appium)calendar— Android Calendar sample (Appium; also shows an API collection)youtube— YouTube sample (Appium; uses image templates)gmail_web— Gmail web sample (Selenium)playwright— Minimal web sample (Playwright)mobile_web— Wikipedia search in Chrome on an Android device (Appium)
Exact values depend on the directories under optics_framework/samples/. Use only names that exist as subdirectories there.
Desktop apps¶
Optics runs desktop apps on macOS, Linux and Windows through Appium and appium-xa11y-driver. Run Appium on the machine that shows the app (see Configuration).
-
Make a project from the desktop sample:
-
Set the desktop, the app and the Appium URL in
notes/config.yaml: -
Check the setup, then run the suite:
optics quickstart asks the same questions when you choose desktop.
Generating Code¶
Generate test automation code from a project's test data (test cases, modules, config):
Options:
<project_path>: Path to the project folder (containing test case and module data).--output <file_name>: File name of the generated test. Defaults totest_generated.py(pytest) ortest_generated.robot(robot). The file goes in<project_path>/generated/Tests/, with arequirements.txtin<project_path>/generated/.--framework:pytest(default) orrobot.
Listing Available Keywords¶
Display all available keywords and their parameters:
Executing Dry Run¶
Validate test cases without executing actions (keyword and parameter checks):
optics dry_run <folder_path> [--runner <runner_name>] [--use-printer | --no-use-printer]
[--include <test_case> ...] [--exclude <test_case> ...]
optics dry-run is the same command.
Options:
<folder_path>: Path to the project directory.--runner <runner_name>: Test runner to use (default:test_runner).--use-printer(default): Enable live result printer.--no-use-printer: Disable live result printer.--include <test_case> .../--exclude <test_case> ...: Validate only a subset of test cases. The rules are the same as foroptics execute(see Selecting test cases).
Unknown steps and unresolved ${variables} are flagged per step, with reasons collected in a Failure details panel below the summary (Did you mean '…'? suggestions included for close keyword matches). optics dry_run never touches a device — unlike optics execute, no driver preflight runs.
Serving the REST API¶
Start the REST API server (e.g. for programmatic or remote use):
Options:
--host: Host to bind (default:127.0.0.1).--port: Port to bind (default:8000).--workers: Number of worker processes (default:1).
The server has no authentication. Keep it on 127.0.0.1, or put it behind an authenticating gateway or a network policy. A caller of the server cannot name anything on the server:
project_path,credentials_path, Read Data file andENV:sources, andfile:or browser-internal URLs are refused. Send data and templates in the request.- Each session writes its outputs to its own temporary folder. The server deletes the folder when the session ends.
- Browser pages cannot read the server's responses or send preflighted requests (such as JSON bodies), unless you list their origins in
OPTICS_CORS_ORIGINS(comma-separated,*is refused). CORS does not stop a simple cross-origin request from reaching the server. - A request whose
Hostis not a loopback name gets421on a loopback-bound server. SetOPTICS_ALLOWED_HOSTS(comma-separated host names) to apply the check on any bind address, such as in a container published on127.0.0.1; loopback names stay allowed.
For endpoint details, request/response formats, and examples, see REST API Usage.
Interactive Live Session¶
Open an interactive session against a live target (device, browser, or TV) and run keywords as you go:
With a folder, Optics loads that project's config.yaml; without one, session defaults are used. Natural-language instructions are also available when an LLM engine is configured.
For the TUI, /save recording, and device commands, see Live Usage.
MCP Server¶
Expose Optics keywords as Model Context Protocol tools so an LLM client (Claude Desktop, Cursor, ...) can drive sessions:
Requires the mcp extra, which the installer always includes. With pip: pip install "optics-framework[mcp]".
For setup and client configuration, see MCP Usage.
Shell autocompletion¶
Enable shell autocompletion for the optics command:
The completion scripts are always written under ~/.optics/. With your confirmation, Optics also appends one source line to your shell RC (e.g. .bashrc, .zshrc) so commands and arguments complete when you press Tab; decline (or run without an interactive terminal) and it prints the line for you to add by hand instead — nothing is modified without an explicit yes.
Showing Help Information¶
Get help for the CLI:
Configuring a Project¶
Answer a few questions and Optics writes the project's config.yaml for you:
[folder]: Project folder whoseconfig.yamlto write (default: current directory).
For power users, optics configure <folder> --edit opens an interactive TUI over every config field instead (arrow keys to move, space to edit, s to save, q to quit). Edits always go to that project's own config.yaml — there is no global config file anymore.
Deprecated: optics config
The old optics config command edited a global file the runner never read. It now prints a deprecation notice and forwards to the project editor for the current directory; use optics configure instead.
Checking Your Setup¶
Diagnose engines, tooling, and a project's config.yaml:
[folder]: Project folder to diagnose (default: current directory). With one, the Appium probe targets that project's configured server URL and itsconfig.yamlis validated.--check: Non-interactive mode — exit non-zero when a project-config check fails (useful in CI).
The Desktop section checks the Appium server, the appium-xa11y-driver in APPIUM_HOME (default ~/.appium) and, on macOS, shows an ℹ️ row that names the Accessibility and Screen Recording permissions. Give them to the Node.js that runs Appium (the appium-xa11y LaunchAgent), or to your terminal if you start Appium in it. Doctor does not check these permissions. When the driver is missing, it shows appium driver install --source=npm appium-xa11y-driver.
Checking Version¶
Check the installed version:
Additional Information¶
Command name
The CLI command is optics. The PyPI package is optics-framework. Install with pip install optics-framework; then run optics in your terminal.
Optional parameters
Options such as --runner, --force, and --git-init are optional. Omit them to use defaults (e.g. test_runner for --runner).
Driver installation
When using optics setup --install, use engine names listed by optics setup --list (e.g. appium, easyocr).