Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions page_objects_ts/InventoryPage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Locator, Page } from "@playwright/test";
export class InventoryPage {
page: Page;

addToCartFirstButtonItem: Locator;
removeButtonFirstItem: Locator;

Expand All @@ -22,6 +23,8 @@ export class InventoryPage {
shoppingContainerIcon: Locator;
shoppingCartBagde: Locator;

productsSoftContainer: Locator

constructor(page: Page) {
this.page = page;
this.addToCartFirstButtonItem = page.locator("#add-to-cart-sauce-labs-backpack");
Expand All @@ -44,6 +47,7 @@ export class InventoryPage {

this.shoppingContainerIcon = page.locator("#shopping_cart_container");
this.shoppingCartBagde = page.locator('a span[class="shopping_cart_badge"]');
this.productsSoftContainer = page.locator('.product_sort_container');
}

async addToCartFirstItem() {
Expand Down Expand Up @@ -85,6 +89,9 @@ export class InventoryPage {
async ShopContainerIcon() {
await this.shoppingContainerIcon.click();
}
async ProductsSortingClick() {
await this.productsSoftContainer.click();
}
}

module.exports = { InventoryPage };
18 changes: 9 additions & 9 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default defineConfig({
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
workers: 5,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
Expand All @@ -39,15 +39,15 @@ export default defineConfig({
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },

/* Test against mobile viewports. */
// {
Expand Down
112 changes: 112 additions & 0 deletions tests/errorUser.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { test, expect } from "@playwright/test";
import usersData from "../fixtures/usersData.json";
import { POManager } from "../page_objects_ts/POManager";

test.describe("Tests for error user", () => {
test("Login, adding and remove from cart iteams", async ({ page }) => {
const poManager = new POManager(page);
const username = usersData.users[4];
const password = usersData.password;

await poManager.mainPage.visitMainPage();
await poManager.mainPage.fillUsername(username);
await poManager.mainPage.fillPassword(password);
await poManager.mainPage.loginButton();
await page.waitForURL("/inventory.html");

await poManager.inventoryPage.addToCartFirstItem();
await expect(poManager.inventoryPage.removeButtonFirstItem).toBeVisible();
await poManager.inventoryPage.removeFirstItem();
await expect(
poManager.inventoryPage.addToCartFirstButtonItem
).not.toBeVisible();

await poManager.inventoryPage.addToCart2ndItem();
await expect(poManager.inventoryPage.removeButton2ndItem).toBeVisible();
await poManager.inventoryPage.remove2ndItem();
await expect(
poManager.inventoryPage.addToCartButton2ndItem
).not.toBeVisible();

await poManager.inventoryPage.addToCart3rdItem();
await expect(poManager.inventoryPage.addToCartButton3rdItem).toBeVisible();
await expect(poManager.inventoryPage.removeButton3rdItem).not.toBeVisible();

await poManager.inventoryPage.addToCart4thItem();
await expect(poManager.inventoryPage.addToCartButton4thItem).toBeVisible();
await expect(poManager.inventoryPage.removeButton4thItem).not.toBeVisible();

await poManager.inventoryPage.addToCart5thItem();
await expect(poManager.inventoryPage.removeButton5thItem).toBeVisible();
await poManager.inventoryPage.remove5thItem();
await expect(
poManager.inventoryPage.addToCartButton5thItem
).not.toBeVisible();

await poManager.inventoryPage.addToCart6thItem();
await expect(poManager.inventoryPage.addToCartButton6thItem).toBeVisible();
await expect(poManager.inventoryPage.removeButton6thItem).not.toBeVisible();
});

test("Verify sorting error modal", async ({ page }) => {
const poManager = new POManager(page);
const username = usersData.users[4];
const password = usersData.password;

// Login to the application
await poManager.mainPage.visitMainPage();
await poManager.mainPage.fillUsername(username);
await poManager.mainPage.fillPassword(password);
await poManager.mainPage.loginButton();
await page.waitForURL("/inventory.html");

// Set up alert handling BEFORE triggering sorting
const dialogPromise = new Promise((resolve) => {
page.once("dialog", async (dialog) => {
console.log("Dialog message:", dialog.message());
expect(dialog.message()).toContain("Sorting is broken!");
await dialog.dismiss(); // Clicks "OK"
resolve(true);
});
});

// Select the sorting option
await page.selectOption(".product_sort_container", "za");

// Ensure the alert was handled
await dialogPromise;
});

test("Last name field issue that causing failure with purshase", async ({ page }) => {
const poManager = new POManager(page);
const username = usersData.users[4];
const password = usersData.password;

// Login to the application
await poManager.mainPage.visitMainPage();
await poManager.mainPage.fillUsername(username);
await poManager.mainPage.fillPassword(password);
await poManager.mainPage.loginButton();
await page.waitForURL("/inventory.html");

await poManager.inventoryPage.addToCartFirstItem();
await poManager.inventoryPage.ShopContainerIcon();
await poManager.cartPage.clickCheckout();
await poManager.checkoutStepOnePage.enterCheckoutDetails(
"Yulia",
"Test",
"34221"
);
await poManager.checkoutStepOnePage.submitCheckout();
await poManager.checkoutStepTwoPage.completeCheckout();

// Assert Finish button is visible and enabled (clickable)
await expect(poManager.checkoutStepTwoPage.finishButton).toBeVisible();
await expect(poManager.checkoutStepTwoPage.finishButton).toBeEnabled();

await page.waitForTimeout(1000);

// Assert the user remains on the same page (URL does not change)
await expect(page).toHaveURL("/checkout-step-two.html");
});
});