Fixture for CardList component.
test('renders experience card data', async ({ cardList }) => { await expect(cardList.getListItems(), 'correct number of card items').toHaveCount(EXPERIENCE_ITEMS.length); for (const [index, item] of EXPERIENCE_ITEMS.entries()) { const cardItem = new CardListItem(cardList.getWrapper(), cardList.getListItemByIndex(index)); await cardItem.expectTitleText(item.title); await cardItem.expectSubtitleText(item.subtitle); } }); Copy
test('renders experience card data', async ({ cardList }) => { await expect(cardList.getListItems(), 'correct number of card items').toHaveCount(EXPERIENCE_ITEMS.length); for (const [index, item] of EXPERIENCE_ITEMS.entries()) { const cardItem = new CardListItem(cardList.getWrapper(), cardList.getListItemByIndex(index)); await cardItem.expectTitleText(item.title); await cardItem.expectSubtitleText(item.subtitle); } });
Provides method helpers for locating child CardListItem elements.
export default class CardList implements ListComponent { /** @public Component wrapper. */ private readonly cardList: Locator; /** * @param page - Playwright page object. */ public constructor(private readonly page: Page) { this.cardList = page.getByRole('list', { name: 'card list' }); } /** Getter method. @returns {@link cardList}. */ public getWrapper(): Locator { return this.cardList; } /** Testing helper method. */ public async rendersCorrectly(): Promise<boolean> { await expect(this.getWrapper(), 'card list should be visible').toBeVisible(); return true; } /** Get all list item locators. */ getListItems(): Locator { return this.cardList.getByRole('listitem'); } /** Get a specific card list item by index. */ getListItemByIndex(index: number): Locator { return this.getListItems().nth(index); } /** Get the number of card list items. */ async getListLength(): Promise<number> { return await this.getListItems().count(); }} Copy
export default class CardList implements ListComponent { /** @public Component wrapper. */ private readonly cardList: Locator; /** * @param page - Playwright page object. */ public constructor(private readonly page: Page) { this.cardList = page.getByRole('list', { name: 'card list' }); } /** Getter method. @returns {@link cardList}. */ public getWrapper(): Locator { return this.cardList; } /** Testing helper method. */ public async rendersCorrectly(): Promise<boolean> { await expect(this.getWrapper(), 'card list should be visible').toBeVisible(); return true; } /** Get all list item locators. */ getListItems(): Locator { return this.cardList.getByRole('listitem'); } /** Get a specific card list item by index. */ getListItemByIndex(index: number): Locator { return this.getListItems().nth(index); } /** Get the number of card list items. */ async getListLength(): Promise<number> { return await this.getListItems().count(); }}
Playwright page object.
Readonly
Component wrapper.
Private
Getter method.
cardList.
Testing helper method.
Get all list item locators.
Get a specific card list item by index.
Get the number of card list items.
Fixture for CardList component.
Example
Remarks
Provides method helpers for locating child CardListItem elements.
Source