Skip to content

Commit

Permalink
Merge pull request #4 from VadimNastoyashchy/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
VadimNastoyashchy authored Dec 9, 2022
2 parents 79c4cb5 + 486cbbc commit 53190e1
Show file tree
Hide file tree
Showing 19 changed files with 285 additions and 29 deletions.
9 changes: 2 additions & 7 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 Down Expand Up @@ -76,12 +76,7 @@ exports.config = {
framework: "cucumber",
reporters: ["spec"],
cucumberOpts: {
require: [
"./features/step-definitions/given.ts",
"./features/step-definitions/then.ts",
"./features/step-definitions/when.ts",

],
require: ["./features/step-definitions/*.ts",],
backtrace: false,
requireModule: [],
dryRun: false,
Expand Down
11 changes: 11 additions & 0 deletions features/login_problem_user.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Swaglabs app Log In

Scenario Outline: As a problem 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 |
| problem_user | secret_sauce | PRODUCTS |
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Feature: Swaglabs app Log In

Examples:
| username | password | title |
| standard_user | secret_sauce | PRODUCTS |
| standard_user | secret_sauce | PRODUCTS |
5 changes: 5 additions & 0 deletions features/pageobjects/AccountType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum AccountType {
Standard = "standard",
LocKed = "locked",
Problem = "problem",
}
22 changes: 22 additions & 0 deletions features/pageobjects/Credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {AccountType} from "./AccountType";

export default class Credentials {
private static readonly accountInfo = {
standard: {
userName: "standard_user",
password: "secret_sauce"
},
locked: {
userName: "locked_out_user",
password: "secret_sauce"
},
problem: {
userName: "problem_user",
password: "secret_sauce"
}
};

public static getUserCredentials(accountType: AccountType) {
return this.accountInfo[accountType];
}
}
77 changes: 77 additions & 0 deletions features/pageobjects/Swipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {RectReturn} from "@wdio/protocols/build/types";

interface ICoordinates {
x: number;
y: number;
}

const SWIPE_COORDINATES = {
downPoint: {
from: {x: 50, y: 85},
to: {x: 50, y: 15},
},
upPoint: {
from: {x: 50, y: 15},
to: {x: 50, y: 85},
},
rightPoint: {
from: {x: 95, y: 50},
to: {x: 5, y: 50},
},
leftPoint: {
from: {x: 5, y: 50},
to: {x: 95, y: 50},
},
};

export default class Swipe {

public static async up() {
await this.swipeOn(SWIPE_COORDINATES.upPoint.from, SWIPE_COORDINATES.upPoint.to);
}

public static async down() {
await this.swipeOn(SWIPE_COORDINATES.downPoint.from, SWIPE_COORDINATES.downPoint.to);
}

public static async right() {
await this.swipeOn(SWIPE_COORDINATES.rightPoint.from, SWIPE_COORDINATES.rightPoint.to);
}

public static async left() {
await this.swipeOn(SWIPE_COORDINATES.leftPoint.from, SWIPE_COORDINATES.leftPoint.to,);
}

private static async swipeOn(from: ICoordinates, to: ICoordinates) {
const SCREEN_SIZE = await driver.getWindowRect();
const moveFromScreenCoordinates = this.getDeviceScreenCoordinates(SCREEN_SIZE, from);
const moveToScreenCoordinates = this.getDeviceScreenCoordinates(SCREEN_SIZE, to);

await this.swipe(moveFromScreenCoordinates, moveToScreenCoordinates,);
}

private static getDeviceScreenCoordinates(screenSize: RectReturn, coordinates: ICoordinates): ICoordinates {
return {
x: Math.round(screenSize.width * (coordinates.x / 100)),
y: Math.round(screenSize.height * (coordinates.y / 100)),
};
}

private static async swipe(from: ICoordinates, to: ICoordinates) {
await driver.performActions([
{
type: "pointer",
id: "finger1",
parameters: {pointerType: "touch"},
actions: [
{type: "pointerMove", duration: 0, x: from.x, y: from.y},
{type: "pointerDown", button: 0},
{type: "pause", duration: 100},
{type: "pointerMove", duration: 1000, x: to.x, y: to.y},
{type: "pointerUp", button: 0},
],
},
]);
await driver.pause(1000);
}
}
18 changes: 18 additions & 0 deletions features/pageobjects/components/HeaderComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class HeaderComponent {

private readonly basketLocator = "//android.view.ViewGroup[@content-desc='test-Cart']/android.view.ViewGroup/";

private get basketImg() {
return $(`${this.basketLocator}android.widget.ImageView`);
}

public get basketProductsCount() {
return $(`${this.basketLocator}android.widget.TextView`);
}

public async clickOnBasket() {
await (await this.basketImg).click();
}
}

export default new HeaderComponent();
16 changes: 16 additions & 0 deletions features/pageobjects/pages/CartPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CartPage {

private get checkoutBtn() {
return $("//*[@text=\"CHECKOUT\"]");
}

public get yourCartTitle() {
return $("//*[@text=\"YOUR CART\"]");
}

public async clickOnCheckoutBtn() {
await (await this.checkoutBtn).click();
}
}

export default new CartPage();
8 changes: 8 additions & 0 deletions features/pageobjects/pages/CheckoutCompletePage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CheckoutCompletePage {

public get checkoutCompleteTitle() {
return $("//*[@text=\"CHECKOUT: COMPLETE!\"]");
}
}

export default new CheckoutCompletePage();
34 changes: 34 additions & 0 deletions features/pageobjects/pages/CheckoutInformationPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class CheckoutInformationPage {

private get firstNameField() {
return $("~test-First Name");
}

private get lastNameField() {
return $("~test-Last Name");
}

private get zipField() {
return $("~test-Zip/Postal Code");
}

private get continueBtn() {
return $("//*[@text=\"CONTINUE\"]");
}

public get checkoutInformationTitle() {
return $("//*[@text=\"CHECKOUT: INFORMATION\"]");
}

public async fillUserInformation(firstName: string, lastName: string, zipCode: string) {
await (await this.firstNameField).setValue(firstName);
await (await this.lastNameField).setValue(lastName);
await (await this.zipField).setValue(zipCode);
}

public async clickOnContinueBtn() {
await (await this.continueBtn).click();
}
}

export default new CheckoutInformationPage();
16 changes: 16 additions & 0 deletions features/pageobjects/pages/CheckoutOverviewPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CheckoutOverviewPage {

private get finishBtn() {
return $("//*[@text=\"FINISH\"]");
}

public get checkoutOverviewTitle() {
return $("//*[@text=\"CHECKOUT: OVERVIEW\"]");
}

public async clickOnFinishBtn() {
await (await this.finishBtn).click();
}
}

export default new CheckoutOverviewPage();
3 changes: 2 additions & 1 deletion features/pageobjects/pages/InventoryPage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import HeaderComponent from "../components/HeaderComponent";

class InventoryPage {

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

private get addToCartBtn() {
return $$("//*[@text=\"ADD TO CART\"]");
Expand Down
1 change: 0 additions & 1 deletion features/pageobjects/pages/LoginPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class LoginPage {

private get inputEmail() {
Expand Down
14 changes: 14 additions & 0 deletions features/product_order.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Feature: Swaglabs app product order

Scenario Outline: As a standard user, I can order the product

Given I am logged in the app
And I want to add one product into the basket
And I complete first order step
When I fill <firstName> and <lastName> and <zipCode> on the second order step
Then I click on the finnish button on the third order step
And I will see page title <title>

Examples:
| firstName | lastName | zipCode | | title |
| Vadym | Nastoiashchyi | 21000 | | CHECKOUT: COMPLETE! |
7 changes: 0 additions & 7 deletions features/step-definitions/given.ts

This file was deleted.

16 changes: 16 additions & 0 deletions features/step-definitions/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {Given, Then, When} from "@wdio/cucumber-framework";
import LoginPage from "../pageobjects/pages/LoginPage";
import InventoryPage from "../pageobjects/pages/InventoryPage";

Given(/^I am on the login page/, async () => {
await expect(await LoginPage.swaglabsImg).toBeDisplayed();
await expect(await LoginPage.logInButton).toBeDisplayed();
});

When(/^I login with (\w+) and (.+)$/, async (username, password) => {
await LoginPage.logInWithCredentials(username, password);
});

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

Given(/^I am logged in the app/, async () => {
const {userName, password} = Credentials.getUserCredentials(AccountType.Standard);
await LoginPage.logInWithCredentials(userName, password);
await expect((await InventoryPage.productsTitle)).toBeDisplayed();
});

When(/^I want to add one product into the basket/, async () => {
await InventoryPage.clickOnFirstAddToCardBtn();
await expect(await (await InventoryPage.header.basketProductsCount).getText()).toEqual("1");
});

When(/^I complete first order step/, async () => {
await InventoryPage.header.clickOnBasket();
await expect(await (await CartPage.yourCartTitle).getText()).toEqual("YOUR CART");
});

When(/^I fill (\w+) and (\w+) and (\w+) on the second order step/, async (firstName, lastName, zipCode) => {
await CartPage.clickOnCheckoutBtn();
await expect(await (await CheckoutInformationPage.checkoutInformationTitle).getText()).toEqual("CHECKOUT: INFORMATION");
await CheckoutInformationPage.fillUserInformation(firstName, lastName, zipCode);
await CheckoutInformationPage.clickOnContinueBtn();
await expect(await (await CheckoutOverviewPage.checkoutOverviewTitle).getText()).toEqual("CHECKOUT: OVERVIEW");
await Swipe.down();
});

Then(/^I click on the finnish button on the third order step/, async () => {
await CheckoutOverviewPage.clickOnFinishBtn();
});

Then(/^I will see page title (.*)/, async (title) => {
await expect(await (await CheckoutCompletePage.checkoutCompleteTitle).getText()).toEqual(title);
});
6 changes: 0 additions & 6 deletions features/step-definitions/then.ts

This file was deleted.

6 changes: 0 additions & 6 deletions features/step-definitions/when.ts

This file was deleted.

0 comments on commit 53190e1

Please sign in to comment.