diff --git a/TEST_CASES.md b/TEST_CASES.md index 2059440..8937e64 100644 --- a/TEST_CASES.md +++ b/TEST_CASES.md @@ -167,7 +167,7 @@ ### Pre-conditions: - The user has a valid account on the online store. -- The user knows their login credentials and purposely sets the wrong password. +- The user knows their login credentials (username and password). ### Steps: - Open the web browser. @@ -183,4 +183,35 @@ - Products are sorted correctly in descending order by name. - Products are sorted correctly in ascending order by name. +--- + +## 7) Test Case: Sort by price + +### Test Case ID: +- TC-07 + +### Test Case Name: +- Should sort the products by price in descending and ascending order. + +### Test Objective: +- Verify that a user can sort products by price. + +### Pre-conditions: +- The user has a valid account on the online store. +- The user knows their login credentials (username and password). + +### Steps: +- Open the web browser. +- Go to the online store's login page URL (https://www.saucedemo.com/). +- Login to the user (standard_user). +- sort products by price in descending order. +- verify that the first product on the list is Sauce Labs Fleece Jacket. +- sort products by price in ascending order. +- verify that the first product on the list is Sauce Labs Onesie. + +### Expected Results: +- The user successfully logs in and is redirected to the homepage. +- Products are sorted correctly in descending order by price. +- Products are sorted correctly in ascending order by price. + --- \ No newline at end of file diff --git a/page_object/homePage.ts b/page_object/homePage.ts index d6e0fd9..a77d61c 100644 --- a/page_object/homePage.ts +++ b/page_object/homePage.ts @@ -28,6 +28,12 @@ export class HomePage { const optionValue = (order == "asc") ? "az" : "za"; await this.sortByButton.selectOption(optionValue); } + + async sortByPrice(order: "asc" | "desc") { + await this.sortByButton.click(); + const optionValue = (order == "asc") ? "lohi" : "hilo"; + await this.sortByButton.selectOption(optionValue); + } async checkFirstItemOnProductList() { return this.firstProductOnList; diff --git a/tests/sorting.spec.ts b/tests/sorting.spec.ts index 8dc00d4..3b9393b 100644 --- a/tests/sorting.spec.ts +++ b/tests/sorting.spec.ts @@ -2,12 +2,24 @@ import { test, expect } from '@playwright/test'; import { LoginPage } from '../page_object/loginPage'; import { HomePage } from '../page_object/homePage' -test('Should sort the products by name in descending and ascending order', async ({ page }) => { +let homePage: HomePage; + +test.beforeEach(async ({page}) => { const loginPage = new LoginPage(page); - const homePage = new HomePage(page); + homePage = new HomePage(page); await loginPage.login(process.env.STANDARD_USER, process.env.PASSWORD); +}) + +test('Should sort the products by name in descending and ascending order', async () => { await homePage.sortByName("desc"); expect(await homePage.checkFirstItemOnProductList()).toContainText("T-Shirt (Red)"); await homePage.sortByName("asc"); expect(await homePage.checkFirstItemOnProductList()).toContainText("Sauce Labs Backpack"); }); + +test('Should sort the products by price in descending and ascending order', async () => { + await homePage.sortByPrice("desc"); + expect(await homePage.checkFirstItemOnProductList()).toContainText("Sauce Labs Fleece Jacket"); + await homePage.sortByPrice("asc"); + expect(await homePage.checkFirstItemOnProductList()).toContainText("Sauce Labs Onesie"); +});