Playwright Skill

โดย lackeyjb

ช่วยให้ Claude สามารถเขียนและดำเนินการระบบอัตโนมัติของ Playwright ได้ทันที ตั้งแต่การทดสอบหน้าเว็บแบบง่ายไปจนถึงขั้นตอนที่ซับซ้อนหลายขั้นตอน

npx skills add https://github.com/lackeyjb/playwright-skill --skill playwright-skill

Playwright Browser Automation

Write and execute focused Playwright scripts for the user's request. Prefer the skill's executor and helpers, but use the full Playwright API when needed.

Path resolution

This skill can be installed in several locations, so resolve its directory first. Set SKILL_DIR to the directory containing this SKILL.md file, then run the commands below as written:

export SKILL_DIR=<absolute path of the directory containing this SKILL.md>
export TMP_DIR="$(node -p 'require("node:os").tmpdir()')"

If shell state does not persist between commands, substitute the literal paths for $SKILL_DIR and $TMP_DIR in each command instead.

Common installation paths:

  • Plugin system: ~/.claude/plugins/marketplaces/playwright-skill/skills/playwright-skill
  • Manual global: ~/.claude/skills/playwright-skill
  • Project-specific: <project>/.claude/skills/playwright-skill

Workflow

  1. For localhost work, detect running servers before writing a URL:

    node -e "require('$SKILL_DIR/lib/helpers').detectDevServers().then(s => console.log(JSON.stringify(s)))"
    

    Use the only result automatically. Ask which URL to use when there are multiple results. Ask for a URL or offer to start a server when none exist.

  2. Write reusable scripts to $TMP_DIR/playwright-test-*.js unless the user asks to save them in the project. Use PW_SCRIPT_DIR to preserve scripts.

  3. Use a visible browser by default. Use headless: true only when requested or when the environment has no display.

  4. Put the target URL in a constant or environment variable.

  5. Run scripts with node "$SKILL_DIR/run.js" <script.js>.

  6. Report actions, failures, and artifact paths. Do not claim success without checking the resulting page.

Setup

Run once:

cd "$SKILL_DIR" && npm run setup

This installs Playwright and Chromium. Use cd "$SKILL_DIR" && npm run install-all-browsers when Firefox or WebKit is required.

Minimal example

const os = require('node:os');
const path = require('node:path');
const { chromium } = require('playwright');

const targetUrl = process.env.TARGET_URL || 'http://localhost:3000';
const artifactDir = process.env.PW_ARTIFACT_DIR || os.tmpdir();

(async () => {
  const browser = await chromium.launch({ headless: false });
  try {
    const page = await browser.newPage();
    await page.goto(targetUrl);
    console.log('Page loaded:', await page.title());
    await page.screenshot({ path: path.join(artifactDir, 'page.png'), fullPage: true });
  } finally {
    await browser.close();
  }
})();

Run it:

node "$SKILL_DIR/run.js" "$TMP_DIR/playwright-test-page.js"

For short one-off tasks, use inline execution:

node "$SKILL_DIR/run.js" -e "const browser = await chromium.launch({headless: false}); try { const page = await browser.newPage(); await page.goto('https://example.com'); console.log(await page.title()); } finally { await browser.close(); }"

The -e process exits as soon as the snippet settles, so close the browser inside the snippet.

Current Playwright patterns

Prefer locators that describe what a user sees, in this order:

  1. page.getByRole() with an accessible name
  2. page.getByLabel() for form controls
  3. page.getByText() for visible content
  4. page.getByTestId() when the application provides a test contract

Actions auto-wait for actionability. Use web-first assertions or a locator's waitFor() instead of waitForSelector(), fixed sleeps, or networkidle.

await page.getByLabel('Email').fill('test@example.com');
await page.getByRole('button', { name: 'Sign in' }).click();
await page.waitForURL('**/dashboard');
await page.getByRole('heading', { name: 'Dashboard' }).waitFor();

Common tasks

Responsive checks

{
  const os = require('node:os');
  const path = require('node:path');

  const artifactDir = process.env.PW_ARTIFACT_DIR || os.tmpdir();
  const viewports = [
    { name: 'desktop', width: 1440, height: 900 },
    { name: 'mobile', width: 390, height: 844 },
  ];

  for (const viewport of viewports) {
    await page.setViewportSize(viewport);
    await page.goto(targetUrl);
    await page.screenshot({ path: path.join(artifactDir, `${viewport.name}.png`), fullPage: true });
  }
}

