Token导航 LogoToken导航TokenDH.com
研究检索操作浏览器github未标认证来源可访问许可证需确认审计异常

playwright-testingPlaywright 测试

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

259

周安装

11

GitHub Stars

2

下载量

91
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:playwright-testing(Playwright 测试)
来源仓库:https://github.com/dtinth/agent-skills
仓库路径:skills/playwright-testing
安装命令:
npx skills add https://github.com/dtinth/agent-skills --skill playwright-testing
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/dtinth/agent-skills --skill playwright-testing

简介

playwright-testing 提供自动化测试设计和执行辅助能力。

  • 适用于端到端测试、回归验证和测试用例维护等质量保障场景。
  • 强调验证用户可见行为,避免依赖实现细节的测试设计。
  • 使用前需确认项目测试框架配置,区分模拟环境和真实浏览器操作。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Test authoring guidelines

For more details on Playwright best practices see https://playwright.dev/docs/best-practices

Test user-visible behavior

Automated tests should verify that the application code works for the end users, and avoid relying on implementation details such as things which users will not typically use, see, or even know about such as the name of a function, whether something is an array, or the CSS class of some element. The end user will see or interact with what is rendered on the page, so your test should typically only see/interact with the same rendered output.

Make tests as isolated as possible

Each test should be completely isolated from another test and should run independently with its own local storage, session storage, data, cookies etc.

Avoid testing third-party dependencies

Only test what you control. Don't try to test links to external sites or third party servers that you do not control, unless it is specifically for testing purposes.

Use locators

Locators come with auto waiting and retry-ability. To make tests resilient, we recommend prioritizing user-facing attributes and explicit contracts.

// 👍 Use role selectors
page.getByRole("button", { name: "submit" });

// Using filters to locate elements with text
page.getByRole("listitem").filter({ hasText: "Product 2" });

// Use chaining and filtering
page
  .getByRole("listitem")
  .filter({ hasText: "Product 2" })
  .getByRole("button", { name: "Add to cart" });

// 👎 Avoid CSS selectors
page.locator("button.buttonIcon.episode-actions-later");

Locator preference

  1. getByRole to locate by explicit and implicit accessibility attributes ⭐⭐⭐⭐⭐
  2. getByText to locate by text content
  3. getByLabel to locate a form control by associated label's text
  4. getByPlaceholder to locate an input by placeholder
  5. getByAltText to locate an element, usually image, by its text alternative
  6. getByTitle to locate an element by its title attribute
  7. getByTestId to locate an element based on its data-testid

Filtering

// Filter elements having text
page.getByRole("listitem").filter({ hasText: "Product 2" });

// Filter elements not having text
page.getByRole("listitem").filter({ hasNotText: "Out of stock" });

// Filter elements having another locator inside
page
  .getByRole("listitem")
  .filter({ has: page.getByRole("heading", { name: "Product 2" }) });

// Filter only visible elements
// Note: Hidden elements do not have a role, so this filter is not
//       needed when using getByRole
// 👎 CSS selector is not recommended, use a better locator if possible
page.locator(".something").filter({ visible: true });

The filtering locator must be relative to the original locator and is queried starting with the original locator match, not the document root. Therefore, the following will not work, because the filtering locator starts matching from the <ul> list element that is outside of the <li> list item matched by the original locator:

// ✖ WRONG
page
  .getByRole('listitem')
  .filter({ has: page.getByRole('list').getByText('Product 2') }))

There is hasNot which does the opposite of has.

Combining locators

// Chaining: Find buttons inside listitems
page.getByRole("listitem").getByRole("button");

// Use `and` for intersection (buttons whose title is Subscribe)
page.getByRole("button").and(page.getByTitle("Subscribe"));

// Use `or` to match multiple locators
page
  .getByRole("button", { name: "New" })
  .or(page.getByText("Confirm security settings"));

// Example: Dismiss a known dialog before clicking New
const newEmail = page.getByRole("button", { name: "New" });
const dialog = page.getByText("Confirm security settings");
await expect(newEmail.or(dialog).first()).toBeVisible();
if (await dialog.isVisible())
  await page.getByRole("button", { name: "Dismiss" }).click();
await newEmail.click();

Locators are strict. This means that all operations on locators that imply some target DOM element will throw an exception if more than one element matches. For example, the following call throws if there are several buttons in the DOM:

