diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3ac2686 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "cucumberautocomplete.steps": [ + "features/step-definitions/*.ts", + ], + "cucumberautocomplete.strictGherkinCompletion": true +} \ No newline at end of file diff --git a/features/pageobjects/components/FilterComponent.ts b/features/pageobjects/components/FilterComponent.ts new file mode 100644 index 0000000..85e9507 --- /dev/null +++ b/features/pageobjects/components/FilterComponent.ts @@ -0,0 +1,11 @@ +class FilterComponent { + private get nameZtoA() { + return $("//*[@text=\"Name (Z to A)\"]"); + } + + public async clickOnNameZtoA() { + await (await this.nameZtoA).click(); + } +} + +export default new FilterComponent(); \ No newline at end of file diff --git a/features/pageobjects/pages/InventoryPage.ts b/features/pageobjects/pages/InventoryPage.ts index 2902396..3c6bb2e 100644 --- a/features/pageobjects/pages/InventoryPage.ts +++ b/features/pageobjects/pages/InventoryPage.ts @@ -1,13 +1,23 @@ import HeaderComponent from "../components/HeaderComponent"; +import FilterComponent from "../components/FilterComponent"; class InventoryPage { public header = HeaderComponent; + public filter = FilterComponent; private get addToCartBtn() { return $$("//*[@text=\"ADD TO CART\"]"); } + private get productItemTitles() { + return $$("//android.widget.TextView[@content-desc=\"test-Item title\"]"); + } + + private get filterBtn() { + return $("//android.view.ViewGroup[@content-desc=\"test-Modal Selector Button\"]"); + } + public get productsTitle() { return $("//*[@text=\"PRODUCTS\"]"); } @@ -15,6 +25,16 @@ class InventoryPage { public async clickOnFirstAddToCardBtn() { await (await this.addToCartBtn[0]).click(); } + + public async clickOnFilterBtn() { + await (await this.filterBtn).click(); + } + + public async checkProductItemsIsSortedFromZtoA() { + const firstProductTitle = await (await this.productItemTitles[0]).getText(); + const secondProductTitle = await (await this.productItemTitles[1]).getText(); + await expect(firstProductTitle.charCodeAt(0)).toBeGreaterThan(secondProductTitle.charCodeAt(0)); + } } export default new InventoryPage(); \ No newline at end of file diff --git a/features/product_filter.feature b/features/product_filter.feature new file mode 100644 index 0000000..4909ea8 --- /dev/null +++ b/features/product_filter.feature @@ -0,0 +1,7 @@ +Feature: Swaglabs app product filter + + Scenario Outline: As a standard user, I can filter the product + + Given I am logged in the app + When I chose NAME(Z-A) in filter options + Then products should be sorted From Z to A \ No newline at end of file diff --git a/features/step-definitions/productFilter.ts b/features/step-definitions/productFilter.ts new file mode 100644 index 0000000..b239818 --- /dev/null +++ b/features/step-definitions/productFilter.ts @@ -0,0 +1,12 @@ +import {Then, When} from "@wdio/cucumber-framework"; +import InventoryPage from "../pageobjects/pages/InventoryPage"; + +When(/^I chose NAME\(Z-A\) in filter options$/, async () => { + await InventoryPage.clickOnFilterBtn(); + await InventoryPage.filter.clickOnNameZtoA(); + await expect((await InventoryPage.productsTitle)).toBeDisplayed(); +}); + +Then(/^products should be sorted From Z to A$/, async () => { + await InventoryPage.checkProductItemsIsSortedFromZtoA(); +}); \ No newline at end of file