AgentSkillsCN

user-simulation-test

在端到端测试中模拟真实用户行为的规则与模式。涵盖 UI 交互、API 流程,以及基于场景的测试策略。

SKILL.md
--- frontmatter
description: Rules and patterns for simulating real user behavior in E2E tests. Covers UI interactions, API flows, and scenario-based testing strategies.
name: user-simulation-test
allowed-tools: ["Read", "Grep", "Glob", "Bash", "Task", "mcp__plugin_playwright_playwright__*"]

User Simulation Test Rules

Core Principle

Test as users do, not as developers think.

Simulate complete user journeys including:

  • UI interactions (clicks, inputs, drag-drop, scrolls)
  • Form submissions with realistic data
  • Multi-step workflows with wait states
  • Error scenarios and edge cases

Test Type Selection

Project TypePrimary TestSecondary TestTools
Web FrontendPlaywright E2EAPI Mockbrowser_* MCP tools
API BackendHTTP SequenceUnit Testscurl/httpie + project runner
Full StackIntegration E2EAPI + UIPlaywright + API calls
CLI ToolScript ExecutionUnit TestsBash + project runner

Scenario Structure

Every test scenario must include:

yaml
Scenario:
  name: string           # Descriptive name
  description: string    # What this tests
  preconditions: []      # Required state before test
  steps: Step[]          # User actions in sequence
  assertions: []         # Expected outcomes
  cleanup: []            # Post-test cleanup actions

Detailed templates: Read("references/scenario-templates.md")


UI Interaction Patterns

Click & Input

ActionPlaywright ToolNotes
Click buttonbrowser_clickUse ref from snapshot
Type textbrowser_typeSet slowly=true for key handlers
Fill formbrowser_fill_formBatch field updates
Select optionbrowser_select_optionFor dropdowns
Press keybrowser_press_keyEnter, Escape, etc.

Advanced Interactions

ActionPlaywright ToolUse Case
Drag & Dropbrowser_dragFile upload, reordering
Hoverbrowser_hoverTooltips, menus
Wait for textbrowser_wait_forLoading states
Take screenshotbrowser_take_screenshotVisual verification

API Testing Patterns

HTTP Sequence Test

yaml
APISequence:
  - name: "Login"
    method: POST
    endpoint: /api/auth/login
    body: { email, password }
    extract: { token: "response.data.token" }

  - name: "Create Resource"
    method: POST
    endpoint: /api/resources
    headers: { Authorization: "Bearer ${token}" }
    body: { ... }
    assertions:
      - status: 201
      - response.data.id: exists

Test Data Strategy

Realistic Data Generation

Field TypeStrategyExample
EmailPattern + timestamptest_${timestamp}@example.com
NameFake namesKorean/English name generators
PhonePattern010-XXXX-XXXX
AddressRealistic fakeValid format, fake data
PaymentTest cardsStripe/Toss test numbers

Data Isolation

  • Always use test-specific data prefixes
  • Clean up created data after tests
  • Use separate test database/environment when possible

Wait Strategies

SituationStrategyTool
Page loadWait for elementbrowser_wait_for text
API responseWait for network idlebrowser_network_requests
AnimationFixed delaybrowser_wait_for time
Loading spinnerWait for disappearbrowser_wait_for textGone

Assertion Patterns

UI Assertions

yaml
UIAssertions:
  - type: text_visible
    value: "Success message"

  - type: element_exists
    selector: "[data-testid='result']"

  - type: url_contains
    value: "/dashboard"

  - type: no_console_errors
    level: error

API Assertions

yaml
APIAssertions:
  - type: status_code
    expected: 200

  - type: response_time
    max_ms: 2000

  - type: json_path
    path: "$.data.items"
    condition: "length > 0"

Error Handling

Graceful Degradation

  1. Screenshot on failure - Capture visual state
  2. Console log capture - Get browser errors
  3. Network request dump - See failed API calls
  4. State preservation - Keep test state for debugging

Recovery Actions

yaml
OnFailure:
  - capture_screenshot
  - capture_console_logs
  - capture_network_requests
  - preserve_browser_state  # Don't close immediately

Test Categories

CategoryFrequencyCoverage
SmokeEvery changeCritical paths only
RegressionPre-releaseFull user journeys
IntegrationFeature completeCross-service flows
LoadScheduledPerformance under stress

Test patterns: Read("references/test-patterns.md")