import { expect, Page } from "@playwright/test"; import HeaderPage from "./headerPage"; export default class BooksPage { header = new HeaderPage(); constructor(private page: Page) { } static Elements = { get_Categories: "app-book-filter a", get_Title: "div.card-title", get_Price: "div.card-title +p", btn_AddToCart: "//span[contains(text(),'Add to Cart')]/parent::button", get_BookCard: "mat-card", get_SnackBar: "//simple-snack-bar/span[1]", txt_Search: "input[type='search']", lst_BookOption: "mat-option[role='option'] span" } // Static method to return Elements static getObjects() { return this.Elements; } async verifyAllCategories(categories: string[]) { const bookCategories = this.page.locator(BooksPage.Elements.get_Categories); await expect(bookCategories).toHaveText(categories); } async addBookToCart(book: string) { await this.header.enterBookName(book); await expect(this.page.locator(BooksPage.Elements.get_Title)) .toHaveText(book, { ignoreCase: true }); this.page.click(BooksPage.Elements.btn_AddToCart); const toast = this.page.locator(BooksPage.Elements.get_SnackBar); await expect(toast).toBeVisible(); await expect(toast).toHaveText("One Item added to cart"); } }