-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckoutChallenge.spec.ts
More file actions
47 lines (44 loc) · 1.91 KB
/
Copy pathcheckoutChallenge.spec.ts
File metadata and controls
47 lines (44 loc) · 1.91 KB
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
46
47
import { test, expect } from "@playwright/test";
import { randomState } from "@helpers/states";
test.describe("Checkout challenge", async () => {
test.use({ storageState: ".auth/customer01.json" });
test.beforeEach(async ({ page }) => {
await page.goto("/");
});
test("buy now pay later", async ({ page, headless, isMobile }) => {
await page.getByText("Claw Hammer with Shock Reduction Grip").click();
await page.getByTestId("add-to-cart").click();
await expect(page.getByTestId("cart-quantity")).toHaveText("1");
if (isMobile === true) {
await page.getByLabel("Toggle navigation").click();
}
await page.getByTestId("nav-cart").click();
await page.getByTestId("proceed-1").click();
await page.getByTestId("proceed-2").click();
await expect(
page.locator(".step-indicator").filter({ hasText: "2" })
).toHaveCSS("background-color", "rgb(51, 153, 51)");
await page.getByTestId("street").fill("123 Testing Way");
await page.getByTestId("city").fill("Sacramento");
await page.getByTestId("state").fill(randomState());
await page.getByTestId("country").fill("USA");
await page.getByTestId("postal_code").fill("98765");
await page.getByTestId("proceed-3").click();
await expect(page.getByTestId("finish")).toBeDisabled();
await page.getByTestId("payment-method").selectOption("Buy Now Pay Later");
await page
.getByTestId("monthly_installments")
.selectOption("6 Monthly Installments");
await page.getByTestId("finish").click();
await expect(page.locator(".help-block")).toHaveText(
"Payment was successful"
);
headless
? await test.step("visual test", async () => {
await expect(page).toHaveScreenshot("checkout.png", {
mask: [page.getByTitle("Practice Software Testing - Toolshop")],
});
})
: console.log("Running in Headed mode, no screenshot comparison");
});
});