Skip to content

Commit

Permalink
Test case 07
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubRumpca committed Jun 13, 2024
1 parent f86e01c commit d29c041
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
33 changes: 32 additions & 1 deletion TEST_CASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.

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

0 comments on commit d29c041

Please sign in to comment.