POMWright is a TypeScript-based framework that implements the Page Object Model Design Pattern, designed specifically to augment Playwright's testing capabilities.
POMWright provides a way of abstracting the implementation details of a web page and encapsulating them into a reusable page object. This approach makes the tests easier to read, write and maintain, and helps reduce duplicated code by breaking down the code into smaller, reusable components, making the code more maintainable and organized.
Simply extend a class with BasePage to create a Page Object Class (POC).
Define different base URLs by extending an abstract class with BasePage per domain and have your POCs for each domain extend the abstract classes.
Seamlessly integrate custom Playwright Fixtures with your POMWright POCs.
Define comprehensive locators for each POC and share common locators between them.
Efficiently manage and chain locators through LocatorSchemaPaths.
Modify single or multiple locators within a chained locator dynamically during tests.
Ensure that original LocatorSchemas remain immutable and reusable across tests.
Gain insights with detailed logs for nested locators, integrated with Playwright's HTML report. Or use the Log fixture throughout your own POCs and tests to easily attach them to the HTML report based on log levels.
Enhance your tests with advanced sessionStorage handling capabilities.
Ensure you have Node.js installed, then run:
npm install pomwright --save-dev
or
pnpm i -D pomwright
Explore POMWright in action by diving into the example project located in the "example" folder. Follow these steps to get started:
Navigate to the "example" folder and install the necessary dependencies:
pnpm install
Install or update Playwright browsers:
pnpm playwright install --with-deps
Execute tests across chromium, firefox, and webkit:
pnpm playwright test
Control parallel test execution. By default, up to 4 tests run in parallel. Modify this setting as needed:
pnpm playwright test --workers 2 # Set the number of parallel workers
After the tests complete, a Playwright HTML report is available in ./example/playwright-report. Open the index.html file in your browser to view the results.
Dive into using POMWright with these examples:
import { Page, TestInfo } from "@playwright/test";
import { BasePage, PlaywrightReportLogger, GetByMethod } from "pomwright";
type LocatorSchemaPath =
| "content"
| "content.heading"
| "content.region.details"
| "content.region.details.button.edit";
export default class Profile extends BasePage<LocatorSchemaPath> {
constructor(page: Page, testInfo: TestInfo, pwrl: PlaywrightReportLogger) {
super(page, testInfo, "https://someDomain.com", "/profile", Profile.name, pwrl);
}
protected initLocatorSchemas() {
this.locators.addSchema("content", {
locator: ".main-content",
locatorMethod: GetByMethod.locator
});
this.locators.addSchema("content.heading", {
role: "heading",
roleOptions: {
name: "Your Profile"
},
locatorMethod: GetByMethod.role
});
this.locators.addSchema("content.region.details", {
role: "region",
roleOptions: {
name: "Profile Details"
},
locatorMethod: GetByMethod.role
});
this.locators.addSchema("content.region.details.button.edit", {
role: "button",
roleOptions: {
name: "Edit"
},
locatorMethod: GetByMethod.role
});
}
// add your helper methods here...
}
import { test as base } from "pomwright";
import Profile from "...";
type fixtures = {
profile: Profile;
}
export const test = base.extend<fixtures>({
profile: async ({ page, log }, use, testInfo) => {
const profile = new Profile(page, testInfo, log);
await use(profile);
}
});
import { test } from ".../fixtures";
test("click edit button with a single locator", async ({ profile }) => {
// perform setup/navigation...
await profile.page.waitForURL(profile.fullUrl);
/**
* returns the locator resolving to the full locatorSchemaPath
*/
const editBtn = await profile.getLocator("content.region.details.button.edit");
await editBtn.click();
});
import { test } from ".../fixtures";
test("click edit button with a nested locator", async ({ profile }) => {
// perform setup/navigation...
await profile.page.waitForURL(profile.fullUrl);
/**
* returns a nested/chained locator consisting of the 3 locators:
* content,
* content.region.details
* content.region.details.button.edit
*/
const editBtn = await profile.getNestedLocator("content.region.details.button.edit");
await editBtn.click();
});
import { test } from ".../fixtures";
test("specify index for nested locator(s)", async ({ profile }) => {
// perform setup/navigation...
await profile.page.waitForURL(profile.fullUrl);
/**
* returns a nested/chained locator consisting of the 3 locators:
* content
* content.region.details with .first()
* content.region.details.button.edit with .nth(1)
*/
const editBtn = await profile.getNestedLocator("content.region.details.button.edit", {
3: 0, 4: 1
});
await editBtn.click();
});
import { test } from ".../fixtures";
test("update a locator before use", async ({ profile }) => {
// perform setup/navigation...
await profile.page.waitForURL(profile.fullUrl);
/**
* returns a nested/chained locator consisting of the 3 locators:
* content,
* content.region.details
* content.region.details.button.edit (updated)
*/
const editBtn = await profile.getLocatorSchema("content.region.details.button.edit")
.update({ roleOptions: { name: "Edit details" }})
.getNestedLocator();
await editBtn.click();
});
import { test } from ".../fixtures";
test("update a nested locator before use", async ({ profile }) => {
// perform setup/navigation...
await profile.page.waitForURL(profile.fullUrl);
/**
* returns a nested/chained locator consisting of the 3 locators:
* content,
* content.region.details (updated)
* content.region.details.button.edit
*/
const editBtn = await profile.getLocatorSchema("content.region.details.button.edit")
.updates({
2: { // content.region.details
locator: ".profile-details",
locatorMethod: GetByMethod.locator
}
})
.getNestedLocator();
await editBtn.click();
});
import { test } from ".../fixtures";
test("make multiple versions of a locator", async ({ profile }) => {
// perform setup/navigation...
await profile.page.waitForURL(profile.fullUrl);
const editBtnSchema = profile.getLocatorSchema("content.region.details.button.edit");
const editBtn = await editBtnSchema.getLocator();
await editBtn.click();
editBtnSchema.update({ roleOptions: { name: "Edit details" }});
const editBtnUpdated = await editBtnSchema.getNestedLocator();
await editBtnUpdated.click();
/**
* Calling profile.getLocatorSchema("content.region.details.button.edit") again
* will return a new deepCopy of the original LocatorSchema
*/
});
If you encounter any issues or have questions, please check our issues page or reach out to us directly.
Pull Requests are welcome!
POMWright is open-source software licensed under the Apache-2.0 license