davila7/claude-code-templates / cli-tool/components/skills/development/playwright-java
playwright-java
VerifiedScaffold, write, debug, and enhance enterprise-grade Playwright E2E tests in Java using Page Object Model, JUnit 5, Allure reporting, and parallel execution.
| File | Kind | Size |
|---|---|---|
| BasePage.java | other | 4.7 KB |
| BaseTest.java | other | 4.4 KB |
| SKILL.md | skill md | 13.4 KB |
| assertions.md | markdown | 4.1 KB |
| config.md | markdown | 6.5 KB |
| fixtures.md | markdown | 7.6 KB |
| page-objects.md | markdown | 6.0 KB |
BasePage.java
View on GitHubpackage com.company.tests.base;
import com.company.tests.config.ConfigReader;
import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.options.AriaRole;
import com.microsoft.playwright.options.LoadState;
import com.microsoft.playwright.options.WaitForSelectorState;
import io.qameta.allure.Step;
/**
* BasePage – foundation for all Page Object classes.
*
* Responsibilities:
* - Inject Page via constructor (never create Playwright here)
* - Provide common action helpers with Allure @Step reporting
* - Enforce strict locator strategy (role/label/testid first)
* - Declare getUrl() so pages can self-navigate
*/
public abstract class BasePage {
protected final Page page;
public BasePage(Page page) {
this.page = page;
}
// ─── Navigation ────────────────────────────────────────────────────────────
/** Navigate to this page's URL relative to baseUrl */
@Step("Navigate to {this.getUrl()}")
public <T extends BasePage> T navigate() {
page.navigate(ConfigReader.getBaseUrl() + getUrl());
waitForPageLoad();
//noinspection unchecked
return (T) this;
}
/** Each page declares its relative URL path, e.g. "/login" */
protected abstract String getUrl();
@Step("Wait for network idle")
protected void waitForPageLoad() {
page.waitForLoadState(LoadState.NETWORKIDLE);
}
// ─── Locator Shortcuts ──────────────────────────────────────────────────────
protected Locator byRole(AriaRole role, String name) {
return page.getByRole(role, new Page.GetByRoleOptions().setName(name));
}
protected Locator byLabel(String label) {
return page.getByLabel(label);
}
protected Locator byTestId(String testId) {
return page.getByTestId(testId);
}
protected Locator byText(String text) {
return page.getByText(text);
}
protected Locator byPlaceholder(String placeholder) {
return page.getByPlaceholder(placeholder);
}
// ─── Action Helpers ─────────────────────────────────────────────────────────
@Step("Fill '{locatorDesc}' with value")
protected void fill(Locator locator, String value) {
locator.waitFor(new Locator.WaitForOptions()
.setState(WaitForSelectorState.VISIBLE)
.setTimeout(10_000));
locator.clear();
locator.fill(value);
}
@Step("Click and wait for navigation")
protected void clickAndWaitForNav(Locator locator) {
page.waitForNavigation(() -> locator.click());
}
@Step("Click '{locatorDesc}'")
protected void click(Locator locator) {
locator.waitFor(new Locator.WaitForOptions()
.setState(WaitForSelectorState.VISIBLE)
.setTimeout(10_000));
locator.click();
}
@Step("Wait for element to be visible")
protected void waitForVisible(Locator locator, int timeoutMs) {
locator.waitFor(new Locator.WaitForOptions()
.setState(WaitForSelectorState.VISIBLE)
.setTimeout(timeoutMs));
}
@Step("Wait for element to be hidden")
protected void waitForHidden(Locator locator) {
locator.waitFor(new Locator.WaitForOptions()
.setState(WaitForSelectorState.HIDDEN)
.setTimeout(15_000));
}
@Step("Select option '{value}' from dropdown")
protected void selectOption(Locator locator, String value) {
locator.selectOption(value);
}
@Step("Check checkbox")
protected void check(Locator locator) {
if (!locator.isChecked()) locator.check();
}
@Step("Uncheck checkbox")
protected void uncheck(Locator locator) {
if (locator.isChecked()) locator.uncheck();
}
// ─── Scroll ─────────────────────────────────────────────────────────────────
protected void scrollIntoView(Locator locator) {
locator.scrollIntoViewIfNeeded();
}
// ─── Utility ────────────────────────────────────────────────────────────────
public String getCurrentUrl() {
return page.url();
}
public String getPageTitle() {
return page.title();
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |