Skip to content

Commit

Permalink
Add checkActiveSortingOption()
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubRumpca committed Jun 13, 2024
1 parent d29c041 commit 177e217
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
12 changes: 8 additions & 4 deletions TEST_CASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@
- 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).
- verify that the active sorting option is "Name (Z to A)".
- 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.
- verify that the active sorting option is "Name (A to Z)".
- 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.
Expand Down Expand Up @@ -205,9 +207,11 @@
- 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.
- verify that the active sorting option is "Price (high to low)".
- 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.
- verify that the active sorting option is "Price (low to high)".
- 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.
Expand Down
6 changes: 6 additions & 0 deletions page_object/homePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ export class HomePage {
readonly shoppingCartButton: Locator;
readonly sortByButton: Locator;
readonly firstProductOnList: Locator;
readonly activeSortingOption: 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.activeSortingOption = this.page.locator('[data-test="active-option"]');
this.firstProductOnList = this.page.locator('[data-test="inventory-item-name"]').first();
}

Expand Down Expand Up @@ -38,4 +40,8 @@ export class HomePage {
async checkFirstItemOnProductList() {
return this.firstProductOnList;
}

async checkActiveSortingOption() {
return this.activeSortingOption;
}
}
6 changes: 5 additions & 1 deletion tests/sorting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ test.beforeEach(async ({page}) => {

test('Should sort the products by name in descending and ascending order', async () => {
await homePage.sortByName("desc");
expect(await homePage.checkActiveSortingOption()).toContainText("Name (Z to A)");
expect(await homePage.checkFirstItemOnProductList()).toContainText("T-Shirt (Red)");
await homePage.sortByName("asc");
expect(await homePage.checkActiveSortingOption()).toContainText("Name (A to Z)");
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.checkActiveSortingOption()).toContainText("Price (high to low)");
expect(await homePage.checkFirstItemOnProductList()).toContainText("Sauce Labs Fleece Jacket");
await homePage.sortByPrice("asc");
expect(await homePage.checkActiveSortingOption()).toContainText("Price (low to high)");
expect(await homePage.checkFirstItemOnProductList()).toContainText("Sauce Labs Onesie");
});

0 comments on commit 177e217

Please sign in to comment.