-
Notifications
You must be signed in to change notification settings - Fork 41
/
ProductPage.ts
45 lines (41 loc) · 1.5 KB
/
ProductPage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { expect, Locator, Page } from "@playwright/test";
export class ProductPage {
readonly page: Page;
readonly addToCartButton: Locator;
readonly variant: Locator;
readonly variantText: Locator;
readonly productOption: Locator;
readonly miniCartLink: Locator;
readonly productRemove: Locator;
constructor(page: Page) {
this.page = page;
this.addToCartButton = page.getByTestId("add-to-cart-button");
this.variant = page.getByTestId("product-variant");
this.variantText = page.getByTestId("product-variant-text");
this.productOption = page.getByTestId("cart-product-options");
this.miniCartLink = page.getByTestId("cart-button");
this.productRemove = page.getByTestId("product-remove-button");
}
async addToCart() {
await expect(this.page.getByTestId("add-to-cart-button")).toBeVisible();
await this.addToCartButton.waitFor();
await this.addToCartButton.click();
}
async addVariantToCart() {
for (const variant of await this.page
.getByTestId("product-variant-text")
.all())
await variant.click(), await this.page.waitForLoadState("load");
await this.addToCartButton.waitFor();
await this.addToCartButton.click();
await this.miniCartLink.click();
expect(this.variantText.textContent).toEqual(
this.productOption.textContent
);
await Promise.all([
await this.page.waitForLoadState("load"),
await this.productRemove.click(),
]);
await this.page.getByTestId("cart-close-button").click();
}
}