From d80f49efa1eab0d7c22b75816cd964ccc34bc0b6 Mon Sep 17 00:00:00 2001 From: Jakub Rumpca Date: Thu, 13 Jun 2024 14:21:45 +0200 Subject: [PATCH] Test case 06 --- TEST_CASES.md | 31 +++++++++++++++++++++++++++++++ page_object/homePage.ts | 14 ++++++++++++++ tests/sorting.spec.ts | 13 +++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 tests/sorting.spec.ts diff --git a/TEST_CASES.md b/TEST_CASES.md index 114c53e..2059440 100644 --- a/TEST_CASES.md +++ b/TEST_CASES.md @@ -152,4 +152,35 @@ - The user can not logs in. - The error message is displayed. +--- + +## 6) Test Case: Sort by name + +### Test Case ID: +- TC-06 + +### Test Case Name: +- Should sort the products by name in descending and ascending order. + +### Test Objective: +- Verify that a user can sort products by name. + +### Pre-conditions: +- The user has a valid account on the online store. +- The user knows their login credentials and purposely sets the wrong 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 name in descending order. +- verify that the first product on the list is T-Shirt (Red). +- sort products by name in ascending order. +- verify that the first product on the list is Sauce Labs Backpack. + +### Expected Results: +- The user successfully logs in and is redirected to the homepage. +- Products are sorted correctly in descending order by name. +- Products are sorted correctly in ascending order by name. + --- \ No newline at end of file diff --git a/page_object/homePage.ts b/page_object/homePage.ts index 3390647..d6e0fd9 100644 --- a/page_object/homePage.ts +++ b/page_object/homePage.ts @@ -3,11 +3,15 @@ import { type Locator, type Page } from '@playwright/test'; export class HomePage { readonly page: Page; readonly shoppingCartButton: Locator; + readonly sortByButton: Locator; + readonly firstProductOnList: Locator; private addToCartButton: Locator; constructor(page: Page) { this.page = page; this.shoppingCartButton = this.page.locator('[data-test="shopping-cart-link"]'); + this.sortByButton = this.page.locator('[data-test="product-sort-container"]'); + this.firstProductOnList = this.page.locator('[data-test="inventory-item-name"]').first(); } async addProduct(productName: "backpack" | "bike-light" | "onesie") { @@ -18,4 +22,14 @@ export class HomePage { async goToYourCart() { await this.shoppingCartButton.click(); } + + async sortByName(order: "asc" | "desc") { + await this.sortByButton.click(); + const optionValue = (order == "asc") ? "az" : "za"; + await this.sortByButton.selectOption(optionValue); + } + + async checkFirstItemOnProductList() { + return this.firstProductOnList; + } } diff --git a/tests/sorting.spec.ts b/tests/sorting.spec.ts new file mode 100644 index 0000000..8dc00d4 --- /dev/null +++ b/tests/sorting.spec.ts @@ -0,0 +1,13 @@ +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 }) => { + const loginPage = new LoginPage(page); + const homePage = new HomePage(page); + await loginPage.login(process.env.STANDARD_USER, process.env.PASSWORD); + await homePage.sortByName("desc"); + expect(await homePage.checkFirstItemOnProductList()).toContainText("T-Shirt (Red)"); + await homePage.sortByName("asc"); + expect(await homePage.checkFirstItemOnProductList()).toContainText("Sauce Labs Backpack"); +});