baldart 3.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +599 -0
- package/README.md +566 -0
- package/VERSION +1 -0
- package/bin/baldart.js +143 -0
- package/framework/.claude/agents/REGISTRY.md +169 -0
- package/framework/.claude/agents/api-perf-cost-auditor.md +291 -0
- package/framework/.claude/agents/code-reviewer.md +350 -0
- package/framework/.claude/agents/codebase-architect.md +391 -0
- package/framework/.claude/agents/coder.md +291 -0
- package/framework/.claude/agents/deep-human-insight.md +198 -0
- package/framework/.claude/agents/doc-reviewer.md +440 -0
- package/framework/.claude/agents/email-deliverability-architect.md +193 -0
- package/framework/.claude/agents/hybrid-ml-architect.md +285 -0
- package/framework/.claude/agents/hyper-gamification-designer.md +149 -0
- package/framework/.claude/agents/legal-counsel-gdpr.md +179 -0
- package/framework/.claude/agents/marketing-conversion-strategist.md +162 -0
- package/framework/.claude/agents/motion-expert.md +108 -0
- package/framework/.claude/agents/onboarding-architect-lead.md +230 -0
- package/framework/.claude/agents/plan-auditor.md +546 -0
- package/framework/.claude/agents/prd-card-writer.md +372 -0
- package/framework/.claude/agents/prd.md +744 -0
- package/framework/.claude/agents/qa-sentinel.md +305 -0
- package/framework/.claude/agents/remotion-animator-orchestrator.md +218 -0
- package/framework/.claude/agents/security-reviewer.md +276 -0
- package/framework/.claude/agents/senior-researcher.md +175 -0
- package/framework/.claude/agents/seo-analytics-strategist.md +156 -0
- package/framework/.claude/agents/skill-improver.md +61 -0
- package/framework/.claude/agents/ui-expert.md +191 -0
- package/framework/.claude/agents/visual-designer.md +190 -0
- package/framework/.claude/agents/website-orchestrator.md +118 -0
- package/framework/.claude/agents/wiki-curator.md +145 -0
- package/framework/.claude/commands/baldart-push.md +15 -0
- package/framework/.claude/commands/check.md +237 -0
- package/framework/.claude/commands/codexreview.md +203 -0
- package/framework/.claude/commands/design-review.md +11 -0
- package/framework/.claude/commands/issue-review.md +34 -0
- package/framework/.claude/commands/new.md +331 -0
- package/framework/.claude/commands/qa.md +257 -0
- package/framework/.claude/hooks/framework-edit-gate.js +208 -0
- package/framework/.claude/hooks/lint-before-commit.sh.template +66 -0
- package/framework/.claude/settings.local.json.example +32 -0
- package/framework/.claude/skills/api-design-principles/SKILL.md +567 -0
- package/framework/.claude/skills/api-design-principles/assets/api-design-checklist.md +155 -0
- package/framework/.claude/skills/api-design-principles/assets/rest-api-template.py +182 -0
- package/framework/.claude/skills/api-design-principles/references/graphql-schema-design.md +583 -0
- package/framework/.claude/skills/api-design-principles/references/rest-best-practices.md +408 -0
- package/framework/.claude/skills/baldart-push/SKILL.md +222 -0
- package/framework/.claude/skills/bug/SKILL.md +200 -0
- package/framework/.claude/skills/bug/references/logging-patterns.md +174 -0
- package/framework/.claude/skills/capture/SKILL.md +125 -0
- package/framework/.claude/skills/capture/references/synthesis-template.md +42 -0
- package/framework/.claude/skills/context-primer/SKILL.md +189 -0
- package/framework/.claude/skills/copywriting/SKILL.md +273 -0
- package/framework/.claude/skills/copywriting/references/copy-frameworks.md +338 -0
- package/framework/.claude/skills/copywriting/references/natural-transitions.md +252 -0
- package/framework/.claude/skills/doc-writing-for-rag/SKILL.md +119 -0
- package/framework/.claude/skills/doc-writing-for-rag/references/before-after-examples.md +291 -0
- package/framework/.claude/skills/doc-writing-for-rag/references/compact-templates.md +183 -0
- package/framework/.claude/skills/doc-writing-for-rag/references/frontmatter-minimal.md +112 -0
- package/framework/.claude/skills/doc-writing-for-rag/references/line-count-targets.md +110 -0
- package/framework/.claude/skills/doc-writing-for-rag/references/schemas-and-errors.md +129 -0
- package/framework/.claude/skills/find-skills/SKILL.md +133 -0
- package/framework/.claude/skills/frontend-design/LICENSE.txt +177 -0
- package/framework/.claude/skills/frontend-design/SKILL.md +84 -0
- package/framework/.claude/skills/gamification-design/SKILL.md +130 -0
- package/framework/.claude/skills/issue-review/SKILL.md +45 -0
- package/framework/.claude/skills/kie-ai/SKILL.md +262 -0
- package/framework/.claude/skills/kie-ai/references/models-catalog.md +272 -0
- package/framework/.claude/skills/kie-ai/scripts/kie_api.sh +209 -0
- package/framework/.claude/skills/kie-ai/scripts/remove_greenscreen.py +69 -0
- package/framework/.claude/skills/kie-ai/scripts/setup_api_key.sh +77 -0
- package/framework/.claude/skills/motion-design/LICENSE +21 -0
- package/framework/.claude/skills/motion-design/README.md +82 -0
- package/framework/.claude/skills/motion-design/SKILL.md +336 -0
- package/framework/.claude/skills/motion-design/director/choreography.md +93 -0
- package/framework/.claude/skills/motion-design/director/context-adaptation.md +83 -0
- package/framework/.claude/skills/motion-design/director/core-philosophy.md +53 -0
- package/framework/.claude/skills/motion-design/director/decision-framework.md +91 -0
- package/framework/.claude/skills/motion-design/director/disney-principles.md +102 -0
- package/framework/.claude/skills/motion-design/director/emotion-mapping.md +71 -0
- package/framework/.claude/skills/motion-design/director/motion-personality.md +89 -0
- package/framework/.claude/skills/motion-design/director/narrative-structure.md +62 -0
- package/framework/.claude/skills/motion-design/patterns/ambient-continuous.md +81 -0
- package/framework/.claude/skills/motion-design/patterns/entrance-exit.md +82 -0
- package/framework/.claude/skills/motion-design/patterns/multi-element.md +69 -0
- package/framework/.claude/skills/motion-design/patterns/state-feedback.md +96 -0
- package/framework/.claude/skills/motion-design/reference/property-selection.md +95 -0
- package/framework/.claude/skills/motion-design/reference/quality-checklist.md +67 -0
- package/framework/.claude/skills/motion-design/reference/timing-easing-tables.md +106 -0
- package/framework/.claude/skills/motion-design/reference/troubleshooting.md +73 -0
- package/framework/.claude/skills/new/SKILL.md +1687 -0
- package/framework/.claude/skills/playwright-skill/API_REFERENCE.md +652 -0
- package/framework/.claude/skills/playwright-skill/SKILL.md +157 -0
- package/framework/.claude/skills/playwright-skill/package.json +26 -0
- package/framework/.claude/skills/prd/SKILL.md +228 -0
- package/framework/.claude/skills/prd/assets/card-template.yml +232 -0
- package/framework/.claude/skills/prd/assets/epic-template.yml +190 -0
- package/framework/.claude/skills/prd/assets/prd-template.md +230 -0
- package/framework/.claude/skills/prd/assets/state-template.md +78 -0
- package/framework/.claude/skills/prd/references/api-perf-gate.md +152 -0
- package/framework/.claude/skills/prd/references/audit-phase.md +478 -0
- package/framework/.claude/skills/prd/references/backlog-phase.md +145 -0
- package/framework/.claude/skills/prd/references/discovery-phase.md +359 -0
- package/framework/.claude/skills/prd/references/impact-analysis.md +233 -0
- package/framework/.claude/skills/prd/references/prd-add-phase.md +214 -0
- package/framework/.claude/skills/prd/references/prd-writing-phase.md +145 -0
- package/framework/.claude/skills/prd/references/research-phase.md +216 -0
- package/framework/.claude/skills/prd/references/ui-design-phase.md +61 -0
- package/framework/.claude/skills/prd/references/validation-phase.md +72 -0
- package/framework/.claude/skills/prd-add/SKILL.md +222 -0
- package/framework/.claude/skills/prd-add/references/impact-analysis.md +233 -0
- package/framework/.claude/skills/remotion-best-practices/SKILL.md +48 -0
- package/framework/.claude/skills/remotion-best-practices/rules/3d.md +86 -0
- package/framework/.claude/skills/remotion-best-practices/rules/animations.md +29 -0
- package/framework/.claude/skills/remotion-best-practices/rules/assets/charts-bar-chart.tsx +173 -0
- package/framework/.claude/skills/remotion-best-practices/rules/assets/text-animations-typewriter.tsx +100 -0
- package/framework/.claude/skills/remotion-best-practices/rules/assets/text-animations-word-highlight.tsx +108 -0
- package/framework/.claude/skills/remotion-best-practices/rules/assets.md +78 -0
- package/framework/.claude/skills/remotion-best-practices/rules/audio.md +169 -0
- package/framework/.claude/skills/remotion-best-practices/rules/calculate-metadata.md +104 -0
- package/framework/.claude/skills/remotion-best-practices/rules/can-decode.md +75 -0
- package/framework/.claude/skills/remotion-best-practices/rules/charts.md +58 -0
- package/framework/.claude/skills/remotion-best-practices/rules/compositions.md +141 -0
- package/framework/.claude/skills/remotion-best-practices/rules/display-captions.md +184 -0
- package/framework/.claude/skills/remotion-best-practices/rules/extract-frames.md +229 -0
- package/framework/.claude/skills/remotion-best-practices/rules/fonts.md +152 -0
- package/framework/.claude/skills/remotion-best-practices/rules/get-audio-duration.md +58 -0
- package/framework/.claude/skills/remotion-best-practices/rules/get-video-dimensions.md +68 -0
- package/framework/.claude/skills/remotion-best-practices/rules/get-video-duration.md +58 -0
- package/framework/.claude/skills/remotion-best-practices/rules/gifs.md +141 -0
- package/framework/.claude/skills/remotion-best-practices/rules/images.md +130 -0
- package/framework/.claude/skills/remotion-best-practices/rules/import-srt-captions.md +69 -0
- package/framework/.claude/skills/remotion-best-practices/rules/light-leaks.md +73 -0
- package/framework/.claude/skills/remotion-best-practices/rules/lottie.md +67 -0
- package/framework/.claude/skills/remotion-best-practices/rules/maps.md +401 -0
- package/framework/.claude/skills/remotion-best-practices/rules/measuring-dom-nodes.md +34 -0
- package/framework/.claude/skills/remotion-best-practices/rules/measuring-text.md +143 -0
- package/framework/.claude/skills/remotion-best-practices/rules/parameters.md +98 -0
- package/framework/.claude/skills/remotion-best-practices/rules/sequencing.md +118 -0
- package/framework/.claude/skills/remotion-best-practices/rules/subtitles.md +36 -0
- package/framework/.claude/skills/remotion-best-practices/rules/tailwind.md +11 -0
- package/framework/.claude/skills/remotion-best-practices/rules/text-animations.md +20 -0
- package/framework/.claude/skills/remotion-best-practices/rules/timing.md +179 -0
- package/framework/.claude/skills/remotion-best-practices/rules/transcribe-captions.md +70 -0
- package/framework/.claude/skills/remotion-best-practices/rules/transitions.md +197 -0
- package/framework/.claude/skills/remotion-best-practices/rules/transparent-videos.md +106 -0
- package/framework/.claude/skills/remotion-best-practices/rules/trimming.md +52 -0
- package/framework/.claude/skills/remotion-best-practices/rules/videos.md +171 -0
- package/framework/.claude/skills/seo-audit/SKILL.md +394 -0
- package/framework/.claude/skills/seo-audit/references/aeo-geo-patterns.md +279 -0
- package/framework/.claude/skills/seo-audit/references/ai-writing-detection.md +190 -0
- package/framework/.claude/skills/simplify/SKILL.md +137 -0
- package/framework/.claude/skills/skill-creator/LICENSE.txt +202 -0
- package/framework/.claude/skills/skill-creator/SKILL.md +356 -0
- package/framework/.claude/skills/skill-creator/references/output-patterns.md +82 -0
- package/framework/.claude/skills/skill-creator/references/workflows.md +28 -0
- package/framework/.claude/skills/skill-creator/scripts/init_skill.py +303 -0
- package/framework/.claude/skills/skill-creator/scripts/package_skill.py +110 -0
- package/framework/.claude/skills/skill-creator/scripts/quick_validate.py +95 -0
- package/framework/.claude/skills/ui-design/SKILL.md +199 -0
- package/framework/.claude/skills/ui-design/references/component-discovery.md +54 -0
- package/framework/.claude/skills/ui-design/references/evaluation.md +171 -0
- package/framework/.claude/skills/ui-design/references/generation.md +109 -0
- package/framework/.claude/skills/ui-design/references/inventory.md +59 -0
- package/framework/.claude/skills/webapp-testing/LICENSE.txt +202 -0
- package/framework/.claude/skills/webapp-testing/SKILL.md +123 -0
- package/framework/.claude/skills/webapp-testing/examples/console_logging.py +35 -0
- package/framework/.claude/skills/webapp-testing/examples/element_discovery.py +40 -0
- package/framework/.claude/skills/webapp-testing/examples/static_html_automation.py +33 -0
- package/framework/.claude/skills/webapp-testing/scripts/with_server.py +106 -0
- package/framework/.claude/skills/worktree-manager/SKILL.md +680 -0
- package/framework/AGENTS.md +240 -0
- package/framework/agents/api-contracts.md +137 -0
- package/framework/agents/architecture.md +145 -0
- package/framework/agents/coding-standards.md +148 -0
- package/framework/agents/data-model.md +110 -0
- package/framework/agents/deployment-protocol.md +232 -0
- package/framework/agents/design-review.md +172 -0
- package/framework/agents/env-reference.md +171 -0
- package/framework/agents/github-issue-subagent.md +252 -0
- package/framework/agents/index.md +261 -0
- package/framework/agents/llm-wiki-methodology.md +216 -0
- package/framework/agents/maintenance-protocol.md +305 -0
- package/framework/agents/observability.md +162 -0
- package/framework/agents/performance.md +155 -0
- package/framework/agents/project-context.md +145 -0
- package/framework/agents/runbook.md +208 -0
- package/framework/agents/security.md +168 -0
- package/framework/agents/skills-mapping.md +286 -0
- package/framework/agents/testing.md +111 -0
- package/framework/agents/workflows.md +215 -0
- package/framework/docs/PROJECT-CONFIGURATION.md +336 -0
- package/framework/docs/references/brand-guidelines.md +170 -0
- package/framework/docs/references/ui-guidelines.template.md +182 -0
- package/framework/routines/code-review.routine.yml +46 -0
- package/framework/routines/doc-review.routine.yml +45 -0
- package/framework/routines/ds-drift.routine.yml +52 -0
- package/framework/routines/full-sweep.routine.yml +51 -0
- package/framework/routines/index.yml +70 -0
- package/framework/routines/skill-improve.routine.yml +50 -0
- package/framework/routines/wiki-review.routine.yml +45 -0
- package/framework/templates/baldart.config.template.yml +113 -0
- package/framework/templates/breaking-change-checklist.md +484 -0
- package/framework/templates/feature-card.template.yml +125 -0
- package/framework/templates/overlays/README.md +44 -0
- package/framework/templates/overlays/copywriting.fidelity-example.md +62 -0
- package/framework/templates/overlays/ui-design.fidelity-example.md +75 -0
- package/framework/templates/skill-project-context.snippet.md +19 -0
- package/framework/templates/spec.template.md +208 -0
- package/package.json +51 -0
- package/src/commands/add.js +229 -0
- package/src/commands/configure.js +385 -0
- package/src/commands/doctor.js +486 -0
- package/src/commands/migrate.js +185 -0
- package/src/commands/push.js +0 -0
- package/src/commands/routines.js +269 -0
- package/src/commands/status.js +130 -0
- package/src/commands/update.js +419 -0
- package/src/commands/version.js +88 -0
- package/src/utils/contamination.js +400 -0
- package/src/utils/git.js +181 -0
- package/src/utils/hooks.js +152 -0
- package/src/utils/routine-adapters/claude-code-cloud.js +78 -0
- package/src/utils/routine-adapters/cron.js +138 -0
- package/src/utils/routine-adapters/github-actions.js +141 -0
- package/src/utils/routine-adapters/index.js +21 -0
- package/src/utils/routines.js +166 -0
- package/src/utils/state.js +143 -0
- package/src/utils/symlinks.js +425 -0
- package/src/utils/ui.js +133 -0
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
# Playwright Skill - Complete API Reference
|
|
2
|
+
|
|
3
|
+
This document contains the comprehensive Playwright API reference and advanced patterns. For quick-start execution patterns, see [SKILL.md](SKILL.md).
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Installation & Setup](#installation--setup)
|
|
8
|
+
- [Core Patterns](#core-patterns)
|
|
9
|
+
- [Selectors & Locators](#selectors--locators)
|
|
10
|
+
- [Common Actions](#common-actions)
|
|
11
|
+
- [Waiting Strategies](#waiting-strategies)
|
|
12
|
+
- [Assertions](#assertions)
|
|
13
|
+
- [Page Object Model](#page-object-model-pom)
|
|
14
|
+
- [Network & API Testing](#network--api-testing)
|
|
15
|
+
- [Visual Testing](#visual-testing)
|
|
16
|
+
- [Mobile Testing](#mobile-testing)
|
|
17
|
+
- [Debugging](#debugging)
|
|
18
|
+
- [Performance Testing](#performance-testing)
|
|
19
|
+
- [Parallel Execution](#parallel-execution)
|
|
20
|
+
- [Data-Driven Testing](#data-driven-testing)
|
|
21
|
+
- [Accessibility Testing](#accessibility-testing)
|
|
22
|
+
- [CI/CD Integration](#cicd-integration)
|
|
23
|
+
- [Best Practices](#best-practices)
|
|
24
|
+
- [Common Patterns & Solutions](#common-patterns--solutions)
|
|
25
|
+
- [Troubleshooting](#troubleshooting)
|
|
26
|
+
|
|
27
|
+
## Installation & Setup
|
|
28
|
+
|
|
29
|
+
### Prerequisites
|
|
30
|
+
|
|
31
|
+
Before using this skill, ensure Playwright is available:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Check if Playwright is installed
|
|
35
|
+
npm list playwright 2>/dev/null || echo "Playwright not installed"
|
|
36
|
+
|
|
37
|
+
# Install (if needed)
|
|
38
|
+
cd ~/.claude/skills/playwright-skill
|
|
39
|
+
npm run setup
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Basic Configuration
|
|
43
|
+
|
|
44
|
+
Create `playwright.config.ts`:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { defineConfig, devices } from '@playwright/test';
|
|
48
|
+
|
|
49
|
+
export default defineConfig({
|
|
50
|
+
testDir: './tests',
|
|
51
|
+
fullyParallel: true,
|
|
52
|
+
forbidOnly: !!process.env.CI,
|
|
53
|
+
retries: process.env.CI ? 2 : 0,
|
|
54
|
+
workers: process.env.CI ? 1 : undefined,
|
|
55
|
+
reporter: 'html',
|
|
56
|
+
use: {
|
|
57
|
+
baseURL: 'http://localhost:3000',
|
|
58
|
+
trace: 'on-first-retry',
|
|
59
|
+
screenshot: 'only-on-failure',
|
|
60
|
+
video: 'retain-on-failure',
|
|
61
|
+
},
|
|
62
|
+
projects: [
|
|
63
|
+
{
|
|
64
|
+
name: 'chromium',
|
|
65
|
+
use: { ...devices['Desktop Chrome'] },
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
webServer: {
|
|
69
|
+
command: 'npm run start',
|
|
70
|
+
url: 'http://localhost:3000',
|
|
71
|
+
reuseExistingServer: !process.env.CI,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Core Patterns
|
|
77
|
+
|
|
78
|
+
### Basic Browser Automation
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
const { chromium } = require('playwright');
|
|
82
|
+
|
|
83
|
+
(async () => {
|
|
84
|
+
// Launch browser
|
|
85
|
+
const browser = await chromium.launch({
|
|
86
|
+
headless: false, // Set to true for headless mode
|
|
87
|
+
slowMo: 50 // Slow down operations by 50ms
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const context = await browser.newContext({
|
|
91
|
+
viewport: { width: 1280, height: 720 },
|
|
92
|
+
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const page = await context.newPage();
|
|
96
|
+
|
|
97
|
+
// Navigate
|
|
98
|
+
await page.goto('https://example.com', {
|
|
99
|
+
waitUntil: 'networkidle' // Wait for network to be idle
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Your automation here
|
|
103
|
+
|
|
104
|
+
await browser.close();
|
|
105
|
+
})();
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Test Structure
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { test, expect } from '@playwright/test';
|
|
112
|
+
|
|
113
|
+
test.describe('Feature Name', () => {
|
|
114
|
+
test.beforeEach(async ({ page }) => {
|
|
115
|
+
await page.goto('/');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('should do something', async ({ page }) => {
|
|
119
|
+
// Arrange
|
|
120
|
+
const button = page.locator('button[data-testid="submit"]');
|
|
121
|
+
|
|
122
|
+
// Act
|
|
123
|
+
await button.click();
|
|
124
|
+
|
|
125
|
+
// Assert
|
|
126
|
+
await expect(page).toHaveURL('/success');
|
|
127
|
+
await expect(page.locator('.message')).toHaveText('Success!');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Selectors & Locators
|
|
133
|
+
|
|
134
|
+
### Best Practices for Selectors
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
// PREFERRED: Data attributes (most stable)
|
|
138
|
+
await page.locator('[data-testid="submit-button"]').click();
|
|
139
|
+
await page.locator('[data-cy="user-input"]').fill('text');
|
|
140
|
+
|
|
141
|
+
// GOOD: Role-based selectors (accessible)
|
|
142
|
+
await page.getByRole('button', { name: 'Submit' }).click();
|
|
143
|
+
await page.getByRole('textbox', { name: 'Email' }).fill('user@example.com');
|
|
144
|
+
await page.getByRole('heading', { level: 1 }).click();
|
|
145
|
+
|
|
146
|
+
// GOOD: Text content (for unique text)
|
|
147
|
+
await page.getByText('Sign in').click();
|
|
148
|
+
await page.getByText(/welcome back/i).click();
|
|
149
|
+
|
|
150
|
+
// OK: Semantic HTML
|
|
151
|
+
await page.locator('button[type="submit"]').click();
|
|
152
|
+
await page.locator('input[name="email"]').fill('test@test.com');
|
|
153
|
+
|
|
154
|
+
// AVOID: Classes and IDs (can change frequently)
|
|
155
|
+
await page.locator('.btn-primary').click(); // Avoid
|
|
156
|
+
await page.locator('#submit').click(); // Avoid
|
|
157
|
+
|
|
158
|
+
// LAST RESORT: Complex CSS/XPath
|
|
159
|
+
await page.locator('div.container > form > button').click(); // Fragile
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Advanced Locator Patterns
|
|
163
|
+
|
|
164
|
+
```javascript
|
|
165
|
+
// Filter and chain locators
|
|
166
|
+
const row = page.locator('tr').filter({ hasText: 'John Doe' });
|
|
167
|
+
await row.locator('button').click();
|
|
168
|
+
|
|
169
|
+
// Nth element
|
|
170
|
+
await page.locator('button').nth(2).click();
|
|
171
|
+
|
|
172
|
+
// Combining conditions
|
|
173
|
+
await page.locator('button').and(page.locator('[disabled]')).count();
|
|
174
|
+
|
|
175
|
+
// Parent/child navigation
|
|
176
|
+
const cell = page.locator('td').filter({ hasText: 'Active' });
|
|
177
|
+
const row = cell.locator('..');
|
|
178
|
+
await row.locator('button.edit').click();
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Common Actions
|
|
182
|
+
|
|
183
|
+
### Form Interactions
|
|
184
|
+
|
|
185
|
+
```javascript
|
|
186
|
+
// Text input
|
|
187
|
+
await page.getByLabel('Email').fill('user@example.com');
|
|
188
|
+
await page.getByPlaceholder('Enter your name').fill('John Doe');
|
|
189
|
+
|
|
190
|
+
// Clear and type
|
|
191
|
+
await page.locator('#username').clear();
|
|
192
|
+
await page.locator('#username').type('newuser', { delay: 100 });
|
|
193
|
+
|
|
194
|
+
// Checkbox
|
|
195
|
+
await page.getByLabel('I agree').check();
|
|
196
|
+
await page.getByLabel('Subscribe').uncheck();
|
|
197
|
+
|
|
198
|
+
// Radio button
|
|
199
|
+
await page.getByLabel('Option 2').check();
|
|
200
|
+
|
|
201
|
+
// Select dropdown
|
|
202
|
+
await page.selectOption('select#country', 'usa');
|
|
203
|
+
await page.selectOption('select#country', { label: 'United States' });
|
|
204
|
+
await page.selectOption('select#country', { index: 2 });
|
|
205
|
+
|
|
206
|
+
// Multi-select
|
|
207
|
+
await page.selectOption('select#colors', ['red', 'blue', 'green']);
|
|
208
|
+
|
|
209
|
+
// File upload
|
|
210
|
+
await page.setInputFiles('input[type="file"]', 'path/to/file.pdf');
|
|
211
|
+
await page.setInputFiles('input[type="file"]', [
|
|
212
|
+
'file1.pdf',
|
|
213
|
+
'file2.pdf'
|
|
214
|
+
]);
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Mouse Actions
|
|
218
|
+
|
|
219
|
+
```javascript
|
|
220
|
+
// Click variations
|
|
221
|
+
await page.click('button'); // Left click
|
|
222
|
+
await page.click('button', { button: 'right' }); // Right click
|
|
223
|
+
await page.dblclick('button'); // Double click
|
|
224
|
+
await page.click('button', { position: { x: 10, y: 10 } }); // Click at position
|
|
225
|
+
|
|
226
|
+
// Hover
|
|
227
|
+
await page.hover('.menu-item');
|
|
228
|
+
|
|
229
|
+
// Drag and drop
|
|
230
|
+
await page.dragAndDrop('#source', '#target');
|
|
231
|
+
|
|
232
|
+
// Manual drag
|
|
233
|
+
await page.locator('#source').hover();
|
|
234
|
+
await page.mouse.down();
|
|
235
|
+
await page.locator('#target').hover();
|
|
236
|
+
await page.mouse.up();
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Keyboard Actions
|
|
240
|
+
|
|
241
|
+
```javascript
|
|
242
|
+
// Type with delay
|
|
243
|
+
await page.keyboard.type('Hello World', { delay: 100 });
|
|
244
|
+
|
|
245
|
+
// Key combinations
|
|
246
|
+
await page.keyboard.press('Control+A');
|
|
247
|
+
await page.keyboard.press('Control+C');
|
|
248
|
+
await page.keyboard.press('Control+V');
|
|
249
|
+
|
|
250
|
+
// Special keys
|
|
251
|
+
await page.keyboard.press('Enter');
|
|
252
|
+
await page.keyboard.press('Tab');
|
|
253
|
+
await page.keyboard.press('Escape');
|
|
254
|
+
await page.keyboard.press('ArrowDown');
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Waiting Strategies
|
|
258
|
+
|
|
259
|
+
### Smart Waiting
|
|
260
|
+
|
|
261
|
+
```javascript
|
|
262
|
+
// Wait for element states
|
|
263
|
+
await page.locator('button').waitFor({ state: 'visible' });
|
|
264
|
+
await page.locator('.spinner').waitFor({ state: 'hidden' });
|
|
265
|
+
await page.locator('button').waitFor({ state: 'attached' });
|
|
266
|
+
await page.locator('button').waitFor({ state: 'detached' });
|
|
267
|
+
|
|
268
|
+
// Wait for specific conditions
|
|
269
|
+
await page.waitForURL('**/success');
|
|
270
|
+
await page.waitForURL(url => url.pathname === '/dashboard');
|
|
271
|
+
|
|
272
|
+
// Wait for network
|
|
273
|
+
await page.waitForLoadState('networkidle');
|
|
274
|
+
await page.waitForLoadState('domcontentloaded');
|
|
275
|
+
|
|
276
|
+
// Wait for function
|
|
277
|
+
await page.waitForFunction(() => document.querySelector('.loaded'));
|
|
278
|
+
await page.waitForFunction(
|
|
279
|
+
text => document.body.innerText.includes(text),
|
|
280
|
+
'Content loaded'
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
// Wait for response
|
|
284
|
+
const responsePromise = page.waitForResponse('**/api/users');
|
|
285
|
+
await page.click('button#load-users');
|
|
286
|
+
const response = await responsePromise;
|
|
287
|
+
|
|
288
|
+
// Wait for request
|
|
289
|
+
await page.waitForRequest(request =>
|
|
290
|
+
request.url().includes('/api/') && request.method() === 'POST'
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
// Custom timeout
|
|
294
|
+
await page.locator('.slow-element').waitFor({
|
|
295
|
+
state: 'visible',
|
|
296
|
+
timeout: 10000 // 10 seconds
|
|
297
|
+
});
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Assertions
|
|
301
|
+
|
|
302
|
+
### Common Assertions
|
|
303
|
+
|
|
304
|
+
```javascript
|
|
305
|
+
import { expect } from '@playwright/test';
|
|
306
|
+
|
|
307
|
+
// Page assertions
|
|
308
|
+
await expect(page).toHaveTitle('My App');
|
|
309
|
+
await expect(page).toHaveURL('https://example.com/dashboard');
|
|
310
|
+
await expect(page).toHaveURL(/.*dashboard/);
|
|
311
|
+
|
|
312
|
+
// Element visibility
|
|
313
|
+
await expect(page.locator('.message')).toBeVisible();
|
|
314
|
+
await expect(page.locator('.spinner')).toBeHidden();
|
|
315
|
+
await expect(page.locator('button')).toBeEnabled();
|
|
316
|
+
await expect(page.locator('input')).toBeDisabled();
|
|
317
|
+
|
|
318
|
+
// Text content
|
|
319
|
+
await expect(page.locator('h1')).toHaveText('Welcome');
|
|
320
|
+
await expect(page.locator('.message')).toContainText('success');
|
|
321
|
+
await expect(page.locator('.items')).toHaveText(['Item 1', 'Item 2']);
|
|
322
|
+
|
|
323
|
+
// Input values
|
|
324
|
+
await expect(page.locator('input')).toHaveValue('test@example.com');
|
|
325
|
+
await expect(page.locator('input')).toBeEmpty();
|
|
326
|
+
|
|
327
|
+
// Attributes
|
|
328
|
+
await expect(page.locator('button')).toHaveAttribute('type', 'submit');
|
|
329
|
+
await expect(page.locator('img')).toHaveAttribute('src', /.*\.png/);
|
|
330
|
+
|
|
331
|
+
// CSS properties
|
|
332
|
+
await expect(page.locator('.error')).toHaveCSS('color', 'rgb(255, 0, 0)');
|
|
333
|
+
|
|
334
|
+
// Count
|
|
335
|
+
await expect(page.locator('.item')).toHaveCount(5);
|
|
336
|
+
|
|
337
|
+
// Checkbox/Radio state
|
|
338
|
+
await expect(page.locator('input[type="checkbox"]')).toBeChecked();
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
## Page Object Model (POM)
|
|
342
|
+
|
|
343
|
+
### Basic Page Object
|
|
344
|
+
|
|
345
|
+
```javascript
|
|
346
|
+
// pages/LoginPage.js
|
|
347
|
+
class LoginPage {
|
|
348
|
+
constructor(page) {
|
|
349
|
+
this.page = page;
|
|
350
|
+
this.usernameInput = page.locator('input[name="username"]');
|
|
351
|
+
this.passwordInput = page.locator('input[name="password"]');
|
|
352
|
+
this.submitButton = page.locator('button[type="submit"]');
|
|
353
|
+
this.errorMessage = page.locator('.error-message');
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async navigate() {
|
|
357
|
+
await this.page.goto('/login');
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
async login(username, password) {
|
|
361
|
+
await this.usernameInput.fill(username);
|
|
362
|
+
await this.passwordInput.fill(password);
|
|
363
|
+
await this.submitButton.click();
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
async getErrorMessage() {
|
|
367
|
+
return await this.errorMessage.textContent();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Usage in test
|
|
372
|
+
test('login with valid credentials', async ({ page }) => {
|
|
373
|
+
const loginPage = new LoginPage(page);
|
|
374
|
+
await loginPage.navigate();
|
|
375
|
+
await loginPage.login('user@example.com', 'password123');
|
|
376
|
+
await expect(page).toHaveURL('/dashboard');
|
|
377
|
+
});
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
## Network & API Testing
|
|
381
|
+
|
|
382
|
+
### Intercepting Requests
|
|
383
|
+
|
|
384
|
+
```javascript
|
|
385
|
+
// Mock API responses
|
|
386
|
+
await page.route('**/api/users', route => {
|
|
387
|
+
route.fulfill({
|
|
388
|
+
status: 200,
|
|
389
|
+
contentType: 'application/json',
|
|
390
|
+
body: JSON.stringify([
|
|
391
|
+
{ id: 1, name: 'John' },
|
|
392
|
+
{ id: 2, name: 'Jane' }
|
|
393
|
+
])
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// Modify requests
|
|
398
|
+
await page.route('**/api/**', route => {
|
|
399
|
+
const headers = {
|
|
400
|
+
...route.request().headers(),
|
|
401
|
+
'X-Custom-Header': 'value'
|
|
402
|
+
};
|
|
403
|
+
route.continue({ headers });
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
// Block resources
|
|
407
|
+
await page.route('**/*.{png,jpg,jpeg,gif}', route => route.abort());
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### Custom Headers via Environment Variables
|
|
411
|
+
|
|
412
|
+
The skill supports automatic header injection via environment variables:
|
|
413
|
+
|
|
414
|
+
```bash
|
|
415
|
+
# Single header (simple)
|
|
416
|
+
PW_HEADER_NAME=X-Automated-By PW_HEADER_VALUE=playwright-skill
|
|
417
|
+
|
|
418
|
+
# Multiple headers (JSON)
|
|
419
|
+
PW_EXTRA_HEADERS='{"X-Automated-By":"playwright-skill","X-Request-ID":"123"}'
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
These headers are automatically applied to all requests when using:
|
|
423
|
+
- `helpers.createContext(browser)` - headers merged automatically
|
|
424
|
+
- `getContextOptionsWithHeaders(options)` - utility injected by run.js wrapper
|
|
425
|
+
|
|
426
|
+
**Precedence (highest to lowest):**
|
|
427
|
+
1. Headers passed directly in `options.extraHTTPHeaders`
|
|
428
|
+
2. Environment variable headers
|
|
429
|
+
3. Playwright defaults
|
|
430
|
+
|
|
431
|
+
**Use case:** Identify automated traffic so your backend can return LLM-optimized responses (e.g., plain text errors instead of styled HTML).
|
|
432
|
+
|
|
433
|
+
## Visual Testing
|
|
434
|
+
|
|
435
|
+
### Screenshots
|
|
436
|
+
|
|
437
|
+
```javascript
|
|
438
|
+
// Full page screenshot
|
|
439
|
+
await page.screenshot({
|
|
440
|
+
path: 'screenshot.png',
|
|
441
|
+
fullPage: true
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
// Element screenshot
|
|
445
|
+
await page.locator('.chart').screenshot({
|
|
446
|
+
path: 'chart.png'
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
// Visual comparison
|
|
450
|
+
await expect(page).toHaveScreenshot('homepage.png');
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
## Mobile Testing
|
|
454
|
+
|
|
455
|
+
```javascript
|
|
456
|
+
// Device emulation
|
|
457
|
+
const { devices } = require('playwright');
|
|
458
|
+
const iPhone = devices['iPhone 12'];
|
|
459
|
+
|
|
460
|
+
const context = await browser.newContext({
|
|
461
|
+
...iPhone,
|
|
462
|
+
locale: 'en-US',
|
|
463
|
+
permissions: ['geolocation'],
|
|
464
|
+
geolocation: { latitude: 37.7749, longitude: -122.4194 }
|
|
465
|
+
});
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
## Debugging
|
|
469
|
+
|
|
470
|
+
### Debug Mode
|
|
471
|
+
|
|
472
|
+
```bash
|
|
473
|
+
# Run with inspector
|
|
474
|
+
npx playwright test --debug
|
|
475
|
+
|
|
476
|
+
# Headed mode
|
|
477
|
+
npx playwright test --headed
|
|
478
|
+
|
|
479
|
+
# Slow motion
|
|
480
|
+
npx playwright test --headed --slowmo=1000
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
### In-Code Debugging
|
|
484
|
+
|
|
485
|
+
```javascript
|
|
486
|
+
// Pause execution
|
|
487
|
+
await page.pause();
|
|
488
|
+
|
|
489
|
+
// Console logs
|
|
490
|
+
page.on('console', msg => console.log('Browser log:', msg.text()));
|
|
491
|
+
page.on('pageerror', error => console.log('Page error:', error));
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
## Performance Testing
|
|
495
|
+
|
|
496
|
+
```javascript
|
|
497
|
+
// Measure page load time
|
|
498
|
+
const startTime = Date.now();
|
|
499
|
+
await page.goto('https://example.com');
|
|
500
|
+
const loadTime = Date.now() - startTime;
|
|
501
|
+
console.log(`Page loaded in ${loadTime}ms`);
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
## Parallel Execution
|
|
505
|
+
|
|
506
|
+
```javascript
|
|
507
|
+
// Run tests in parallel
|
|
508
|
+
test.describe.parallel('Parallel suite', () => {
|
|
509
|
+
test('test 1', async ({ page }) => {
|
|
510
|
+
// Runs in parallel with test 2
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
test('test 2', async ({ page }) => {
|
|
514
|
+
// Runs in parallel with test 1
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
## Data-Driven Testing
|
|
520
|
+
|
|
521
|
+
```javascript
|
|
522
|
+
// Parameterized tests
|
|
523
|
+
const testData = [
|
|
524
|
+
{ username: 'user1', password: 'pass1', expected: 'Welcome user1' },
|
|
525
|
+
{ username: 'user2', password: 'pass2', expected: 'Welcome user2' },
|
|
526
|
+
];
|
|
527
|
+
|
|
528
|
+
testData.forEach(({ username, password, expected }) => {
|
|
529
|
+
test(`login with ${username}`, async ({ page }) => {
|
|
530
|
+
await page.goto('/login');
|
|
531
|
+
await page.fill('#username', username);
|
|
532
|
+
await page.fill('#password', password);
|
|
533
|
+
await page.click('button[type="submit"]');
|
|
534
|
+
await expect(page.locator('.message')).toHaveText(expected);
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
## Accessibility Testing
|
|
540
|
+
|
|
541
|
+
```javascript
|
|
542
|
+
import { injectAxe, checkA11y } from 'axe-playwright';
|
|
543
|
+
|
|
544
|
+
test('accessibility check', async ({ page }) => {
|
|
545
|
+
await page.goto('/');
|
|
546
|
+
await injectAxe(page);
|
|
547
|
+
await checkA11y(page);
|
|
548
|
+
});
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
## CI/CD Integration
|
|
552
|
+
|
|
553
|
+
### GitHub Actions
|
|
554
|
+
|
|
555
|
+
```yaml
|
|
556
|
+
name: Playwright Tests
|
|
557
|
+
on:
|
|
558
|
+
push:
|
|
559
|
+
branches: [main, master]
|
|
560
|
+
jobs:
|
|
561
|
+
test:
|
|
562
|
+
runs-on: ubuntu-latest
|
|
563
|
+
steps:
|
|
564
|
+
- uses: actions/checkout@v3
|
|
565
|
+
- uses: actions/setup-node@v3
|
|
566
|
+
- name: Install dependencies
|
|
567
|
+
run: npm ci
|
|
568
|
+
- name: Install Playwright Browsers
|
|
569
|
+
run: npx playwright install --with-deps
|
|
570
|
+
- name: Run tests
|
|
571
|
+
run: npx playwright test
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
## Best Practices
|
|
575
|
+
|
|
576
|
+
1. **Test Organization** - Use descriptive test names, group related tests
|
|
577
|
+
2. **Selector Strategy** - Prefer data-testid attributes, use role-based selectors
|
|
578
|
+
3. **Waiting** - Use Playwright's auto-waiting, avoid hard-coded delays
|
|
579
|
+
4. **Error Handling** - Add proper error messages, take screenshots on failure
|
|
580
|
+
5. **Performance** - Run tests in parallel, reuse authentication state
|
|
581
|
+
|
|
582
|
+
## Common Patterns & Solutions
|
|
583
|
+
|
|
584
|
+
### Handling Popups
|
|
585
|
+
|
|
586
|
+
```javascript
|
|
587
|
+
const [popup] = await Promise.all([
|
|
588
|
+
page.waitForEvent('popup'),
|
|
589
|
+
page.click('button.open-popup')
|
|
590
|
+
]);
|
|
591
|
+
await popup.waitForLoadState();
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
### File Downloads
|
|
595
|
+
|
|
596
|
+
```javascript
|
|
597
|
+
const [download] = await Promise.all([
|
|
598
|
+
page.waitForEvent('download'),
|
|
599
|
+
page.click('button.download')
|
|
600
|
+
]);
|
|
601
|
+
await download.saveAs(`./downloads/${download.suggestedFilename()}`);
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
### iFrames
|
|
605
|
+
|
|
606
|
+
```javascript
|
|
607
|
+
const frame = page.frameLocator('#my-iframe');
|
|
608
|
+
await frame.locator('button').click();
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
### Infinite Scroll
|
|
612
|
+
|
|
613
|
+
```javascript
|
|
614
|
+
async function scrollToBottom(page) {
|
|
615
|
+
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
|
|
616
|
+
await page.waitForTimeout(500);
|
|
617
|
+
}
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
## Troubleshooting
|
|
621
|
+
|
|
622
|
+
### Common Issues
|
|
623
|
+
|
|
624
|
+
1. **Element not found** - Check if element is in iframe, verify visibility
|
|
625
|
+
2. **Timeout errors** - Increase timeout, check network conditions
|
|
626
|
+
3. **Flaky tests** - Use proper waiting strategies, mock external dependencies
|
|
627
|
+
4. **Authentication issues** - Verify auth state is properly saved
|
|
628
|
+
|
|
629
|
+
## Quick Reference Commands
|
|
630
|
+
|
|
631
|
+
```bash
|
|
632
|
+
# Run tests
|
|
633
|
+
npx playwright test
|
|
634
|
+
|
|
635
|
+
# Run in headed mode
|
|
636
|
+
npx playwright test --headed
|
|
637
|
+
|
|
638
|
+
# Debug tests
|
|
639
|
+
npx playwright test --debug
|
|
640
|
+
|
|
641
|
+
# Generate code
|
|
642
|
+
npx playwright codegen https://example.com
|
|
643
|
+
|
|
644
|
+
# Show report
|
|
645
|
+
npx playwright show-report
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
## Additional Resources
|
|
649
|
+
|
|
650
|
+
- [Playwright Documentation](https://playwright.dev/docs/intro)
|
|
651
|
+
- [API Reference](https://playwright.dev/docs/api/class-playwright)
|
|
652
|
+
- [Best Practices](https://playwright.dev/docs/best-practices)
|