Skip to content

Commit

Permalink
Merge pull request #11 from JakubRumpca/Test-case-06
Browse files Browse the repository at this point in the history
Test case 06: Sort by name
  • Loading branch information
JakubRumpca authored Jun 13, 2024
2 parents 48d9825 + d80f49e commit f86e01c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
31 changes: 31 additions & 0 deletions TEST_CASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---
14 changes: 14 additions & 0 deletions page_object/homePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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;
}
}
13 changes: 13 additions & 0 deletions tests/sorting.spec.ts
Original file line number Diff line number Diff line change
@@ -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");
});

0 comments on commit f86e01c

Please sign in to comment.