WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit ccd67dc

Browse files
authored
Merge pull request #22 from auto-qa-hub/tests-for-error-user
tests-for-error-user
2 parents eed70aa + b9518f2 commit ccd67dc

File tree

3 files changed

+128
-9
lines changed

3 files changed

+128
-9
lines changed

page_objects_ts/InventoryPage.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Locator, Page } from "@playwright/test";
22
export class InventoryPage {
33
page: Page;
4+
45
addToCartFirstButtonItem: Locator;
56
removeButtonFirstItem: Locator;
67

@@ -22,6 +23,8 @@ export class InventoryPage {
2223
shoppingContainerIcon: Locator;
2324
shoppingCartBagde: Locator;
2425

26+
productsSoftContainer: Locator
27+
2528
constructor(page: Page) {
2629
this.page = page;
2730
this.addToCartFirstButtonItem = page.locator("#add-to-cart-sauce-labs-backpack");
@@ -44,6 +47,7 @@ export class InventoryPage {
4447

4548
this.shoppingContainerIcon = page.locator("#shopping_cart_container");
4649
this.shoppingCartBagde = page.locator('a span[class="shopping_cart_badge"]');
50+
this.productsSoftContainer = page.locator('.product_sort_container');
4751
}
4852

4953
async addToCartFirstItem() {
@@ -85,6 +89,9 @@ export class InventoryPage {
8589
async ShopContainerIcon() {
8690
await this.shoppingContainerIcon.click();
8791
}
92+
async ProductsSortingClick() {
93+
await this.productsSoftContainer.click();
94+
}
8895
}
8996

9097
module.exports = { InventoryPage };

playwright.config.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default defineConfig({
2020
/* Retry on CI only */
2121
retries: process.env.CI ? 2 : 0,
2222
/* Opt out of parallel tests on CI. */
23-
workers: process.env.CI ? 1 : undefined,
23+
workers: 5,
2424
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
2525
reporter: 'html',
2626
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
@@ -39,15 +39,15 @@ export default defineConfig({
3939
use: { ...devices['Desktop Chrome'] },
4040
},
4141

42-
{
43-
name: 'firefox',
44-
use: { ...devices['Desktop Firefox'] },
45-
},
42+
// {
43+
// name: 'firefox',
44+
// use: { ...devices['Desktop Firefox'] },
45+
// },
4646

47-
{
48-
name: 'webkit',
49-
use: { ...devices['Desktop Safari'] },
50-
},
47+
// {
48+
// name: 'webkit',
49+
// use: { ...devices['Desktop Safari'] },
50+
// },
5151

5252
/* Test against mobile viewports. */
5353
// {

tests/errorUser.spec.ts

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import { test, expect } from "@playwright/test";
2+
import usersData from "../fixtures/usersData.json";
3+
import { POManager } from "../page_objects_ts/POManager";
4+
5+
test.describe("Tests for error user", () => {
6+
test("Login, adding and remove from cart iteams", async ({ page }) => {
7+
const poManager = new POManager(page);
8+
const username = usersData.users[4];
9+
const password = usersData.password;
10+
11+
await poManager.mainPage.visitMainPage();
12+
await poManager.mainPage.fillUsername(username);
13+
await poManager.mainPage.fillPassword(password);
14+
await poManager.mainPage.loginButton();
15+
await page.waitForURL("/inventory.html");
16+
17+
await poManager.inventoryPage.addToCartFirstItem();
18+
await expect(poManager.inventoryPage.removeButtonFirstItem).toBeVisible();
19+
await poManager.inventoryPage.removeFirstItem();
20+
await expect(
21+
poManager.inventoryPage.addToCartFirstButtonItem
22+
).not.toBeVisible();
23+
24+
await poManager.inventoryPage.addToCart2ndItem();
25+
await expect(poManager.inventoryPage.removeButton2ndItem).toBeVisible();
26+
await poManager.inventoryPage.remove2ndItem();
27+
await expect(
28+
poManager.inventoryPage.addToCartButton2ndItem
29+
).not.toBeVisible();
30+
31+
await poManager.inventoryPage.addToCart3rdItem();
32+
await expect(poManager.inventoryPage.addToCartButton3rdItem).toBeVisible();
33+
await expect(poManager.inventoryPage.removeButton3rdItem).not.toBeVisible();
34+
35+
await poManager.inventoryPage.addToCart4thItem();
36+
await expect(poManager.inventoryPage.addToCartButton4thItem).toBeVisible();
37+
await expect(poManager.inventoryPage.removeButton4thItem).not.toBeVisible();
38+
39+
await poManager.inventoryPage.addToCart5thItem();
40+
await expect(poManager.inventoryPage.removeButton5thItem).toBeVisible();
41+
await poManager.inventoryPage.remove5thItem();
42+
await expect(
43+
poManager.inventoryPage.addToCartButton5thItem
44+
).not.toBeVisible();
45+
46+
await poManager.inventoryPage.addToCart6thItem();
47+
await expect(poManager.inventoryPage.addToCartButton6thItem).toBeVisible();
48+
await expect(poManager.inventoryPage.removeButton6thItem).not.toBeVisible();
49+
});
50+
51+
test("Verify sorting error modal", async ({ page }) => {
52+
const poManager = new POManager(page);
53+
const username = usersData.users[4];
54+
const password = usersData.password;
55+
56+
// Login to the application
57+
await poManager.mainPage.visitMainPage();
58+
await poManager.mainPage.fillUsername(username);
59+
await poManager.mainPage.fillPassword(password);
60+
await poManager.mainPage.loginButton();
61+
await page.waitForURL("/inventory.html");
62+
63+
// Set up alert handling BEFORE triggering sorting
64+
const dialogPromise = new Promise((resolve) => {
65+
page.once("dialog", async (dialog) => {
66+
console.log("Dialog message:", dialog.message());
67+
expect(dialog.message()).toContain("Sorting is broken!");
68+
await dialog.dismiss(); // Clicks "OK"
69+
resolve(true);
70+
});
71+
});
72+
73+
// Select the sorting option
74+
await page.selectOption(".product_sort_container", "za");
75+
76+
// Ensure the alert was handled
77+
await dialogPromise;
78+
});
79+
80+
test("Last name field issue that causing failure with purshase", async ({ page }) => {
81+
const poManager = new POManager(page);
82+
const username = usersData.users[4];
83+
const password = usersData.password;
84+
85+
// Login to the application
86+
await poManager.mainPage.visitMainPage();
87+
await poManager.mainPage.fillUsername(username);
88+
await poManager.mainPage.fillPassword(password);
89+
await poManager.mainPage.loginButton();
90+
await page.waitForURL("/inventory.html");
91+
92+
await poManager.inventoryPage.addToCartFirstItem();
93+
await poManager.inventoryPage.ShopContainerIcon();
94+
await poManager.cartPage.clickCheckout();
95+
await poManager.checkoutStepOnePage.enterCheckoutDetails(
96+
"Yulia",
97+
"Test",
98+
"34221"
99+
);
100+
await poManager.checkoutStepOnePage.submitCheckout();
101+
await poManager.checkoutStepTwoPage.completeCheckout();
102+
103+
// Assert Finish button is visible and enabled (clickable)
104+
await expect(poManager.checkoutStepTwoPage.finishButton).toBeVisible();
105+
await expect(poManager.checkoutStepTwoPage.finishButton).toBeEnabled();
106+
107+
await page.waitForTimeout(1000);
108+
109+
// Assert the user remains on the same page (URL does not change)
110+
await expect(page).toHaveURL("/checkout-step-two.html");
111+
});
112+
});

0 commit comments

Comments
 (0)