Login flow

Use test credentials supplied by the user. Never invent or expose real credentials. Verify both the navigation and a post-login element.

await page.goto(`${targetUrl}/login`);
await page.getByLabel('Email').fill(process.env.TEST_EMAIL);
await page.getByLabel('Password').fill(process.env.TEST_PASSWORD);
await page.getByRole('button', { name: /sign in|log in/i }).click();
await page.waitForURL('**/dashboard');
await page.getByRole('heading', { name: /dashboard/i }).waitFor();

Save scripts and artifacts

PW_SCRIPT_DIR=./playwright-tests node "$SKILL_DIR/run.js" "$TMP_DIR/playwright-test-login.js"
PW_ARTIFACT_DIR=./playwright-artifacts node "$SKILL_DIR/run.js" "$TMP_DIR/playwright-test-page.js"

PW_SCRIPT_DIR copies file-based scripts before execution and adds a timestamp when a filename already exists. PW_ARTIFACT_DIR controls helper screenshot output; the default is the operating system temporary directory.

Connect to an existing Chrome session

Start Chrome with remote debugging enabled, then connect with Playwright:

const browser = await chromium.connectOverCDP('http://127.0.0.1:9222');
const page = browser.contexts()[0].pages()[0];

This reuses cookies and extensions in that session. Do not use it for secrets unless the user explicitly asks; a connected browser has the user's access.

Helpers

const helpers = require(`${process.env.PW_SKILL_DIR}/lib/helpers`);

const servers = await helpers.detectDevServers();
const browser = await helpers.launchBrowser('chromium');
const context = await helpers.createContext(browser);
const page = await context.newPage();
await helpers.handleCookieBanner(page);
await helpers.takeScreenshot(page, 'result');

Available helpers are detectDevServers, getExtraHeadersFromEnv, launchBrowser, createContext, handleCookieBanner, and takeScreenshot. Use Playwright locators and assertions directly for actions, waits, extraction, authentication, tables, and retries.

Configuration

  • PW_BROWSER: chromium, firefox, or webkit for launchBrowser().
  • PW_CHANNEL: installed browser channel such as chrome or msedge.
  • PW_EXECUTABLE_PATH: explicit browser executable path.
  • PW_HEADLESS: true or false; visible mode is the default.
  • SLOW_MO: action delay in milliseconds.
  • PW_HEADER_NAME and PW_HEADER_VALUE: one extra HTTP header.
  • PW_EXTRA_HEADERS: JSON object of extra HTTP headers.
  • PW_SCRIPT_DIR: directory for preserving file-based scripts.
  • PW_ARTIFACT_DIR: directory for helper-generated screenshots.

See API_REFERENCE.md for network interception, API mocking, authentication state, video, visual checks, device emulation, and CI patterns.

Skills ที่เกี่ยวข้อง

