Skip to content

Commit

Permalink
Added order test | swipe service
Browse files Browse the repository at this point in the history
  • Loading branch information
VadimNastoyashchy committed Dec 8, 2022
1 parent f81180c commit 944563e
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/wdio-android.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports.config = {
autoCompile: true,
tsNodeOpts: {
transpileOnly: true,
project: "test/tsconfig.json"
project: "tsconfig.json"
}
},
//
Expand Down
77 changes: 77 additions & 0 deletions src/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);
}
}
13 changes: 11 additions & 2 deletions src/components/HeaderComponent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@

export default class HeaderComponent {

public get productsTitle() {
return $("//*[@text=\"PRODUCTS\"]");
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();
}
}
5 changes: 5 additions & 0 deletions src/interfaces/IUserInformation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default interface IUserInformation {
firstName: string,
lastName: string,
zipCode: string
}
15 changes: 15 additions & 0 deletions src/pages/CartPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

export default class CartPage {

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

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

public async clickOnCheckoutBtn() {
await (await this.checkoutBtn).click();
}
}
6 changes: 6 additions & 0 deletions src/pages/CheckoutCompletePage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default class CheckoutCompletePage {

public get checkoutCompleteTitle() {
return $("//*[@text=\"CHECKOUT: COMPLETE!\"]");
}
}
34 changes: 34 additions & 0 deletions src/pages/CheckoutInformationPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import IUserInformation from "../interfaces/IUserInformation";

export default 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, lastName, zipCode }: IUserInformation) {
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();
}
}
15 changes: 15 additions & 0 deletions src/pages/CheckoutOverviewPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

export default class CheckoutOverviewPage {

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

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

public async clickOnFinishBtn() {
await (await this.finishBtn).click();
}
}
11 changes: 11 additions & 0 deletions src/pages/InventoryPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@ export default class InventoryPage {

public header = new HeaderComponent();

private get addToCartBtn() {
return $$("//*[@text=\"ADD TO CART\"]");
}

public get productsTitle() {
return $("//*[@text=\"PRODUCTS\"]");
}

public async clickOnFirstAddToCardBtn() {
await (await this.addToCartBtn[0]).click();
}
}
2 changes: 1 addition & 1 deletion src/pages/LoginPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class LoginPage {
}

private async clickOnLogInButton() {
await this.logInButton.click();
await (await this.logInButton).click();
}

public async logInWithCredentials({ userName, password }: ICredentials) {
Expand Down
3 changes: 2 additions & 1 deletion test/specs/android/logIn_problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ describe("Log in tests", () => {
it("Log in as \"problem_user\"", async () => {
const loginPage = new LoginPage();
const inventoryPage = new InventoryPage();

await loginPage.logInWithCredentials(Credentials.getUserCredentials(AccountType.Problem));
await expect(await inventoryPage.header.productsTitle.getText()).toEqual("PRODUCTS");
await expect(await inventoryPage.productsTitle.getText()).toEqual("PRODUCTS");
});
});
3 changes: 2 additions & 1 deletion test/specs/android/logIn_standard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ describe("Log in tests", () => {
it("Log in as \"standard_user\"", async () => {
const loginPage = new LoginPage();
const inventoryPage = new InventoryPage();

await loginPage.logInWithCredentials(Credentials.getUserCredentials(AccountType.Standard));
await expect(await inventoryPage.header.productsTitle.getText()).toEqual("PRODUCTS");
await expect(await inventoryPage.productsTitle.getText()).toEqual("PRODUCTS");
});
});
40 changes: 40 additions & 0 deletions test/specs/android/order.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { AccountType } from "../../../src/AccountType";
import Credentials from "../../../src/Credentials";
import CartPage from "../../../src/pages/CartPage";
import CheckoutCompletePage from "../../../src/pages/CheckoutCompletePage";
import CheckoutInformationPage from "../../../src/pages/CheckoutInformationPage";
import CheckoutOverviewPage from "../../../src/pages/CheckoutOverviewPage";
import InventoryPage from "../../../src/pages/InventoryPage";
import LoginPage from "../../../src/pages/LoginPage";
import Swipe from "../../../src/Swipe";

describe("Product order verification tests", () => {
it("Product order (positive flow)", async () => {
const loginPage = new LoginPage();
const inventoryPage = new InventoryPage();
const cartPage = new CartPage();
const checkoutInformationPage = new CheckoutInformationPage();
const checkoutOverviewPage = new CheckoutOverviewPage();
const checkoutCompletePage = new CheckoutCompletePage();
const user = {
firstName: "Vadym",
lastName: "Nastoiashchyi",
zipCode: "21000"
};

await loginPage.logInWithCredentials(Credentials.getUserCredentials(AccountType.Standard));
await expect((await inventoryPage.productsTitle)).toBeDisplayed();
await inventoryPage.clickOnFirstAddToCardBtn();
await expect(await (await inventoryPage.header.basketProductsCount).getText()).toEqual("1");
await inventoryPage.header.clickOnBasket();
await expect(await (await cartPage.yourCartTitle).getText()).toEqual("YOUR CART");
await cartPage.clickOnCheckoutBtn();
await expect(await (await checkoutInformationPage.checkoutInformationTitle).getText()).toEqual("CHECKOUT: INFORMATION");
await checkoutInformationPage.fillUserInformation(user);
await checkoutInformationPage.clickOnContinueBtn();
await expect(await (await checkoutOverviewPage.checkoutOverviewTitle).getText()).toEqual("CHECKOUT: OVERVIEW");
await Swipe.down();
await checkoutOverviewPage.clickOnFinishBtn();
await expect(await (await checkoutCompletePage.checkoutCompleteTitle).getText()).toEqual("CHECKOUT: COMPLETE!");
});
});
File renamed without changes.

0 comments on commit 944563e

Please sign in to comment.