ワンクリックで
playwright-testing
Playwright testing. Use this skill to write and run automated tests for web applications using Playwright.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Playwright testing. Use this skill to write and run automated tests for web applications using Playwright.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
Create and maintain JSR (JavaScript Registry) packages. Use this whenever the user wants to publish a package to JSR, set up a new JSR project, configure exports, write documentation, or troubleshoot JSR publishing.
Skills for Puzzle Driven Development (PDD). Refer to this skill when a project uses PDD or the operator mentions PDD or puzzle-driven development. Use this skill when: (1) Breaking a large feature into incremental deliverables, (2) Writing @todo stub comments to mark unimplemented code, (3) Picking up an existing @todo puzzle to implement, (4) Deciding whether to wrap up a task with a stub or keep working.
Use this when: (1) Creating a new project-specific skill to document project patterns, (2) Improving or updating an existing project skill, (3) Writing skill descriptions that will trigger other agents, (4) Organizing skill content for progressive disclosure, or (5) Learning what project-specific skills exist in .claude/skills/. Ensures skills follow project conventions and provide effective progressive disclosure.
Use this skill to send a message over Discord to the operator
Learn the rules of packlets for managing a JavaScript/TypeScript project. Use this skill whenever a user mentions packlets or when working in a project with packlets (src/packlets) directory.
Use this skill to run background processes or long running processes using tmux.
SOC 職業分類に基づく
| name | playwright-testing |
| description | Playwright testing. Use this skill to write and run automated tests for web applications using Playwright. |
For more details on Playwright best practices see https://playwright.dev/docs/best-practices
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.
Each test should be completely isolated from another test and should run independently with its own local storage, session storage, data, cookies etc.
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.
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");
data-testid// 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.
// 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
// 👎 Don't use manual assertions
expect(await page.getByText("welcome").isVisible()).toBe(true);
// 👍 Use web first assertions
await expect(page.getByText("welcome")).toBeVisible();
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.
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();
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)
}
}
Tester prefix. It helps us distinguish between production code and test code (when the test lives in the same repository as the production code).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:
PageObjectContext.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.