鱼皮AI导航
鱼皮AI导航
  • 主页
  • 社区
  • AI工具
  • AI知识库
  • AI提示词
  • MCP
  • Skills
  • AI学习资源
  • AI资讯
  • GitHub开源
登录/注册

write-e2e-tests

提供端到端的浏览器自动化测试能力,用于验证 UI 交互与功能流程。通过页面对象模型操作工具栏、菜单及编辑器状态,支持跨平台输入模拟、动态断言和数据驱动测试,适用于复杂用户行为的场景验证。

测试与安全
访问 GitHub
文档Skills.MD
name
write-e2e-tests
description
Writing Playwright E2E tests for tldraw. Use when creating browser tests, testing UI interactions, or adding E2E coverage in apps/examples/e2e or apps/dotcom/client/e2e.

Writing E2E tests

E2E tests use Playwright. Located in apps/examples/e2e/ (SDK examples) and apps/dotcom/client/e2e/ (tldraw.com).

Test file structure

▼
text
复制代码
apps/examples/e2e/ ├── fixtures/ │ ├── fixtures.ts # Test fixtures (toolbar, menus, etc.) │ └── menus/ # Page object models ├── tests/ │ └── test-*.spec.ts # Test files └── shared-e2e.ts # Shared utilities

Name test files test-<feature>.spec.ts.

Required declarations

When using page.evaluate() to access the editor or UI events:

▼
typescript
复制代码
import { Editor } from 'tldraw' declare const editor: Editor declare const __tldraw_ui_event: { name: string; data?: any }

Basic test structure

▼
typescript
复制代码
import { expect } from '@playwright/test' import test from '../fixtures/fixtures' import { setupOrReset } from '../shared-e2e' test.describe('Feature name', () => { test.beforeEach(setupOrReset) test('does something', async ({ page, toolbar }) => { // Test implementation }) })

Setup patterns

Standard setup (recommended)

▼
typescript
复制代码
test.beforeEach(setupOrReset) // Smart: navigates first run, fast reset after

Shared page for performance

For tests that don't need full isolation:

▼
typescript
复制代码
let page: Page test.describe('Feature', () => { test.beforeAll(async ({ browser }) => { page = await browser.newPage() await setupPage(page) }) test.beforeEach(async () => { await hardResetEditor(page) }) })

Setup with shapes

▼
typescript
复制代码
import { setupPageWithShapes, hardResetWithShapes } from '../shared-e2e' test.beforeEach(async ({ browser }) => { if (!page) { page = await browser.newPage() await setupPage(page) } else { await hardResetEditor(page) } await setupPageWithShapes(page) })

Available fixtures

▼
typescript
复制代码
test('example', async ({ page, // Playwright page toolbar, // Toolbar page object stylePanel, // Style panel actionsMenu, // Actions menu mainMenu, // Main menu pageMenu, // Page menu navigationPanel, // Navigation panel richTextToolbar, // Rich text toolbar api, // tldrawApi methods isMobile, // Mobile viewport check isMac, // Mac platform check }) => {})

Interacting with the editor

Via page.evaluate

▼
typescript
复制代码
// Execute code in browser context await page.evaluate(() => { editor.createShapes([{ type: 'geo', x: 100, y: 100, props: { w: 100, h: 100 } }]) }) // Fast reset (faster than keyboard shortcuts) await page.evaluate(() => { editor.selectAll().deleteShapes(editor.getSelectedShapeIds()) editor.setCurrentTool('select') }) // Get data from editor const shape = await page.evaluate(() => editor.getOnlySelectedShape()) expect(shape).toMatchObject({ type: 'geo', x: 100, y: 100 })

Testing UI events

▼
typescript
复制代码
await page.keyboard.press('Control+a') expect(await page.evaluate(() => __tldraw_ui_event)).toMatchObject({ name: 'select-all-shapes', data: { source: 'kbd' }, })

Selecting tools and UI elements

By test ID

▼
typescript
复制代码
await page.getByTestId('tools.rectangle').click() await page.getByTestId('tools.more.cloud').click() // In popover await expect(page.getByTestId('tools.select')).toHaveAttribute('aria-pressed', 'true')

Via toolbar fixture

▼
typescript
复制代码
const { select, draw, arrow, rectangle } = toolbar.tools await rectangle.click() await toolbar.isSelected(rectangle) await toolbar.isNotSelected(select) // More tools popover await toolbar.moreToolsButton.click() await toolbar.popOverTools.popoverCloud.click()

Menu interactions

▼
typescript
复制代码
import { clickMenu, withMenu } from '../shared-e2e' // Click a menu item await clickMenu(page, 'main-menu.edit.copy') await clickMenu(page, 'context-menu.copy-as.copy-as-png') // Focus and interact with menu item await page.mouse.click(200, 200, { button: 'right' }) await withMenu(page, 'context-menu.arrange.distribute-horizontal', (item) => item.focus()) await page.keyboard.press('Enter')

Data-driven tests

▼
typescript
复制代码
const tools = [ { tool: 'rectangle', shape: 'geo' }, { tool: 'arrow', shape: 'arrow' }, { tool: 'draw', shape: 'draw' }, ] test('creates shapes with tools', async ({ page, toolbar }) => { for (const { tool, shape } of tools) { await page.getByTestId(`tools.${tool}`).click() await page.mouse.click(200, 200) expect(await getAllShapeTypes(page)).toContain(shape) // Reset for next iteration await page.evaluate(() => { editor.selectAll().deleteShapes(editor.getSelectedShapeIds()) }) } })

Platform-specific handling

Modifier keys

▼
typescript
复制代码
test('copy paste', async ({ page, isMac }) => { const modifier = isMac ? 'Meta' : 'Control' await page.keyboard.down(modifier) await page.keyboard.press('KeyC') await page.keyboard.press('KeyV') await page.keyboard.up(modifier) })

Skip on mobile

▼
typescript
复制代码
test('desktop only feature', async ({ isMobile }) => { if (isMobile) return // Desktop-specific test })

Helper functions

▼
typescript
复制代码
import { getAllShapeTypes, getAllShapeLabels, sleep, sleepFrames } from '../shared-e2e' // Get shape types on canvas const shapes = await getAllShapeTypes(page) expect(shapes).toEqual(['geo', 'arrow']) // Wait for async operations await sleep(100) await sleepFrames(2) // Wait for animation frames

Assertions

▼
typescript
复制代码
// Shape assertions expect(await page.evaluate(() => editor.getOnlySelectedShape())).toMatchObject({ type: 'geo', props: { w: 100, h: 100 }, }) // Attribute assertions await expect(page.getByTestId('tools.select')).toHaveAttribute('aria-pressed', 'true') // CSS assertions (for selection state) await expect(tool).toHaveCSS('color', 'rgb(255, 255, 255)') // Visibility await expect(toolbar.moreToolsPopover).toBeVisible() await expect(toolbar.toolLock).toBeHidden()

Skipping flaky tests

▼
typescript
复制代码
test.describe.skip('clipboard tests', () => { // Skipped because flaky in CI }) test.skip('known issue', async () => {})

Running E2E tests

▼
bash
复制代码
yarn e2e # Examples E2E yarn e2e-dotcom # Dotcom E2E yarn e2e-ui # With Playwright UI yarn e2e -- --grep "toolbar" # Filter by pattern

Key patterns summary

  • Use setupOrReset in beforeEach for test isolation
  • Declare editor and __tldraw_ui_event for page.evaluate()
  • Use page.evaluate() for fast editor manipulation (faster than keyboard)
  • Use getByTestId() with tools.<name> pattern for tool selection
  • Use clickMenu() / withMenu() for menu interactions
  • Handle platform differences with isMac and isMobile fixtures
  • Test against localhost:5420/end-to-end example
测试与安全

快捷安装

复制到终端去安装 Skill

npxskillsaddtldraw/tldraw--skill"write-e2e-tests"
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
🔥热门工具
朱雀AI检测朱雀AI检测
朱雀AI检测助手朱雀AI检测助手
LovartLovart
老鱼简历老鱼简历
WritePass官网WritePass官网
面多多面多多
CursorCursor
星月写作星月写作
朱雀AI检测助手朱雀AI检测助手
零感AI零感AI
Skills 推荐
debug
debug 是一个系统化定位软件缺陷根因的技能,适用于用户报告 'fix'、'broken'、'error' 等问题或测试意外失败时。它通过可验证的假设、最小复现、因果链分析和回归测试,确保在修复前准确定位根本原因。
webapp-testing
提供本地 Web 应用的端到端测试能力,支持页面导航、元素交互、表单填写、动态等待、断言验证、截图捕获、浏览器日志收集及网络请求拦截,适用于前端功能验证与 UI 行为调试。
tdd-process
严格遵循测试驱动开发的红绿重构循环,强制执行先写测试、失败要有意义、实现最小化、验证全覆盖的全流程,确保每次代码变更都由可执行的测试用例驱动并经编译、检查与全量验证确认。
smoke-test
自动化创建 Mastra 项目并完成 Studio 全流程冒烟测试,涵盖项目初始化、环境配置、本地服务启动及 Chrome 浏览器中对 Agents、Tools、Workflows、Scorers 等核心模块的功能验证与截图记录。
property-based-testing
通过生成随机输入验证代码在各类边界条件下的行为一致性,适用于序列化、解析、归一化及纯函数等场景,能有效发现隐含缺陷并提升测试覆盖率,尤其适合需要高可靠性的算法与智能合约验证。