// Throws an error if more than one
await page.getByRole("button").click();

// Click the first button
await page.getByRole("button").first().click();

For more info on selectors refer to https://playwright.dev/docs/locators

Use web first assertions

// 👎 Don't use manual assertions
expect(await page.getByText("welcome").isVisible()).toBe(true);

// 👍 Use web first assertions
await expect(page.getByText("welcome")).toBeVisible();

When encountering challenges

If you encounter challenges when writing tests, it may be tempting to work around them (e.g. by using timeouts, sleeps, or brittle selectors). DO NOT DO THAT! Instead, try to make the app more testable first. Maybe adding semantic attributes (best), data attributes, or test IDs. For example, if a test script clicks the button too fast (before it is ready to be clicked), consider adjusting the app to initially disable the button until it is really ready to be clicked.

Locator handlers

When testing a web page, sometimes unexpected overlays like a "Sign up" dialog appear and block actions you want to automate, e.g. clicking a button. These overlays don't always show up in the same way or at the same time, making them tricky to handle in automated tests.

The addLocatorHandler lets you set up a special function, called a handler, that activates when it detects that overlay is visible. The handler's job is to remove the overlay, allowing your test to continue as if the overlay wasn't there.

Running the handler will alter your page state mid-test. For example it will change the currently focused element and move the mouse. Make sure that actions that run after the handler are self-contained and do not rely on the focus and mouse state being unchanged.

// Setup the handler.
await page.addLocatorHandler(
  page.getByText("Sign up to the newsletter"),
  async () => {
    await page.getByRole("button", { name: "No thanks" }).click();
  },
);

// Write the test as usual.
await page.goto("https://example.com");
await page.getByRole("button", { name: "Start here" }).click();

Page Objects

To set up structure for page objects, extend the base test and expect functions:

// support/index.ts
import { test as base, expect as baseExpect } from "@playwright/test";
import { AppTester } from "./AppTester";

export const test =
  base.extend <
  { app: AppTester } >
  {
    app: async ({ page }, use) => {
      const app = new AppTester(page);
      await use(app);
    },
  };

export const expect = baseExpect;

Create a context interface for page objects:

// support/PageObjectContext.ts
export interface PageObjectContext {
  page: Page
}

Create an AppTester, the root page object:

import type { PageObjectContext } from './PageObjectContext'
import { LoginPageTester } from './LoginPageTester'
import { RepoPageTester } from './RepoPageTester'

export class AppTester {
  constructor(public context: PageObjectContext) {}
  get loginPage() {
    return new LoginPageTester(this.context)
  }
  get repoPage() {
    return new RepoPageTester(this.context)
  }
}
  • Name page objects as well as the root tester class with the Tester prefix. It helps us distinguish between production code and test code (when the test lives in the same repository as the production code).
  • Use getters to lazily-instantiate page objects, so that we do not create page objects that we do not use. Each page object is simple enough and are stateless, so they do not need to be memoized.

Create a page object for each page in your app. For example, a LoginPageTester:

export class LoginPageTester {
  constructor(public context: PageObjectContext) {}
  async goto() {
    const { page } = this.context
    await page.goto('/login')
  }
  async login(username: string, password: string) {
    const { page } = this.context
    await page.getByRole('textbox', { name: 'Username' }).fill(username)
    await page.getByRole('textbox', { name: 'Password' }).fill(password)
    await page.getByRole('button', { name: 'Sign in' }).click()
  }
}

A page object:

  • Is a class.
  • Has a constructor that takes a PageObjectContext.
  • Exposes methods and properties that represent user actions and elements on the page.

Now it can be used in tests:

import { test, expect } from "./support";

test("Create a new issue", async ({ app }) => {
  await app.loginPage.goto();
  await app.loginPage.login("username", "password");
  await app.repoPage.goto("myorg/myrepo");
});

Note: Work iteratively and don't create a premature abstraction! Use existing page object if possible. If not, don't create a new page object just yet! Implement it directly inside the test, and get it working first. Once working, analyze your test script to see if the hardcoded behavior should be added to a an existing page object or a new page object should be created.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.44%
按下载量换算30

Claude

29.38%
按下载量换算27

Cursor

18.59%
按下载量换算17

Gemini CLI

9.36%
按下载量换算9

安全审计

Gen Agent Trust Hub

未通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills