Index of every page on this site: llms.txt
All skills
davila7 avatar

/playwright-java

@c1bc5c1
Run it yourself

Scaffold, write, debug, and enhance enterprise-grade Playwright E2E tests in Java using Page Object Model, JUnit 5, Allure reporting, and parallel execution.

Use this Skill: https://skilld.dev/gh/davila7/claude-code-templates/playwright-java

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

assertions.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Playwright Java – Assertions Reference

Import Statement

import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
import org.assertj.core.api.SoftAssertions;

Locator Assertions (Auto-Retry)

Playwright's assertThat(locator) polls automatically (up to defaultTimeout). Always prefer these over locator.isVisible() + assertTrue.

// Visibility
assertThat(locator).isVisible();
assertThat(locator).isHidden();

// Enabled / Disabled
assertThat(locator).isEnabled();
assertThat(locator).isDisabled();

// Text content (exact or partial)
assertThat(locator).hasText("Exact text");
assertThat(locator).containsText("partial");
assertThat(locator).hasText(Pattern.compile("Order #\\d+"));

// Multiple elements
assertThat(locator).hasCount(5);
assertThat(locator).hasText(new String[]{"Item A", "Item B", "Item C"});

// Attribute
assertThat(locator).hasAttribute("aria-expanded", "true");
assertThat(locator).hasAttribute("href", Pattern.compile(".*\\/dashboard"));

// CSS class
assertThat(locator).hasClass("active");
assertThat(locator).hasClass(Pattern.compile("btn-.*"));

// Input value
assertThat(locator).hasValue("expected input value");
assertThat(locator).hasValue(Pattern.compile("\\d{4}-\\d{2}-\\d{2}")); // date pattern

// Checked state (checkbox/radio)
assertThat(locator).isChecked();
assertThat(locator).not().isChecked();

// Focused
assertThat(locator).isFocused();

// Editable
assertThat(locator).isEditable();

Page Assertions

// URL
assertThat(page).hasURL("https://example.com/dashboard");
assertThat(page).hasURL(Pattern.compile(".*/dashboard"));

// Title
assertThat(page).hasTitle("Dashboard – MyApp");
assertThat(page).hasTitle(Pattern.compile(".*Dashboard.*"));

Negation

// Add .not() for inverse
assertThat(locator).not().isVisible();
assertThat(locator).not().hasText("Error");
assertThat(page).not().hasURL(Pattern.compile(".*/login"));

Custom Timeout on Assertion

assertThat(locator)
    .hasText("Loaded", new LocatorAssertions.HasTextOptions().setTimeout(10_000));

Soft Assertions (AssertJ)

Collect all failures before reporting — critical for form validation tests:

@Test
void shouldDisplayAllProfileFields() {
    ProfilePage profile = new ProfilePage(page());
    profile.navigate();

    SoftAssertions soft = new SoftAssertions();
    soft.assertThat(profile.getNameField().inputValue()).isEqualTo("Amal");
    soft.assertThat(profile.getEmailField().inputValue()).contains("@");
    soft.assertThat(profile.getRoleLabel().textContent()).isEqualTo("Engineer");
    soft.assertAll(); // throws at end with ALL failures listed
}

Response Assertions

APIResponse response = page().context().request().get("/api/health");
assertThat(response).isOK();                         // status 200-299
assertThat(response).hasStatus(201);
assertThat(response).hasHeader("content-type", "application/json");
assertThat(response).hasJSON("{\"status\":\"UP\"}"); // exact JSON match

Screenshot Comparison (Visual Testing)

// Full page screenshot
assertThat(page).hasScreenshot(new PageAssertions.HasScreenshotOptions()
    .setName("dashboard.png")
    .setFullPage(true)
    .setThreshold(0.2));

// Locator screenshot
assertThat(page.locator(".chart-container"))
    .hasScreenshot(new LocatorAssertions.HasScreenshotOptions()
        .setName("revenue-chart.png"));

Update golden files: run with PLAYWRIGHT_UPDATE_SNAPSHOTS=true mvn test


Common Anti-Patterns to Avoid

// ❌ WRONG — no auto-retry, brittle
assertTrue(page.locator(".spinner").isHidden());
Thread.sleep(2000);

// ✅ CORRECT — auto-retry until timeout
assertThat(page.locator(".spinner")).isHidden();

// ❌ WRONG — getText() can return stale value
String text = locator.textContent();
assertEquals("Done", text);

// ✅ CORRECT — assertion retries until text matches
assertThat(locator).hasText("Done");

// ❌ WRONG — count check without waiting
assertEquals(5, page.locator("li").count());

// ✅ CORRECT — waits until count stabilizes
assertThat(page.locator("li")).hasCount(5);

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts1mo3 checks · Risk SAFE
  • Gen Agent Trust Hub1mo

    This skill provides a standard, high-quality template for enterprise Playwright Java automation. It follows industry best practices for the Page Object Model, thread-safe parallel execution, and reporting. All external components, including browser drivers and Maven dependencies, are sourced from official and well-known providers.

  • Socket1mo

    No alerts

  • Snyk1mo

    Risk: LOW · No issues

Signed by skilld at c1bc5c1. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
Other metadata
metadata
{
  "category": "test-automation",
  "risk": "safe",
  "source": "community",
  "date_added": "2025-03-08",
  "author": "amalsam18",
  "tags": [
    "playwright",
    "java",
    "e2e-testing",
    "junit5",
    "page-object-model",
    "allure",
    "selenium-alternative"
  ],
  "tools": [
    "claude",
    "cursor",
    "antigravity"
  ]
}

README badge

README badge for davila7/claude-code-templates/playwright-java