Getting started
This guide will help you configure and run Browser Mode tests in your project.
Automatic initialization
The quickest way is to use the @rstest/core init browser command for automatic configuration:
Initialization process
When you run the command, Rstest automatically:
-
Generates boilerplate code: Rstest detects your project's framework (for example, React), language (for example, TypeScript or JavaScript), test directory (for example, common directories like
tests/,test/, or__tests__/, depending on what is detected), and package manager, then generates sample components and test files. The generated files adapt based on detection results:- Test directory: Files are placed in the detected test directory
- Framework: React projects get JSX component tests, others get native DOM examples
- Language: TypeScript projects get
.ts/.tsxfiles, others get.js/.jsxfiles
-
Creates configuration file: Creates
rstest.browser.config.tsin your project root with basic Browser Mode configuration. -
Updates package.json: Adds a
test:browserscript.
Here's an example output for a React project:
Next steps
After initialization, follow the "Next steps" instructions in the output: install project dependencies, install browser drivers, then run tests.
In CI or other non-interactive environments, add the --yes flag to skip all prompts and use detected configuration:
Manual configuration
1. Install dependencies
First, install the Rstest core package and Browser Mode support package:
Browser Mode requires Playwright as the browser driver. Install the corresponding browser:
You can also install other browsers:
2. Create configuration file
Create or update your rstest.config.ts configuration file:
3. Write tests
Create a browser test file. The recommended approach is to use the Locator API for element queries and interactions:
This example uses page.getByRole() to locate a button by its semantic role, triggers an interaction with click(), and asserts the result with expect.element().toBeVisible(). The assertion automatically waits for the element state to change — no manual polling needed.
Headless vs headed mode
By default, Browser Mode automatically selects the running mode based on the environment:
- CI environment: Automatically uses headless mode (no UI)
- Local development: Uses headed mode by default (shows browser window)
Configuring headless mode
You can explicitly specify this in your configuration file:
Configuration reference
For complete configuration reference, see browser configuration.
Next steps
- User interactions - Use
page+expect.elementfor semantic queries and assertions - Framework guides - Complete configuration and component testing examples for each framework
- User interactions - Simulate user actions