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

    @rstest/browser 提供 Browser Mode 运行时 API,支持 Playwright 风格的 Locator 工作流。

    导出 API

    @rstest/browser 同时导出 BrowserElementExpect v1.0.0-beta.2、ToMatchScreenshotOptions v1.0.0-beta.2、LocatorClickOptions、LocatorGetByRoleOptions、BrowserKeyboard 等选项和断言类型。

    断言 API

    在 Browser Mode 测试中导入 @rstest/browser 后,@rstest/core 的 expect 会自动扩展以下能力:

    示例:查询、交互与断言

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

    详细参考