← 返回
未分类 中文

Playwright Test Generator

AI-driven Playwright test code generator for QA engineers. Generates Page Object Models, standard test scripts, and data-driven tests from natural language d...
AI驱动的Playwright测试代码生成器,为QA工程师提供,可根据自然语言描述生成页面对象模型、标准测试脚本及数据驱动测试。
shenghoo123-png
未分类 clawhub v1.1.0 1 版本 100000 Key: 无需
★ 1
Stars
📥 521
下载
💾 1
安装
1
版本
#automation#generator#latest#playwright#qa#test-automation#testing

概述

Playwright Test Generator

An AI-powered skill that automatically generates Playwright test scripts from natural language descriptions, HTML/page analysis, or existing page URLs.

When to Use

This skill activates when the user:

  • Asks to "generate Playwright tests", "create test script", "build POM from page"
  • Wants to convert natural language steps into test code
  • Needs to analyze a page/URL and generate locators + test code
  • Requests data-driven or Page Object Model test generation
  • Mentions Playwright test generation for pytest, Jest, or native Playwright

Input Types

1. Natural Language → Test Code

Provide test steps in plain English and get complete test scripts.

Example:

Input: "Login to the app with username and password, then verify dashboard loads"
Output: Complete pytest-playwright test with POM

2. Page/URL Analysis → Locators + POM

Provide a URL or HTML content to extract elements and generate Page Object Model.

Example:

Input: URL https://example.com/login
Output: login_page.py with all form element locators + methods

3. HTML Snippet → Element Locators

Provide HTML snippets to extract robust CSS/XPath selectors.

Output Types (Code Genres)

GenreDescriptionFramework
-------------------------------
pomPage Object Modelpytest-playwright / Jest Playwright
standardStandard test scriptpytest-playwright / native Playwright
data-drivenParameterized data testspytest-playwright / Jest Playwright
apiAPI test helpersAny

Framework Support

FrameworkLanguageCode Type
--------------------------------
pytest-playwrightPythonpom, standard, data-driven
jest-playwrightJavaScript/TypeScriptpom, standard, data-driven
native-playwrightJavaScript/TypeScriptstandard, pom

Usage

Command Mode

# Generate from natural language
playwright-test-generator generate \
  --input "Click login button, enter username and password, click submit" \
  --framework pytest \
  --type pom \
  --output ./tests/

# Analyze URL and generate POM
playwright-test-generator analyze \
  --url https://example.com/login \
  --framework pytest \
  --output ./pages/

# Analyze HTML and generate locators
playwright-test-generator extract-locators \
  --html "$(cat form.html)" \
  --output ./locators.json

Interactive Mode

playwright-test-generator interactive

Follow the guided wizard to generate tests step by step.

API Mode (from other skills/agents)

import { PlaywrightTestGenerator } from './src/generator.js';

const gen = new PlaywrightTestGenerator();
const result = await gen.generate({
  input: 'Click the search box, type "playwright", press Enter',
  framework: 'pytest-playwright',
  codeType: 'standard',
  pageName: 'search_page'
});

Pricing / Tier

TierFeaturesRate
----------------------
Free≤10 generations/day, standard scripts only0 credits
ProUnlimited, POM + data-driven, priority1 credit/test
EnterpriseCustom frameworks, team features, SLAContact

Developer Guide

Architecture

src/
├── index.js        # CLI entry + skill interface
├── generator.js    # Core code generation logic
├── parser.js       # NL → test steps parser
├── locator.js      # HTML → locator extractor
└── templates/      # Code generation templates
    ├── pytest_pom.py.ejs
    ├── pytest_standard.py.ejs
    ├── pytest_data_driven.py.ejs
    ├── jest_pom.ts.ejs
    ├── jest_standard.ts.ejs
    └── native_pom.ts.ejs

Generator Pipeline

  1. Parse NL input → structured test steps
  2. Extract page elements (if URL/HTML provided)
  3. Select template based on framework + code type
  4. Render template with steps + locators
  5. Output formatted code

Test Steps Schema

{
  action: 'click' | 'fill' | 'press' | 'navigate' | 'wait' | 'assert' | 'hover' | 'select' | 'check' | 'uncheck',
  target: string,        // CSS selector, XPath, or role-based
  value?: string,        // Input value or expected result
  options?: {
    timeout?: number,
    force?: boolean,
    expect?: 'visible' | 'hidden' | 'enabled' | 'disabled'
  }
}

Locator Strategy

Priority order for element selection:

  1. data-testid attribute (most reliable)
  2. role + accessible name (a11y-first)
  3. id attribute
  4. CSS class + tag combinations
  5. XPath (last resort)

Template Variables

VariableDescription
-----------------------
{{pageName}}Page object name (PascalCase)
{{baseUrl}}Target URL
{{steps}}Array of parsed test steps
{{locators}}Map of element name → selector
{{testData}}Data-driven test data
{{framework}}Target framework
{{imports}}Required imports

Error Handling

  • Invalid input → error with suggestion
  • Unsupported framework → list supported frameworks
  • Generation failure → partial output + error report

版本历史

共 1 个版本

  • v1.1.0 当前
    2026-05-03 08:26 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

Data Cleaner Skill

shenghoo123-png
AI驱动的Excel/CSV数据清洗工具,可去重、处理缺失值、标准化格式、检测异常值,并支持批量处理。
★ 0 📥 717

电商产品描述批量生成器

shenghoo123-png
批量生成多平台电商标题、卖点、详情,支持中英双语与CSV导入,提升跨境及本地化文案效率。
★ 0 📥 499

跨境电商选品工具

shenghoo123-png
跨境电商关键词分析、利润计算与AI Listing生成(支持亚马逊、eBay),助力精准选品与定价优化。
★ 0 📥 517