For AI agents: the complete documentation index is available at https://rstest.rs/llms.txt, the full documentation bundle is available at https://rstest.rs/llms-full.txt, and this page is available as Markdown at https://rstest.rs/api/runtime-api/browser-mode/index.md.
close
  • English
  • Browser mode

    The Browser Mode API is provided by @rstest/browser, designed to let you use a Playwright-style Locator workflow in browser tests.

    Exported API

    @rstest/browser provides the runtime entry for Browser Mode. Its core responsibility is locating elements and driving interactions.

    page provides queries and keyboard input, Locator handles chaining and action execution, BrowserPage describes the APIs supported by page, and setTestIdAttribute configures the test id attribute name.

    The following are the APIs currently exported by @rstest/browser:

    • page - BrowserPage query, DOM conversion, and keyboard entry
    • Locator - Core class for chained queries and interactions
    • BrowserPage - Type definition for page
    • setTestIdAttribute - Configure the attribute name used by getByTestId()

    Assertion API

    The assertion entry point is expect.element(locator).

    When you import @rstest/browser in a Browser Mode test (e.g., import { page } from '@rstest/browser'), expect automatically gains the element capability.

    Its responsibility is to perform web-first assertions (with auto-waiting) on a Locator or DOM Element, such as toBeVisible and toHaveText.

    The relationship between the two can be understood as: @rstest/browser is responsible for finding and operating on elements, while expect.element is responsible for verifying element state.

    Example: query, interaction, and assertion

    browser-example.test.ts
    import { page } from '@rstest/browser';
    import { expect, test } from '@rstest/core';
    
    test('submits form', async () => {
      await page.getByLabel('Email').fill('dev@rstest.rs');
      await page.getByRole('button', { name: 'Submit' }).click();
      await expect.element(page.getByText('Done')).toBeVisible();
    });

    In this example, page first creates a Locator, the Locator executes fill/click, and finally expect.element(locator) performs a visibility assertion on the result, forming a complete test cycle.

    Detailed reference