Execution Modes
TestBro supports three execution modes that determine how it locates elements on the page during test runs. Choose the mode that best fits your testing scenario.
Selector Mode
Fast and deterministic. Uses CSS selectors and ARIA roles to find elements.
testbro run --url https://example.com --mode selector
How it works
- Each test step includes a
targetwith selector information (CSS selector, role, or test ID) - Playwright uses the selector to locate the element directly
- If the selector fails, the step fails immediately
Best for
- Regression testing on stable UIs where selectors rarely change
- Maximum execution speed
- Tests where you have pre-defined selectors from the dashboard or learned from previous AI runs
Limitations
- Breaks when UI structure changes (class names, element hierarchy)
- Requires selectors to be defined upfront or learned from AI mode
AI Mode
Flexible and adaptive. Uses GPT-4o-mini vision to find elements on the page.
testbro run --url https://example.com --mode ai
How it works
- The AI agent takes a screenshot of the current page
- It analyzes the screenshot to understand the page layout and content
- For each step, it uses vision to locate the target element by its description
- It performs the action (click, type, navigate) and verifies assertions visually
Best for
- Testing new or rapidly changing features
- Dynamic UIs where elements are generated at runtime
- When you do not have selectors defined yet
- Running tests generated from PRD or description files
Limitations
- Slower than selector mode (requires API calls for each step)
- Requires an
OPENROUTER_API_KEYenvironment variable - May occasionally misidentify elements on complex pages
Hybrid Mode (Recommended)
Best of both worlds. Tries selectors first, falls back to AI when selectors fail.
testbro run --url https://example.com --mode hybrid
How it works
- For each step, the executor first attempts to use the stored selector
- If the selector succeeds, it proceeds immediately (fast path)
- If the selector fails or is missing, it falls back to the AI agent
- When AI finds an element, it can learn the selector for future runs
Best for
- Production test suites that need both speed and resilience
- Gradually building up selector coverage over time
- Teams transitioning from manual to automated testing
Selector Learning
In hybrid mode (and AI mode), TestBro can learn selectors from successful AI interactions. After a test run, if the AI found elements that did not have selectors, you will be prompted to save the learned selectors:
testbro run --mode hybrid --learn-selectors
Use --yes to auto-confirm selector learning without prompts:
testbro run --mode hybrid --learn-selectors --yes
Learned selectors are stored in the test case and used in future selector and hybrid runs.
Choosing a Mode
| Scenario | Recommended Mode |
|---|---|
| Stable UI, known selectors | Selector |
| New feature, no selectors | AI |
| General-purpose testing | Hybrid |
| CI/CD pipeline | Hybrid or Selector |
| Exploratory testing | AI |
Setting Default Mode
You can set a default mode in your test-bro.config.json:
{
"mode": "hybrid"
}
The --mode flag on the CLI always overrides the config file.
Next Steps
- Test Cases -- How test cases and steps work
- CLI Reference -- All run command options
- CI/CD Integration -- Automated testing setup