[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6AEQG00FEWT575XHW1X72K3":3,"skill-same:01M6AEQG00FEWT575XHW1X72K3":123},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":31,"publishedAt":59,"linkOnly":60,"markdownContent":61,"markdownBody":62,"frontMatter":63,"refName":71,"commitSha":72,"skillDirectory":73,"forksCount":74,"repositoryHtmlUrl":75,"repositoryHomepageUrl":76,"ownerHtmlUrl":77,"ownerBlogUrl":78,"ownerDescription":79,"updatedAt":80,"install":81,"resources":94},"01M6AEQG00FEWT575XHW1X72K3","playwright-java",null,"Scaffold, write, debug, and enhance enterprise-grade Playwright E2E tests in Java using Page Object Model, JUnit 5, Allure reporting, and parallel execution.","davila7\u002Fclaude-code-templates","davila7","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F6216945?v=4","01M6ADEWWFPS191NFM0Y1EX1JH","Daniel Avila","01M6ADJHGM78PHQRD3XZTFDVKK",33481,"MIT","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fdevelopment\u002Fplaywright-java\u002FSKILL.md",[18,23,26],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000008","测试与质量","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":27,"categoryName":28,"taxonomyType":29,"taxonomyTypeDesc":30},"01JBSEEDCAT000000000000030","开发工程师","PROFESSION","适用职业",[32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58],"playwright","java","playwright java","execution","playwright e2e tests","test-automation","2025","selenium-alternative","allure","page-object-model","junit5","e2e-testing","community","write","parallel","model","testing","Enterprise","reporting","selenium","e2e tests","debug","scaffold","test","automation","antigravity","safe","2026-11-10 10:12:30",false,"---\nname: playwright-java\ndescription: \"Scaffold, write, debug, and enhance enterprise-grade Playwright E2E tests in Java using Page Object Model, JUnit 5, Allure reporting, and parallel execution.\"\nmetadata:\n  category: test-automation\n  risk: safe\n  source: community\n  date_added: \"2025-03-08\"\n  author: amalsam18\n  tags: [playwright, java, e2e-testing, junit5, page-object-model, allure, selenium-alternative]\n  tools: [claude, cursor,antigravity]\n---\n\n# Playwright Java – Advanced Test Automation\n\n## Overview\n\nThis skill produces production-quality, enterprise-grade Playwright Java test code.\nIt enforces the Page Object Model (POM), strict locator strategies, thread-safe parallel\nexecution, and full Allure reporting integration. Targets Java 17+ and Playwright 1.44+.\n\nSupporting reference files are available for deeper topics:\n\n| Topic | File |\n|-------|------|\n| Maven POM, ConfigReader, Docker\u002FCI setup | `references\u002Fconfig.md` |\n| Component pattern, dropdowns, uploads, waits | `references\u002Fpage-objects.md` |\n| Full assertion API, soft assertions, visual testing | `references\u002Fassertions.md` |\n| Fixtures, test data factory, auth state, retry | `references\u002Ffixtures.md` |\n| Drop-in base class templates | `templates\u002FBaseTest.java`, `templates\u002FBasePage.java` |\n\n---\n\n## When to Use This Skill\n\n- Use when scaffolding a new Playwright Java project from scratch\n- Use when writing Page Object classes or JUnit 5 test classes\n- Use when the user asks about cross-browser testing, parallel execution, or Allure reports\n- Use when fixing flaky tests or replacing `Thread.sleep()` with proper waits\n- Use when setting up Playwright in CI\u002FCD pipelines (GitHub Actions, Jenkins, Docker)\n- Use when combining API calls and UI assertions in a single test (hybrid testing)\n- Use when the user mentions \"POM pattern\", \"BrowserContext\", \"Playwright fixtures\", or \"traces\"\n\n---\n\n## How It Works\n\n### Step 1: Decide the Approach\n\nUse this matrix to pick the right pattern before writing any code:\n\n| User Request | Approach |\n|---|---|\n| New project from scratch | Full scaffold — see `references\u002Fconfig.md` |\n| Single feature test | POM page class + JUnit5 test class |\n| API + UI hybrid | `APIRequestContext` alongside `Page` |\n| Cross-browser | `@MethodSource` parameterized over browser names |\n| Flaky test fix | Replace `sleep` with `waitFor` \u002F `waitForResponse` |\n| CI integration | `playwright install --with-deps` in pipeline |\n| Parallel execution | `junit-platform.properties` + `ThreadLocal` |\n| Rich reporting | Allure + Playwright trace + video recording |\n\n---\n\n### Step 2: Scaffold the Project Structure\n\nAlways use this layout when creating a new project:\n\n```\nsrc\u002F\n├── test\u002F\n│   ├── java\u002Fcom\u002Fcompany\u002Ftests\u002F\n│   │   ├── base\u002F\n│   │   │   ├── BaseTest.java        ← templates\u002FBaseTest.java\n│   │   │   └── BasePage.java        ← templates\u002FBasePage.java\n│   │   ├── pages\u002F\n│   │   │   └── LoginPage.java\n│   │   ├── tests\u002F\n│   │   │   └── LoginTest.java\n│   │   ├── utils\u002F\n│   │   │   ├── TestDataFactory.java\n│   │   │   └── WaitUtils.java\n│   │   └── config\u002F\n│   │       └── ConfigReader.java\n│   └── resources\u002F\n│       ├── test.properties\n│       ├── junit-platform.properties\n│       └── testdata\u002Fusers.json\npom.xml\n```\n\n---\n\n### Step 3: Set Up Thread-Safe BaseTest\n\n```java\npublic class BaseTest {\n    protected static ThreadLocal\u003CPlaywright>     playwrightTL = new ThreadLocal\u003C>();\n    protected static ThreadLocal\u003CBrowser>        browserTL    = new ThreadLocal\u003C>();\n    protected static ThreadLocal\u003CBrowserContext> contextTL    = new ThreadLocal\u003C>();\n    protected static ThreadLocal\u003CPage>           pageTL       = new ThreadLocal\u003C>();\n\n    protected Page page() { return pageTL.get(); }\n\n    @BeforeEach\n    void setUp() {\n        Playwright playwright = Playwright.create();\n        playwrightTL.set(playwright);\n\n        Browser browser = resolveBrowser(playwright).launch(\n            new BrowserType.LaunchOptions()\n                .setHeadless(ConfigReader.isHeadless()));\n        browserTL.set(browser);\n\n        BrowserContext context = browser.newContext(new Browser.NewContextOptions()\n            .setViewportSize(1920, 1080)\n            .setRecordVideoDir(Paths.get(\"target\u002Fvideos\u002F\"))\n            .setLocale(\"en-US\"));\n        context.tracing().start(new Tracing.StartOptions()\n            .setScreenshots(true).setSnapshots(true));\n        contextTL.set(context);\n        pageTL.set(context.newPage());\n    }\n\n    @AfterEach\n    void tearDown(TestInfo testInfo) {\n        String name = testInfo.getDisplayName().replaceAll(\"[^a-zA-Z0-9]\", \"_\");\n        contextTL.get().tracing().stop(new Tracing.StopOptions()\n            .setPath(Paths.get(\"target\u002Ftraces\u002F\" + name + \".zip\")));\n        pageTL.get().close();\n        contextTL.get().close();\n        browserTL.get().close();\n        playwrightTL.get().close();\n    }\n\n    private BrowserType resolveBrowser(Playwright pw) {\n        return switch (System.getProperty(\"browser\", \"chromium\").toLowerCase()) {\n            case \"firefox\" -> pw.firefox();\n            case \"webkit\"  -> pw.webkit();\n            default        -> pw.chromium();\n        };\n    }\n}\n```\n\n---\n\n### Step 4: Build Page Object Classes\n\n```java\npublic class LoginPage extends BasePage {\n\n    \u002F\u002F Declare ALL locators as fields — never inline in action methods\n    private final Locator emailInput;\n    private final Locator passwordInput;\n    private final Locator loginButton;\n    private final Locator errorMessage;\n\n    public LoginPage(Page page) {\n        super(page);\n        emailInput    = page.getByLabel(\"Email address\");\n        passwordInput = page.getByLabel(\"Password\");\n        loginButton   = page.getByRole(AriaRole.BUTTON,\n                            new Page.GetByRoleOptions().setName(\"Sign in\"));\n        errorMessage  = page.getByTestId(\"login-error\");\n    }\n\n    @Override protected String getUrl() { return \"\u002Flogin\"; }\n\n    \u002F\u002F Navigation methods return the next Page Object — enables fluent chaining\n    public DashboardPage loginAs(String email, String password) {\n        fill(emailInput, email);\n        fill(passwordInput, password);\n        clickAndWaitForNav(loginButton);\n        return new DashboardPage(page);\n    }\n\n    public LoginPage loginExpectingError(String email, String password) {\n        fill(emailInput, email);\n        fill(passwordInput, password);\n        loginButton.click();\n        errorMessage.waitFor();\n        return this;\n    }\n\n    public String getErrorMessage() { return errorMessage.textContent(); }\n}\n```\n\n---\n\n### Step 5: Write Tests with Allure Annotations\n\n```java\n@ExtendWith(AllureJunit5.class)\nclass LoginTest extends BaseTest {\n\n    private LoginPage loginPage;\n\n    @BeforeEach\n    void openLoginPage() {\n        loginPage = new LoginPage(page());\n        loginPage.navigate();\n    }\n\n    @Test\n    @Severity(SeverityLevel.BLOCKER)\n    @DisplayName(\"Valid credentials redirect to dashboard\")\n    void shouldLoginWithValidCredentials() {\n        User user = TestDataFactory.getDefaultUser();\n        DashboardPage dash = loginPage.loginAs(user.email(), user.password());\n\n        assertThat(page()).hasURL(Pattern.compile(\".*\u002Fdashboard\"));\n        assertThat(dash.getWelcomeBanner()).containsText(\"Welcome, \" + user.firstName());\n    }\n\n    @Test\n    void shouldShowErrorOnInvalidCredentials() {\n        loginPage.loginExpectingError(\"bad@test.com\", \"wrongpass\");\n\n        SoftAssertions softly = new SoftAssertions();\n        softly.assertThat(loginPage.getErrorMessage()).contains(\"Invalid email or password\");\n        softly.assertThat(page()).hasURL(Pattern.compile(\".*\u002Flogin\"));\n        softly.assertAll();\n    }\n\n    @ParameterizedTest\n    @MethodSource(\"provideInvalidCredentials\")\n    void shouldRejectInvalidCredentials(String email, String password, String expectedError) {\n        loginPage.loginExpectingError(email, password);\n        assertThat(loginPage.getErrorMessage()).containsText(expectedError);\n    }\n\n    static Stream\u003CArguments> provideInvalidCredentials() {\n        return Stream.of(\n            Arguments.of(\"\", \"password123\", \"Email is required\"),\n            Arguments.of(\"user@test.com\", \"\", \"Password is required\"),\n            Arguments.of(\"notanemail\", \"pass\", \"Invalid email format\")\n        );\n    }\n}\n```\n\n---\n\n## Examples\n\n### Example 1: API + UI Hybrid Test\n\n```java\n@Test\nvoid shouldDisplayNewlyCreatedOrder() {\n    \u002F\u002F Arrange via API — faster than navigating through UI\n    APIRequestContext api = page().context().request();\n    APIResponse response = api.post(\"\u002Fapi\u002Forders\",\n        RequestOptions.create()\n            .setHeader(\"Authorization\", \"Bearer \" + authToken)\n            .setData(Map.of(\"productId\", \"SKU-001\", \"quantity\", 2)));\n    assertThat(response).isOK();\n\n    String orderId = new JsonParser().parse(response.text())\n        .getAsJsonObject().get(\"id\").getAsString();\n\n    OrdersPage orders = new OrdersPage(page());\n    orders.navigate();\n    assertThat(orders.getOrderRowById(orderId)).isVisible();\n}\n```\n\n### Example 2: Network Mocking\n\n```java\n@Test\nvoid shouldHandleApiFailureGracefully() {\n    page().route(\"**\u002Fapi\u002Fproducts\", route -> route.fulfill(\n        new Route.FulfillOptions()\n            .setStatus(503)\n            .setBody(\"{\\\"error\\\":\\\"Service Unavailable\\\"}\")\n            .setContentType(\"application\u002Fjson\")));\n\n    ProductsPage products = new ProductsPage(page());\n    products.navigate();\n\n    assertThat(products.getErrorBanner())\n        .hasText(\"We're having trouble loading products. Please try again.\");\n}\n```\n\n### Example 3: Parallel Cross-Browser Test\n\n```java\n@ParameterizedTest\n@MethodSource(\"browsers\")\nvoid shouldRenderCheckoutOnAllBrowsers(String browserName) {\n    System.setProperty(\"browser\", browserName);\n    new CheckoutPage(page()).navigate();\n    assertThat(page().locator(\".checkout-form\")).isVisible();\n}\n\nstatic Stream\u003CString> browsers() {\n    return Stream.of(\"chromium\", \"firefox\", \"webkit\");\n}\n```\n\n### Example 4: Parallel Execution Config\n\n```properties\n# src\u002Ftest\u002Fresources\u002Fjunit-platform.properties\njunit.jupiter.execution.parallel.enabled=true\njunit.jupiter.execution.parallel.mode.default=concurrent\njunit.jupiter.execution.parallel.config.strategy=fixed\njunit.jupiter.execution.parallel.config.fixed.parallelism=4\n```\n\n### Example 5: GitHub Actions CI Pipeline\n\n```yaml\n- name: Install Playwright browsers\n  run: mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args=\"install --with-deps\"\n\n- name: Run tests\n  run: mvn test -Dbrowser=${{ matrix.browser }} -Dheadless=true\n\n- name: Upload traces on failure\n  uses: actions\u002Fupload-artifact@v4\n  if: failure()\n  with:\n    name: playwright-traces\n    path: target\u002Ftraces\u002F\n\n- name: Upload Allure results\n  uses: actions\u002Fupload-artifact@v4\n  if: always()\n  with:\n    name: allure-results\n    path: target\u002Fallure-results\u002F\n```\n\n---\n\n## Best Practices\n\n- ✅ Use `ThreadLocal\u003CPage>` for every parallel-safe test suite\n- ✅ Declare all `Locator` fields at the top of the Page Object class\n- ✅ Return the next Page Object from navigation methods (fluent chaining)\n- ✅ Use `assertThat(locator)` — it auto-retries until timeout\n- ✅ Use `getByRole`, `getByLabel`, `getByTestId` as first-choice locators\n- ✅ Start tracing in `@BeforeEach` and stop with a file path in `@AfterEach`\n- ✅ Use `SoftAssertions` when validating multiple fields on a single page\n- ✅ Set up saved auth state (`storageState`) to skip login across test classes\n- ❌ Never use `Thread.sleep()` — replace with `waitFor()` or `waitForResponse()`\n- ❌ Never hardcode base URLs — always use `ConfigReader.getBaseUrl()`\n- ❌ Never create a `Playwright` instance inside a Page Object\n- ❌ Never use XPath for dynamic or frequently changing elements\n\n---\n\n## Common Pitfalls\n\n- **Problem:** Tests fail randomly in parallel mode\n  **Solution:** Ensure every test creates its own `Playwright → Browser → BrowserContext → Page` chain via `ThreadLocal`. Never share a `Page` across threads.\n\n- **Problem:** `assertThat(locator).isVisible()` times out even when the element appears\n  **Solution:** Increase timeout with `.setTimeout(10_000)` or raise `context.setDefaultTimeout()` in `BaseTest`.\n\n- **Problem:** `Thread.sleep(2000)` was added but tests are still flaky\n  **Solution:** Replace with `page.waitForResponse(\"**\u002Fapi\u002Fendpoint\", () -> action())` or `assertThat(locator).hasText(\"Done\")` which polls automatically.\n\n- **Problem:** Playwright trace zip is empty or missing\n  **Solution:** Ensure `tracing().start()` is called before test actions and `tracing().stop()` is in `@AfterEach` — not `@AfterAll`.\n\n- **Problem:** Allure report is blank or missing steps\n  **Solution:** Add the AspectJ agent to `maven-surefire-plugin` `\u003CargLine>` in `pom.xml` — see `references\u002Fconfig.md` for the exact snippet.\n\n- **Problem:** `storageState` auth file is stale and tests redirect to login\n  **Solution:** Re-run `AuthSetup` to regenerate `target\u002Fauth\u002Fuser-state.json` before the suite, or add a `@BeforeAll` that conditionally refreshes it.\n\n---\n\n## Related Skills\n\n- `@rest-assured-java` — Use for pure API test suites without any UI interaction\n- `@selenium-java` — Legacy alternative; prefer Playwright for all new projects\n- `@allure-reporting` — Deep-dive into Allure annotations, categories, and history trends\n- `@testcontainers-java` — Use alongside this skill when tests need a live database or service\n- `@github-actions-ci` — For building complete multi-browser matrix CI pipelines\n","# Playwright Java – Advanced Test Automation\n\n## Overview\n\nThis skill produces production-quality, enterprise-grade Playwright Java test code.\nIt enforces the Page Object Model (POM), strict locator strategies, thread-safe parallel\nexecution, and full Allure reporting integration. Targets Java 17+ and Playwright 1.44+.\n\nSupporting reference files are available for deeper topics:\n\n| Topic | File |\n|-------|------|\n| Maven POM, ConfigReader, Docker\u002FCI setup | `references\u002Fconfig.md` |\n| Component pattern, dropdowns, uploads, waits | `references\u002Fpage-objects.md` |\n| Full assertion API, soft assertions, visual testing | `references\u002Fassertions.md` |\n| Fixtures, test data factory, auth state, retry | `references\u002Ffixtures.md` |\n| Drop-in base class templates | `templates\u002FBaseTest.java`, `templates\u002FBasePage.java` |\n\n---\n\n## When to Use This Skill\n\n- Use when scaffolding a new Playwright Java project from scratch\n- Use when writing Page Object classes or JUnit 5 test classes\n- Use when the user asks about cross-browser testing, parallel execution, or Allure reports\n- Use when fixing flaky tests or replacing `Thread.sleep()` with proper waits\n- Use when setting up Playwright in CI\u002FCD pipelines (GitHub Actions, Jenkins, Docker)\n- Use when combining API calls and UI assertions in a single test (hybrid testing)\n- Use when the user mentions \"POM pattern\", \"BrowserContext\", \"Playwright fixtures\", or \"traces\"\n\n---\n\n## How It Works\n\n### Step 1: Decide the Approach\n\nUse this matrix to pick the right pattern before writing any code:\n\n| User Request | Approach |\n|---|---|\n| New project from scratch | Full scaffold — see `references\u002Fconfig.md` |\n| Single feature test | POM page class + JUnit5 test class |\n| API + UI hybrid | `APIRequestContext` alongside `Page` |\n| Cross-browser | `@MethodSource` parameterized over browser names |\n| Flaky test fix | Replace `sleep` with `waitFor` \u002F `waitForResponse` |\n| CI integration | `playwright install --with-deps` in pipeline |\n| Parallel execution | `junit-platform.properties` + `ThreadLocal` |\n| Rich reporting | Allure + Playwright trace + video recording |\n\n---\n\n### Step 2: Scaffold the Project Structure\n\nAlways use this layout when creating a new project:\n\n```\nsrc\u002F\n├── test\u002F\n│   ├── java\u002Fcom\u002Fcompany\u002Ftests\u002F\n│   │   ├── base\u002F\n│   │   │   ├── BaseTest.java        ← templates\u002FBaseTest.java\n│   │   │   └── BasePage.java        ← templates\u002FBasePage.java\n│   │   ├── pages\u002F\n│   │   │   └── LoginPage.java\n│   │   ├── tests\u002F\n│   │   │   └── LoginTest.java\n│   │   ├── utils\u002F\n│   │   │   ├── TestDataFactory.java\n│   │   │   └── WaitUtils.java\n│   │   └── config\u002F\n│   │       └── ConfigReader.java\n│   └── resources\u002F\n│       ├── test.properties\n│       ├── junit-platform.properties\n│       └── testdata\u002Fusers.json\npom.xml\n```\n\n---\n\n### Step 3: Set Up Thread-Safe BaseTest\n\n```java\npublic class BaseTest {\n    protected static ThreadLocal\u003CPlaywright>     playwrightTL = new ThreadLocal\u003C>();\n    protected static ThreadLocal\u003CBrowser>        browserTL    = new ThreadLocal\u003C>();\n    protected static ThreadLocal\u003CBrowserContext> contextTL    = new ThreadLocal\u003C>();\n    protected static ThreadLocal\u003CPage>           pageTL       = new ThreadLocal\u003C>();\n\n    protected Page page() { return pageTL.get(); }\n\n    @BeforeEach\n    void setUp() {\n        Playwright playwright = Playwright.create();\n        playwrightTL.set(playwright);\n\n        Browser browser = resolveBrowser(playwright).launch(\n            new BrowserType.LaunchOptions()\n                .setHeadless(ConfigReader.isHeadless()));\n        browserTL.set(browser);\n\n        BrowserContext context = browser.newContext(new Browser.NewContextOptions()\n            .setViewportSize(1920, 1080)\n            .setRecordVideoDir(Paths.get(\"target\u002Fvideos\u002F\"))\n            .setLocale(\"en-US\"));\n        context.tracing().start(new Tracing.StartOptions()\n            .setScreenshots(true).setSnapshots(true));\n        contextTL.set(context);\n        pageTL.set(context.newPage());\n    }\n\n    @AfterEach\n    void tearDown(TestInfo testInfo) {\n        String name = testInfo.getDisplayName().replaceAll(\"[^a-zA-Z0-9]\", \"_\");\n        contextTL.get().tracing().stop(new Tracing.StopOptions()\n            .setPath(Paths.get(\"target\u002Ftraces\u002F\" + name + \".zip\")));\n        pageTL.get().close();\n        contextTL.get().close();\n        browserTL.get().close();\n        playwrightTL.get().close();\n    }\n\n    private BrowserType resolveBrowser(Playwright pw) {\n        return switch (System.getProperty(\"browser\", \"chromium\").toLowerCase()) {\n            case \"firefox\" -> pw.firefox();\n            case \"webkit\"  -> pw.webkit();\n            default        -> pw.chromium();\n        };\n    }\n}\n```\n\n---\n\n### Step 4: Build Page Object Classes\n\n```java\npublic class LoginPage extends BasePage {\n\n    \u002F\u002F Declare ALL locators as fields — never inline in action methods\n    private final Locator emailInput;\n    private final Locator passwordInput;\n    private final Locator loginButton;\n    private final Locator errorMessage;\n\n    public LoginPage(Page page) {\n        super(page);\n        emailInput    = page.getByLabel(\"Email address\");\n        passwordInput = page.getByLabel(\"Password\");\n        loginButton   = page.getByRole(AriaRole.BUTTON,\n                            new Page.GetByRoleOptions().setName(\"Sign in\"));\n        errorMessage  = page.getByTestId(\"login-error\");\n    }\n\n    @Override protected String getUrl() { return \"\u002Flogin\"; }\n\n    \u002F\u002F Navigation methods return the next Page Object — enables fluent chaining\n    public DashboardPage loginAs(String email, String password) {\n        fill(emailInput, email);\n        fill(passwordInput, password);\n        clickAndWaitForNav(loginButton);\n        return new DashboardPage(page);\n    }\n\n    public LoginPage loginExpectingError(String email, String password) {\n        fill(emailInput, email);\n        fill(passwordInput, password);\n        loginButton.click();\n        errorMessage.waitFor();\n        return this;\n    }\n\n    public String getErrorMessage() { return errorMessage.textContent(); }\n}\n```\n\n---\n\n### Step 5: Write Tests with Allure Annotations\n\n```java\n@ExtendWith(AllureJunit5.class)\nclass LoginTest extends BaseTest {\n\n    private LoginPage loginPage;\n\n    @BeforeEach\n    void openLoginPage() {\n        loginPage = new LoginPage(page());\n        loginPage.navigate();\n    }\n\n    @Test\n    @Severity(SeverityLevel.BLOCKER)\n    @DisplayName(\"Valid credentials redirect to dashboard\")\n    void shouldLoginWithValidCredentials() {\n        User user = TestDataFactory.getDefaultUser();\n        DashboardPage dash = loginPage.loginAs(user.email(), user.password());\n\n        assertThat(page()).hasURL(Pattern.compile(\".*\u002Fdashboard\"));\n        assertThat(dash.getWelcomeBanner()).containsText(\"Welcome, \" + user.firstName());\n    }\n\n    @Test\n    void shouldShowErrorOnInvalidCredentials() {\n        loginPage.loginExpectingError(\"bad@test.com\", \"wrongpass\");\n\n        SoftAssertions softly = new SoftAssertions();\n        softly.assertThat(loginPage.getErrorMessage()).contains(\"Invalid email or password\");\n        softly.assertThat(page()).hasURL(Pattern.compile(\".*\u002Flogin\"));\n        softly.assertAll();\n    }\n\n    @ParameterizedTest\n    @MethodSource(\"provideInvalidCredentials\")\n    void shouldRejectInvalidCredentials(String email, String password, String expectedError) {\n        loginPage.loginExpectingError(email, password);\n        assertThat(loginPage.getErrorMessage()).containsText(expectedError);\n    }\n\n    static Stream\u003CArguments> provideInvalidCredentials() {\n        return Stream.of(\n            Arguments.of(\"\", \"password123\", \"Email is required\"),\n            Arguments.of(\"user@test.com\", \"\", \"Password is required\"),\n            Arguments.of(\"notanemail\", \"pass\", \"Invalid email format\")\n        );\n    }\n}\n```\n\n---\n\n## Examples\n\n### Example 1: API + UI Hybrid Test\n\n```java\n@Test\nvoid shouldDisplayNewlyCreatedOrder() {\n    \u002F\u002F Arrange via API — faster than navigating through UI\n    APIRequestContext api = page().context().request();\n    APIResponse response = api.post(\"\u002Fapi\u002Forders\",\n        RequestOptions.create()\n            .setHeader(\"Authorization\", \"Bearer \" + authToken)\n            .setData(Map.of(\"productId\", \"SKU-001\", \"quantity\", 2)));\n    assertThat(response).isOK();\n\n    String orderId = new JsonParser().parse(response.text())\n        .getAsJsonObject().get(\"id\").getAsString();\n\n    OrdersPage orders = new OrdersPage(page());\n    orders.navigate();\n    assertThat(orders.getOrderRowById(orderId)).isVisible();\n}\n```\n\n### Example 2: Network Mocking\n\n```java\n@Test\nvoid shouldHandleApiFailureGracefully() {\n    page().route(\"**\u002Fapi\u002Fproducts\", route -> route.fulfill(\n        new Route.FulfillOptions()\n            .setStatus(503)\n            .setBody(\"{\\\"error\\\":\\\"Service Unavailable\\\"}\")\n            .setContentType(\"application\u002Fjson\")));\n\n    ProductsPage products = new ProductsPage(page());\n    products.navigate();\n\n    assertThat(products.getErrorBanner())\n        .hasText(\"We're having trouble loading products. Please try again.\");\n}\n```\n\n### Example 3: Parallel Cross-Browser Test\n\n```java\n@ParameterizedTest\n@MethodSource(\"browsers\")\nvoid shouldRenderCheckoutOnAllBrowsers(String browserName) {\n    System.setProperty(\"browser\", browserName);\n    new CheckoutPage(page()).navigate();\n    assertThat(page().locator(\".checkout-form\")).isVisible();\n}\n\nstatic Stream\u003CString> browsers() {\n    return Stream.of(\"chromium\", \"firefox\", \"webkit\");\n}\n```\n\n### Example 4: Parallel Execution Config\n\n```properties\n# src\u002Ftest\u002Fresources\u002Fjunit-platform.properties\njunit.jupiter.execution.parallel.enabled=true\njunit.jupiter.execution.parallel.mode.default=concurrent\njunit.jupiter.execution.parallel.config.strategy=fixed\njunit.jupiter.execution.parallel.config.fixed.parallelism=4\n```\n\n### Example 5: GitHub Actions CI Pipeline\n\n```yaml\n- name: Install Playwright browsers\n  run: mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args=\"install --with-deps\"\n\n- name: Run tests\n  run: mvn test -Dbrowser=${{ matrix.browser }} -Dheadless=true\n\n- name: Upload traces on failure\n  uses: actions\u002Fupload-artifact@v4\n  if: failure()\n  with:\n    name: playwright-traces\n    path: target\u002Ftraces\u002F\n\n- name: Upload Allure results\n  uses: actions\u002Fupload-artifact@v4\n  if: always()\n  with:\n    name: allure-results\n    path: target\u002Fallure-results\u002F\n```\n\n---\n\n## Best Practices\n\n- ✅ Use `ThreadLocal\u003CPage>` for every parallel-safe test suite\n- ✅ Declare all `Locator` fields at the top of the Page Object class\n- ✅ Return the next Page Object from navigation methods (fluent chaining)\n- ✅ Use `assertThat(locator)` — it auto-retries until timeout\n- ✅ Use `getByRole`, `getByLabel`, `getByTestId` as first-choice locators\n- ✅ Start tracing in `@BeforeEach` and stop with a file path in `@AfterEach`\n- ✅ Use `SoftAssertions` when validating multiple fields on a single page\n- ✅ Set up saved auth state (`storageState`) to skip login across test classes\n- ❌ Never use `Thread.sleep()` — replace with `waitFor()` or `waitForResponse()`\n- ❌ Never hardcode base URLs — always use `ConfigReader.getBaseUrl()`\n- ❌ Never create a `Playwright` instance inside a Page Object\n- ❌ Never use XPath for dynamic or frequently changing elements\n\n---\n\n## Common Pitfalls\n\n- **Problem:** Tests fail randomly in parallel mode\n  **Solution:** Ensure every test creates its own `Playwright → Browser → BrowserContext → Page` chain via `ThreadLocal`. Never share a `Page` across threads.\n\n- **Problem:** `assertThat(locator).isVisible()` times out even when the element appears\n  **Solution:** Increase timeout with `.setTimeout(10_000)` or raise `context.setDefaultTimeout()` in `BaseTest`.\n\n- **Problem:** `Thread.sleep(2000)` was added but tests are still flaky\n  **Solution:** Replace with `page.waitForResponse(\"**\u002Fapi\u002Fendpoint\", () -> action())` or `assertThat(locator).hasText(\"Done\")` which polls automatically.\n\n- **Problem:** Playwright trace zip is empty or missing\n  **Solution:** Ensure `tracing().start()` is called before test actions and `tracing().stop()` is in `@AfterEach` — not `@AfterAll`.\n\n- **Problem:** Allure report is blank or missing steps\n  **Solution:** Add the AspectJ agent to `maven-surefire-plugin` `\u003CargLine>` in `pom.xml` — see `references\u002Fconfig.md` for the exact snippet.\n\n- **Problem:** `storageState` auth file is stale and tests redirect to login\n  **Solution:** Re-run `AuthSetup` to regenerate `target\u002Fauth\u002Fuser-state.json` before the suite, or add a `@BeforeAll` that conditionally refreshes it.\n\n---\n\n## Related Skills\n\n- `@rest-assured-java` — Use for pure API test suites without any UI interaction\n- `@selenium-java` — Legacy alternative; prefer Playwright for all new projects\n- `@allure-reporting` — Deep-dive into Allure annotations, categories, and history trends\n- `@testcontainers-java` — Use alongside this skill when tests need a live database or service\n- `@github-actions-ci` — For building complete multi-browser matrix CI pipelines\n",{"name":5,"metadata":64,"description":7},{"risk":58,"tags":65,"tools":66,"author":69,"source":44,"category":37,"date_added":70},[32,33,43,42,41,40,39],[67,68,57],"claude","cursor","amalsam18","2025-03-08","main","2b749c82b5d11fac39d9a6e021ce3f5b8a541bd1","cli-tool\u002Fcomponents\u002Fskills\u002Fdevelopment\u002Fplaywright-java",3931,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates","https:\u002F\u002Faitmpl.com","https:\u002F\u002Fgithub.com\u002Fdavila7","https:\u002F\u002Fdanielavila.me","Building AI dev tools with LLMs","2026-11-14 06:14:46",{"source":8,"skillName":5,"commands":82,"prompt":92,"zipAvailable":93},[83,86,89],{"tool":84,"command":85},"npx","npx skills add davila7\u002Fclaude-code-templates --skill playwright-java",{"tool":87,"command":88},"bunx","bunx skills add davila7\u002Fclaude-code-templates --skill playwright-java",{"tool":90,"command":91},"pnpm","pnpm dlx skills add davila7\u002Fclaude-code-templates --skill playwright-java","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fdevelopment\u002Fplaywright-java\u002FSKILL.md",true,[95,101,107,111,115,119],{"path":96,"resourceType":97,"resourceTypeDesc":98,"sizeBytes":99,"sourceHtmlUrl":100},"assertions.md","REFERENCE","参考文档",4226,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fdevelopment\u002Fplaywright-java\u002Fassertions.md",{"path":102,"resourceType":103,"resourceTypeDesc":104,"sizeBytes":105,"sourceHtmlUrl":106},"BasePage.java","SCRIPT","脚本",4830,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fdevelopment\u002Fplaywright-java\u002FBasePage.java",{"path":108,"resourceType":103,"resourceTypeDesc":104,"sizeBytes":109,"sourceHtmlUrl":110},"BaseTest.java",4526,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fdevelopment\u002Fplaywright-java\u002FBaseTest.java",{"path":112,"resourceType":97,"resourceTypeDesc":98,"sizeBytes":113,"sourceHtmlUrl":114},"config.md",6651,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fdevelopment\u002Fplaywright-java\u002Fconfig.md",{"path":116,"resourceType":97,"resourceTypeDesc":98,"sizeBytes":117,"sourceHtmlUrl":118},"fixtures.md",7755,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fdevelopment\u002Fplaywright-java\u002Ffixtures.md",{"path":120,"resourceType":97,"resourceTypeDesc":98,"sizeBytes":121,"sourceHtmlUrl":122},"page-objects.md",6104,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fdevelopment\u002Fplaywright-java\u002Fpage-objects.md",[124,152,179,210,245,265],{"skillNo":125,"name":126,"nameZh":6,"description":127,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":128,"categories":129,"keywords":131,"publishedAt":59},"01M70NHBTQ8BV0A2SCAZXEPHCX","wealthville-pool-scoring","Score DeFi liquidity pools before providing liquidity. Returns a 0-100 pool score and an Enter\u002FHold\u002FExit\u002FReduce\u002FAvoid verdict with calibrated confidence for ~68,800 Solana pools and 575 EVM pools, plus a public miss-inclusive track record. Use when asked whether a pool is worth LPing into, which pools look best right now, or how accurate the scores have actually been.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fweb-data\u002Fwealthville-pool-scoring\u002FSKILL.md",[130],{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},[132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151],"scoring","pool","wealthville pool scoring","liquidity","which","for","exit","now","use","when","reduce","with","record","track","verdict","evm","solana","how","public","look",{"skillNo":153,"name":154,"nameZh":6,"description":155,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":156,"categories":157,"keywords":159,"publishedAt":59},"01M70MB6VR8ERJ4EM8D5KHBMEV","technical-debt-auditor","Scans a codebase and produces a quantified technical debt report with a prioritized remediation plan. Analyzes dead code, TODO\u002FFIXME\u002FHACK markers, dependency staleness, complexity hotspots, code duplication signals, test coverage gaps, unused exports, and outdated patterns. Use this skill when the user asks to audit their codebase for tech debt, wants a health check of their code quality, says things like \"where should I focus refactoring\", \"find code smells\", \"audit my codebase\", \"what technical debt do we have\", \"prioritize cleanup work\", or asks about code quality metrics. Also trigger when the user mentions \"code rot\", \"legacy cleanup\", \"refactoring priorities\", or wants to understand the overall health of a project before a major effort. Trigger even if the user doesn't say \"technical debt\" explicitly — any request to systematically assess code quality and identify improvement priorities belongs here.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fdevelopment\u002Ftechnical-debt-auditor\u002FSKILL.md",[158],{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},[160,161,162,163,164,165,166,167,168,169,170,141,171,172,173,174,175,176,177,178],"technical debt","debt","technical","technical debt auditor","auditor","coverage","complexity","markers","project","cleanup","unused","code","todo","work","plan","focus","signals","audit","dependency",{"skillNo":180,"name":181,"nameZh":6,"description":182,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":183,"categories":184,"keywords":192,"publishedAt":59},"01M70KPYH9QNHCNME5GJQGE22K","readonly-sql-guard","Make an agent's database access provably read-only. Use when an agent runs caller-supplied SQL against a production\u002FERP\u002Fanalytics database (a \"query\" MCP tool, text-to-SQL, an admin console), or when reviewing DB-access code for write\u002FDDL\u002Fside-effect\u002Ftransaction-escape risks. Checks what a statement CALLS, not just its shape.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fdatabase\u002Freadonly-sql-guard\u002FSKILL.md",[185,188,189],{"categoryNo":186,"categoryName":187,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000010","后端与接口",{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":190,"categoryName":191,"taxonomyType":29,"taxonomyTypeDesc":30},"01JBSEEDCAT000000000000033","数据分析师",[193,194,195,196,197,198,199,137,200,201,202,203,204,205,206,140,207,208,141,209],"readonly","guard","sql guard","sql","readonly sql guard","erp","effect","read-only","db","just","tool","calls","only","MCP","access","database","query",{"skillNo":211,"name":212,"nameZh":6,"description":213,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":214,"licenseFileUrl":215,"sourceHtmlUrl":216,"categories":217,"keywords":221,"publishedAt":59},"01M6AFY6F7CC2BBZP1QD6VTNVC","web-artifacts-builder","Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn\u002Fui). Use for complex artifacts requiring state management, routing, or shadcn\u002Fui components - not for simple single-file HTML\u002FJSX artifacts.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Futilities\u002Fweb-artifacts-builder\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Futilities\u002Fweb-artifacts-builder\u002FSKILL.md",[218],{"categoryNo":219,"categoryName":220,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000009","前端开发",[222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,137,244],"artifacts builder","web","web artifacts builder","artifacts","builder","state","routing","state management","component","css","frontend","ui","Tools","file","components","shadcn","react","Tailwind","suite","jsx","html","single-file","ui components",{"skillNo":246,"name":247,"nameZh":6,"description":248,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":214,"licenseFileUrl":249,"sourceHtmlUrl":250,"categories":251,"keywords":254,"publishedAt":59},"01M6AFWF33SFV9Z3SF4PEEE4BF","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fsecurity\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fsecurity\u002Fwebapp-testing\u002FSKILL.md",[252,253],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":219,"categoryName":220,"taxonomyType":21,"taxonomyTypeDesc":22},[255,48,256,257,32,223,258,232,233,259,260,261,262,137,263,143,264],"webapp testing","webapp","browser","applications","debugging","toolkit","logs","screenshots","local","behavior",{"skillNo":266,"name":267,"nameZh":6,"description":268,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":214,"licenseFileUrl":269,"sourceHtmlUrl":270,"categories":271,"keywords":279,"publishedAt":59},"01M6AF67Q67JJJ5V51JR2P52KA","discernment-nudge","After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals, or emails, estimates or projections, analysis or interpretation of data, factual claims they may rely on, or a multi-step argument — invoke this skill BEFORE finalizing your reply and then, if it applies, append 2-3 short follow-up questions, each tied to something specific in what you just produced, that help the user check key facts, probe the reasoning or assumptions, and notice missing context. Do this at most once per conversation. Skip it when the user asked a trivial how-to or simple lookup, wants a purely educational explanation, asked you only to format, convert, or assemble a file from content they provided, is writing code they will run, is doing creative writing or casual chat, or already asked you to double-check, cite, or review — the skill file explains these boundaries and the exact output format.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fproductivity\u002Fdiscernment-nudge\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fproductivity\u002Fdiscernment-nudge\u002FSKILL.md",[272,275,276],{"categoryNo":273,"categoryName":274,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000018","写作与文案",{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":277,"categoryName":278,"taxonomyType":29,"taxonomyTypeDesc":30},"01JBSEEDCAT000000000000036","内容创作者",[280,281,282,283,284,285,286,287,225,288,235,171,289,290,291,292,293,205,294,141,295,296,297,298,299,149,300],"discernment nudge","nudge","interpretation","help","run","reasoning","data","writing","lookup","content","review","conversation","short","up","invoke","you","analysis","claims","argument","assemble","recommendations"]