Using playwright for e2e is my application, I’m struggling with that personal doubt:
So, I’ve create that fixture in order to provide a custom locator – getComoboxByName
for now – for my application, in order to reduce the duplication I just put it here.
import {test as baseTest, expect as baseExpect, Locator, Page } from '@playwright/test';
type CustomLocators = {
getComboboxByName: (name: string) => Locator;
}
type CustomFixtures = {
page: Page & CustomLocators;
};
const test = baseTest.extend<CustomFixtures>({
page: async ({ page }, use) => {
page.getComboboxByName = (name: string) => {
return page
.locator('.w-attr-container')
.filter({ has: page.getByText(name, { exact: true }) })
.locator('my-listbox') as Locator;
};
await use(page);
},
});
export { baseExpect as expect, test };
In my POM, shall I use the CustomFixtures
type defined in the fixture or just use the Page
type exported by Playwright API?
I want to use the getComboboxByName
import { type Page } from '@playwright/test';
export class BedRequestsTab {
#page: Page;
constructor(page: Page) { // Depend on CustomFixtures instead of Page??? - Will that couple be nocive to my tests?
this.#page = page;
}
async doFilter() {
await this.#page.locator('my-filter')
.getByRole('button', { name: 'Filter', exact: true })
.click();
}
}
New contributor
lmanske is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.