Skip to content

Commit 6ebdc9e

Browse files
committed
refactor: extend fixtures with checkoutPage and readyForCheckout
1 parent aef753f commit 6ebdc9e

File tree

3 files changed

+59
-33
lines changed

3 files changed

+59
-33
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ The project follows the **Page Object Model (POM)** pattern and covers core e-co
99
- Page Object Model (POM)
1010
- Allure Report (planned)
1111
- GitHub Actions (CI/CD)
12+
- [Testomat.io](https://testomat.io/) — test management & living documentation
13+
14+
## Test Documentation
15+
16+
All manual and automated test cases are documented in Testomat.io.
17+
You can explore the full list of test cases and descriptions below 👇
18+
19+
[View Test Cases in Testomat.io](https://www.saucedemo.com/)
1220

1321
## 📂 Project Structure
1422

@@ -23,6 +31,7 @@ fixtures/ # Custom Playwright fixtures
2331
reports/ # Reports (Allure)
2432

2533
## 🚀 How to Run Tests
34+
2635
```bash
2736
# Install dependencies
2837
npm install
@@ -35,3 +44,4 @@ npx playwright test --headed
3544

3645
# Run a specific test file
3746
npx playwright test tests/login.spec.ts
47+
```

fixtures/fixtures.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
import { test as base, expect } from "@playwright/test";
1+
import { Page, test as base, expect } from "@playwright/test";
22
import { LoginPage } from "../pages/LoginPage";
33
import { AddItem } from "../pages/AddItemToCart";
4+
import { Checkout } from "../pages/Checkout";
45

5-
export const test = base.extend<{ loginPage: LoginPage; cartReady: void }>({
6+
interface ReadyForCheckout {
7+
page: Page;
8+
checkoutPage: Checkout;
9+
}
10+
11+
export const test = base.extend<{
12+
loginPage: LoginPage;
13+
cartReady: void;
14+
checkoutPage: Checkout;
15+
readyForCheckout: ReadyForCheckout;
16+
}>({
617
loginPage: async ({ page }, use) => {
718
const loginPage = new LoginPage(page);
819
await loginPage.goto();
@@ -22,6 +33,25 @@ export const test = base.extend<{ loginPage: LoginPage; cartReady: void }>({
2233

2334
await use();
2435
},
36+
37+
checkoutPage: async ({ page }, use) => {
38+
const checkout = new Checkout(page);
39+
40+
await checkout.clickCheckout();
41+
42+
await expect(page).toHaveURL(
43+
"https://www.saucedemo.com/checkout-step-one.html"
44+
);
45+
46+
await use(checkout);
47+
},
48+
49+
readyForCheckout: async (
50+
{ page, loginPage, cartReady, checkoutPage },
51+
use
52+
) => {
53+
await use({ page, checkoutPage });
54+
},
2555
});
2656

2757
export { expect };

tests/Checkout.spec.ts

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,34 @@
1+
import { read } from "fs";
12
import { test, expect } from "../fixtures/fixtures";
23

34
import { AddItem } from "../pages/AddItemToCart";
45

56
import { Checkout } from "../pages/Checkout";
67

78
test.describe("Checkout", () => {
8-
test("Successfull checkout", async ({ page, loginPage, cartReady }) => {
9-
const checkout = new Checkout(page);
9+
test("Successfull checkout", async ({ readyForCheckout }) => {
10+
const { page, checkoutPage } = readyForCheckout;
1011

11-
await checkout.clickCheckout();
12-
await checkout.completeInfo("Kamran", "Musadirli", "12345");
13-
await checkout.clickContinue();
12+
await checkoutPage.completeInfo("Kamran", "Musadirli", "12345");
13+
await checkoutPage.clickContinue();
1414
await page.waitForTimeout(2000);
1515

1616
await expect(page).toHaveURL(
1717
"https://www.saucedemo.com/checkout-step-two.html"
1818
);
1919

20-
await checkout.clickFinish();
20+
await checkoutPage.clickFinish();
2121

2222
await expect(page.locator(".complete-header")).toHaveText(
2323
"Thank you for your order!"
2424
);
2525
});
2626

2727
test.describe("Checkout with invalid data", () => {
28-
test("Checkout with no data", async ({ page, loginPage, cartReady }) => {
29-
const checkout = new Checkout(page);
28+
test("Checkout with no data", async ({ readyForCheckout }) => {
29+
const { page, checkoutPage } = readyForCheckout;
3030

31-
await checkout.clickCheckout();
32-
33-
// without filling the data
34-
35-
await checkout.clickContinue();
31+
await checkoutPage.clickContinue();
3632

3733
await expect(
3834
page.locator(".error-message-container.error")
@@ -46,17 +42,13 @@ test.describe("Checkout", () => {
4642
});
4743

4844
test("Checkout without Last Name And Zip Code", async ({
49-
page,
50-
loginPage,
51-
cartReady,
45+
readyForCheckout,
5246
}) => {
53-
const checkout = new Checkout(page);
54-
55-
await checkout.clickCheckout();
47+
const { page, checkoutPage } = readyForCheckout;
5648

57-
await checkout.completeInfo("Kamran");
49+
await checkoutPage.completeInfo("Kamran");
5850

59-
await checkout.clickContinue();
51+
await checkoutPage.clickContinue();
6052

6153
await expect(
6254
page.locator(".error-message-container.error")
@@ -69,18 +61,12 @@ test.describe("Checkout", () => {
6961
await page.waitForTimeout(2000);
7062
});
7163

72-
test("Checkout without Zip Code", async ({
73-
page,
74-
loginPage,
75-
cartReady,
76-
}) => {
77-
const checkout = new Checkout(page);
78-
79-
await checkout.clickCheckout();
64+
test("Checkout without Zip Code", async ({ readyForCheckout }) => {
65+
const { page, checkoutPage } = readyForCheckout;
8066

81-
await checkout.completeInfo("Kamran", "Musadirli");
67+
await checkoutPage.completeInfo("Kamran", "Musadirli");
8268

83-
await checkout.clickContinue();
69+
await checkoutPage.clickContinue();
8470

8571
await expect(
8672
page.locator(".error-message-container.error")

0 commit comments

Comments
 (0)