agent-framework-azure-ai-py
microsoft
สร้างเอเจนต์ Azure AI Foundry โดยใช้ Microsoft Agent Framework Python SDK (agent-framework-azure-ai) ใช้เมื่อสร้างเอเจนต์แบบถาวรด้วย AzureAIAgentsProvider ใช้เครื่องมือที่โฮสต์ไว้ (ตัวแปลโค้ด การค้นหาไฟล์ การค้นหาเว็บ) ผสานรวมเซิร์ฟเวอร์ MCP จัดการเธรดการสนทนา หรือใช้งานการตอบสนองแบบสตรีมมิ่ง ครอบคลุมเครื่องมือฟังก์ชัน ผลลัพธ์แบบมีโครงสร้าง และเอเจนต์แบบหลายเครื่องมือ
development
Agents
ElevenLabs
สร้างเอเจนต์เสียง AI ด้วย ElevenLabs ใช้เมื่อสร้างผู้ช่วยเสียง บอทบริการลูกค้า ตัวละครเสียงแบบโต้ตอบ หรือประสบการณ์การสนทนาด้วยเสียงแบบเรียลไทม์
development
appinsights-instrumentation
microsoft
คำแนะนำและเอกสารอ้างอิงสำหรับการติดตั้งเครื่องมือวัดเว็บแอปพลิเคชันด้วย Azure Application Insights ครอบคลุมการตั้งค่า SDK รูปแบบการวัดและส่งข้อมูลทางไกล และการกำหนดค่าสำหรับแอปพลิเคชัน ASP.NET Core และ Node.js ที่โฮสต์ใน Azure แยกความแตกต่างระหว่างทักษะนี้ (ข้อมูลอ้างอิงและคำแนะนำ) และ azure-prepare (การนำไปใช้งานจริง) เรียกใช้ azure-prepare เมื่อผู้ใช้ต้องการเพิ่มเครื่องมือวัดในโปรเจกต์ของตน ให้คำแนะนำการติดตั้งเครื่องมือวัดอัตโนมัติสำหรับแอป C# ASP.NET Core ใน Azure App Service รวมถึงแบบแมนนวล...
devopsapidevelopment
Artifacts Builder
Anthropic
ชุดเครื่องมือสำหรับสร้างสิ่งประดิษฐ์ HTML claude.ai ที่ซับซ้อนและมีหลายองค์ประกอบ โดยใช้เทคโนโลยีเว็บฟร้อนท์เอนด์สมัยใหม่ (React, Tailwind CSS, shadcn/ui) ใช้สำหรับสิ่งประดิษฐ์ที่ซับซ้อนซึ่งต้องการการจัดการสถานะ การกำหนดเส้นทาง หรือส่วนประกอบ shadcn/ui - ไม่ใช่สำหรับสิ่งประดิษฐ์ HTML/JSX ไฟล์เดียวแบบง่าย สัญญาอนุญาต: ข้อกำหนดทั้งหมดอยู่ใน LICENSE.txt
development
azure-ai
microsoft
เข้าถึงบริการ Azure AI Search, Speech, OpenAI และ Document Intelligence ผ่านเครื่องมือ MCP แบบรวมศูนย์ AI Search รองรับการค้นหาแบบ full-text, vector, hybrid และ semantic พร้อมการเสริมข้อมูลด้วย AI ในตัวสำหรับการแยกเอนทิตีและการรู้จำอักขระด้วยแสง (OCR) บริการ Speech จัดการการถอดเสียงแบบเรียลไทม์และแบบแบตช์ การสังเคราะห์เสียงพูดเป็นข้อความด้วยเสียงประสาท และการระบุผู้พูด เครื่องมือ MCP ให้การเข้าถึงโดยตรง: azure__search สำหรับการค้นหาดัชนี และ azure__speech สำหรับการถอดเสียงและการสังเคราะห์ SDK...
researchapidevelopment
azure-ai
microsoft
ใช้สำหรับ Azure AI: Search, Speech, OpenAI, Document Intelligence ช่วยในการค้นหา ค้นหาแบบเวกเตอร์/ไฮบริด การแปลงเสียงเป็นข้อความ การแปลงข้อความเป็นเสียง การถอดเสียง และ OCR เมื่อ: AI Search, การค้นหาคำสั่ง, การค้นหาแบบเวกเตอร์, การค้นหาแบบไฮบริด, การค้นหาเชิงความหมาย, การแปลงเสียงเป็นข้อความ, การแปลงข้อความเป็นเสียง, การถอดเสียง, OCR, แปลงข้อความเป็นเสียง
development
azure-ai-agents-persistent-dotnet
microsoft
Azure AI Agents Persistent SDK สำหรับ .NET เอสดีเคระดับต่ำสำหรับสร้างและจัดการเอเจนต์ AI พร้อมเธรด ข้อความ รัน และเครื่องมือ ใช้สำหรับการสร้าง อ่าน อัปเดต ลบเอเจนต์ เธรดการสนทนา การตอบสนองแบบสตรีมมิ่ง การเรียกฟังก์ชัน การค้นหาไฟล์ และตัวแปลโค้ด ทริกเกอร์: "PersistentAgentsClient", "persistent agents", "agent threads", "agent runs", "streaming agents", "function calling agents .NET
development
azure-ai-agents-persistent-java
microsoft
Azure AI Agents Persistent SDK สำหรับ Java. SDK ระดับต่ำสำหรับการสร้างและจัดการเอเจนต์ AI พร้อมเธรด ข้อความ การรัน และเครื่องมือ ทริกเกอร์: "PersistentAgentsClient", "persistent agents java", "agent threads java", "agent runs java", "streaming agents java
development