playwright-java

Scaffold and write Playwright end-to-end tests in Java using Page Object Model and JUnit 5.

30.5k|3.5k|Updated Jul 4, 2025
One-click install
npx skills add https://github.com/davila7/claude-code-templates --skill playwright-java
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: playwright-java
Source: https://github.com/davila7/claude-code-templates/tree/main/cli-tool/components/skills/development/playwright-java
Command: npx skills add https://github.com/davila7/claude-code-templates --skill playwright-java

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Writing maintainable browser automation tests in Java requires consistent architecture, thread-safe parallel execution, and reliable waits. This Skill provides the patterns, base classes, and configuration needed to build Playwright Java test suites without flaky tests or ad-hoc structure.

Core Features & Use Cases

  • Project Scaffolding: Generates a complete Maven project layout with pom.xml, ConfigReader, BaseTest, and BasePage following the Page Object Model.
  • Thread-Safe Parallel Execution: Implements ThreadLocal-based Playwright/Browser/Context/Page lifecycle with JUnit 5 parallel configuration.
  • Allure Reporting & Tracing: Integrates Allure annotations, screenshot attachments, and Playwright trace/video capture for debugging failures.
  • Use Case: A QA engineer needs to automate login and checkout flows across Chromium, Firefox, and WebKit in CI. The Skill produces the page objects, parameterized cross-browser tests, GitHub Actions pipeline, and Allure reporting setup.

Quick Start

Ask the AI to scaffold a new Playwright Java test project with a LoginPage page object and a JUnit 5 test class using the Page Object Model.

Frequently Asked Questions about playwright-java

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up Playwright with Java and JUnit 5?

Add the com.microsoft.playwright dependency and JUnit 5 to your Maven pom.xml, then create a BaseTest class that manages Playwright, Browser, BrowserContext, and Page instances in @BeforeEach and @AfterEach hooks. Run mvn exec:java with the Playwright CLI to install browsers.

How do I run Playwright Java tests in parallel?

Enable parallel execution in junit-platform.properties with junit.jupiter.execution.parallel.enabled=true and concurrent mode. Each test must create its own Playwright-to-Page chain via ThreadLocal variables, since sharing a Page across threads causes random failures.

Playwright vs Selenium for Java test automation?

Playwright is preferred for new projects because its locator assertions auto-retry until timeout, eliminating most explicit waits. It also provides built-in tracing, video recording, network mocking, and a single API across Chromium, Firefox, and WebKit.

Why are my Playwright tests flaky in parallel mode?

Flakiness in parallel mode usually comes from sharing a Page or BrowserContext across threads. Store Playwright, Browser, BrowserContext, and Page in ThreadLocal fields so each test thread gets an isolated browser instance.

How do I fix Thread.sleep in Playwright Java tests?

Replace Thread.sleep with auto-retrying assertions like assertThat(locator).hasText(), or use page.waitForResponse() to wait for specific API calls. Playwright assertions poll automatically until the condition is met or the timeout expires.

Why is my Allure report blank with Playwright Java?

A blank Allure report usually means the AspectJ weaver agent is missing from the maven-surefire-plugin argLine configuration. Add the -javaagent entry pointing to aspectjweaver in your local Maven repository as shown in the pom.xml configuration.