Skip to content

Commit

Permalink
Merge pull request #2 from VadimNastoyashchy/cucumber_support
Browse files Browse the repository at this point in the history
Cucumber support
  • Loading branch information
VadimNastoyashchy authored Dec 9, 2022
2 parents 944563e + 850956d commit f57a0ce
Show file tree
Hide file tree
Showing 23 changed files with 74 additions and 301 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/node_modules
/package-lock.json
/wdio-appium.log
node_modules
package-lock.json
wdio-appium.log
24 changes: 19 additions & 5 deletions config/wdio-android.conf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {join} from "path";
import { join } from "path";

exports.config = {

Expand All @@ -15,7 +15,7 @@ exports.config = {
// ====================
//
port: 4723,
specs: ["./test/specs/android/*.ts"],
specs: ["./features/**/*.feature"],
// Patterns to exclude.
exclude: [],
//
Expand Down Expand Up @@ -73,10 +73,24 @@ exports.config = {
},
],
],
framework: "mocha",
framework: "cucumber",
reporters: ["spec"],
mochaOpts: {
ui: "bdd",
cucumberOpts: {
require: [
"./features/step-definitions/given.ts",
"./features/step-definitions/then.ts",
"./features/step-definitions/when.ts",

],
backtrace: false,
requireModule: [],
dryRun: false,
failFast: false,
snippets: true,
source: true,
strict: false,
tagExpression: "",
timeout: 60000,
ignoreUndefinedDefinitions: false
},
};
11 changes: 11 additions & 0 deletions features/login.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Swaglabs app Log In

Scenario Outline: As a standard user, I can log into Swaglabs application

Given I am on the login page
When I login with <username> and <password>
Then I redirected to the inventory page with title <title>

Examples:
| username | password | title |
| standard_user | secret_sauce | PRODUCTS |
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import HeaderComponent from "../components/HeaderComponent";

export default class InventoryPage {
class InventoryPage {

public header = new HeaderComponent();
// public header = new HeaderComponent();

private get addToCartBtn() {
return $$("//*[@text=\"ADD TO CART\"]");
Expand All @@ -15,4 +14,6 @@ export default class InventoryPage {
public async clickOnFirstAddToCardBtn() {
await (await this.addToCartBtn[0]).click();
}
}
}

export default new InventoryPage();
15 changes: 10 additions & 5 deletions src/pages/LoginPage.ts → features/pageobjects/pages/LoginPage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ICredentials from "../interfaces/ICredentials";

export default class LoginPage {
class LoginPage {

private get inputEmail() {
return $("~test-Username");
Expand All @@ -10,10 +9,14 @@ export default class LoginPage {
return $("~test-Password");
}

private get logInButton() {
public get logInButton() {
return $("//*[@text=\"LOGIN\"]");
}

public get swaglabsImg() {
return $("//android.widget.ScrollView[@content-desc='test-Login']/android.view.ViewGroup/android.widget.ImageView[1]");
}

private async enterEmail(userName: string) {
await this.inputEmail.setValue(userName);
}
Expand All @@ -26,9 +29,11 @@ export default class LoginPage {
await (await this.logInButton).click();
}

public async logInWithCredentials({ userName, password }: ICredentials) {
public async logInWithCredentials(userName: string, password: string) {
await this.enterEmail(userName);
await this.enterPassword(password);
await this.clickOnLogInButton();
}
}
}

export default new LoginPage();
7 changes: 7 additions & 0 deletions features/step-definitions/given.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Given } from "@wdio/cucumber-framework";
import LoginPage from "../pageobjects/pages/LoginPage";

Given(/^I am on the login page/, async () => {
await expect(await LoginPage.swaglabsImg).toBeDisplayed();
await expect(await LoginPage.logInButton).toBeDisplayed();
});
6 changes: 6 additions & 0 deletions features/step-definitions/then.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Then } from "@wdio/cucumber-framework";
import InventoryPage from "../pageobjects/pages/InventoryPage";

Then(/^I redirected to the inventory page with title (.*)$/, async (title) => {
await expect(await InventoryPage.productsTitle.getText()).toEqual(title);
});
6 changes: 6 additions & 0 deletions features/step-definitions/when.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { When } from "@wdio/cucumber-framework";
import LoginPage from "../pageobjects/pages/LoginPage";

When(/^I login with (\w+) and (.+)$/, async (username, password) => {
await LoginPage.logInWithCredentials(username, password);
});
11 changes: 2 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
{
"name": "webdriverio-tests",
"version": "0.1.0",
"description": "",
"private": true,
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@wdio/cucumber-framework": "^7.25.1",
"@wdio/appium-service": "^7.25.1",
"@wdio/cli": "^7.25.1",
"@wdio/local-runner": "^7.25.1",
"@wdio/mocha-framework": "^7.25.1",
"@wdio/spec-reporter": "^7.25.1",
"appium": "^2.0.0-beta.44",
"appium-uiautomator2-driver": "^2.7.0",
Expand All @@ -27,4 +20,4 @@
"scripts": {
"wdioAndroid": "wdio run config/wdio-android.conf.ts"
}
}
}
5 changes: 0 additions & 5 deletions src/AccountType.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/Credentials.ts

This file was deleted.

77 changes: 0 additions & 77 deletions src/Swipe.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/components/HeaderComponent.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/interfaces/ICredentials.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/interfaces/IUserInformation.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/pages/CartPage.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/pages/CheckoutCompletePage.ts

This file was deleted.

34 changes: 0 additions & 34 deletions src/pages/CheckoutInformationPage.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/pages/CheckoutOverviewPage.ts

This file was deleted.

Loading

0 comments on commit f57a0ce

Please sign in to comment.