Skip to content

Commit

Permalink
Added test for product filter scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
VadimNastoyashchy committed Dec 12, 2022
1 parent 486cbbc commit 1c20759
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cucumberautocomplete.steps": [
"features/step-definitions/*.ts",
],
"cucumberautocomplete.strictGherkinCompletion": true
}
11 changes: 11 additions & 0 deletions features/pageobjects/components/FilterComponent.ts
Original file line number Diff line number Diff line change
@@ -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();
20 changes: 20 additions & 0 deletions features/pageobjects/pages/InventoryPage.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
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\"]");
}

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();
7 changes: 7 additions & 0 deletions features/product_filter.feature
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions features/step-definitions/productFilter.ts
Original file line number Diff line number Diff line change
@@ -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();
});

0 comments on commit 1c20759

Please sign in to comment.