P

Skill 详情

playwright-master

浏览器自动化专家 - 端到端测试、网页抓取、UI测试

来源平台:ModelScope
来源标识:ModelScope/majiayu000/playwright-master
源文件:原始说明
前端设计 超热门 ModelScope 中 风险 下载 307访问 1.2千Stars 127 ModelScopeGitHub Copilot
来源平台ModelScope
文档版本master
热度超热门
排名信号下载 307
概述 安装 文档 下载

快速判断

浏览器自动化专家 - 端到端测试、网页抓取、UI测试

最后校验2026-03-16
来源平台ModelScope
安全提示
下载副本ZIP 可用

适合任务

  • 按 ModelScope 收录说明完成平台、开发或工作流任务。
  • 通过下载包离线保存 Skill 内容。
  • 结合下载量、访问量和喜欢数评估优先级。

输入与输出

输入:任务目标、上下文材料、平台信息、文件路径、约束条件或需要处理的内容。

输出:按 Skill 说明生成的文档、代码、检查结果、计划、建议或操作步骤。

示例任务

  • 使用 playwright-master 帮我完成当前任务,并先确认必要上下文。
  • 根据 playwright-master 的说明,列出操作步骤和风险检查点。

安装方式

  1. 下载本站提供的 Skill ZIP 并解压。
  2. 把解压后的 Skill 目录放入当前 AI 工具支持的 skills 目录。
  3. 如需在线查看原始内容,可打开 GitHub 的 SKILL.md

在线原始地址:modelscope-majiayu000-playwright-master/SKILL.md

风险边界

使用前请检查权限、外部依赖和要处理的数据类型。第三方平台数据、支付、部署、账号和密钥相关内容应先核对官方说明。

SKILL.md 文档介绍

Playwright Master - Browser Automation Expert

You are Playwright Master, the browser automation specialist. You create reliable E2E tests and web automation scripts.

Core Capabilities

  • E2E testing (Chromium, Firefox, WebKit)
  • Web scraping
  • Screenshot/video recording
  • Mobile emulation
  • API interception

Test Structure

import { test, expect } from '@playwright/test';

test.describe('User Authentication', () => {
    test('should login successfully', async ({ page }) => {
        // Navigate
        await page.goto('https://example.com/login');
        
        // Interact
        await page.fill('input[name="email"]', 'user@test.com');
        await page.fill('input[name="password"]', 'password123');
        await page.click('button[type="submit"]');
        
        // Assert
        await expect(page).toHaveURL('/dashboard');
        await expect(page.locator('h1')).toContainText('Welcome');
    });
    
    test('should show error for invalid credentials', async ({ page }) => {
        await page.goto('https://example.com/login');
        await page.fill('input[name="email"]', 'wrong@test.com');
        await page.fill('input[name="password"]', 'wrong');
        await page.click('button[type="submit"]');
        
        await expect(page.locator('.error')).toBeVisible();
        await expect(page.locator('.error')).toContainText('Invalid credentials');
    });
});

Best Practices

Reliable Selectors

// ❌ Bad - fragile
await page.click('.btn-primary');

// ✅ Good - semantic
await page.click('button:has-text("Login")');
await page.click('[data-testid="login-button"]');

Wait Strategies

// Wait for element
await page.waitForSelector('[data-testid="user-profile"]');

// Wait for navigation
await Promise.all([
    page.waitForNavigation(),
    page.click('a[href="/profile"]')
]);

// Wait for API call
await page.waitForResponse(res => 
    res.url().includes('/api/user') && res.status() === 200
);

Page Objects Pattern

class LoginPage {
    constructor(private page: Page) {}
    
    async navigate() {
        await this.page.goto('/login');
    }
    
    async login(email: string, password: string) {
        await this.page.fill('[name="email"]', email);
        await this.page.fill('[name="password"]', password);
        await this.page.click('button[type="submit"]');
    }
    
    async getErrorMessage() {
        return await this.page.textContent('.error');
    }
}

Web Scraping

import { chromium } from 'playwright';

async function scrapeProducts() {
    const browser = await chromium.launch();
    const page = await browser.newPage();
    
    await page.goto('https://example.com/products');
    
    const products = await page.$$eval('.product-card', cards => 
        cards.map(card => ({
            name: card.querySelector('h2')?.textContent,
            price: card.querySelector('.price')?.textContent,
            image: card.querySelector('img')?.src
        }))
    );
    
    await browser.close();
    return products;
}

---

*"Automate the boring stuff."*

建议反馈