Skip to content

Commit

Permalink
Refactored classes and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
VadimNastoyashchy committed Dec 8, 2022
1 parent c9425c2 commit f81180c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 32 deletions.
29 changes: 14 additions & 15 deletions config/wdio-android.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports.config = {
// ====================
//
port: 4723,
specs: [],
specs: ["./test/specs/android/*.ts"],
// Patterns to exclude.
exclude: [],
//
Expand All @@ -25,23 +25,22 @@ exports.config = {
//
maxInstances: 2,
capabilities: [
// {
// platformName: "Android",
// maxInstances: 1,
// specs: ["./test/specs/android/logIn_problem.ts"],
// "appium:avd": "Pixel_3_API_29",
// "appium:deviceName": "Pixel_3_10.0",
// "appium:platformVersion": "10.0",
// "appium:orientation": "PORTRAIT",
// "appium:automationName": "UiAutomator2",
// "appium:app": join(process.cwd(), "./app/Android.SauceLabs.Mobile.Sample.app.2.7.1.apk"),
// "appium:appWaitActivity": "com.swaglabsmobileapp.MainActivity",
// "appium:newCommandTimeout": 240,
// },
{
platformName: "Android",
maxInstances: 1,
specs: ["./test/specs/android/logIn_problem.ts"],
"appium:avd": "Pixel_3_API_29",
"appium:deviceName": "Pixel_3_10.0",
"appium:platformVersion": "10.0",
"appium:orientation": "PORTRAIT",
"appium:automationName": "UiAutomator2",
"appium:app": join(process.cwd(), "./app/Android.SauceLabs.Mobile.Sample.app.2.7.1.apk"),
"appium:appWaitActivity": "com.swaglabsmobileapp.MainActivity",
"appium:newCommandTimeout": 240,
},
{
platformName: "Android",
maxInstances: 1,
specs: ["./test/specs/android/logIn_standard.ts"],
"appium:avd": "Pixel_XL_API_29",
"appium:deviceName": "Pixel_XL_10.0",
"appium:platformVersion": "10.0",
Expand Down
8 changes: 8 additions & 0 deletions src/components/HeaderComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export default class HeaderComponent {

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

}
7 changes: 7 additions & 0 deletions src/pages/InventoryPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import HeaderComponent from "../components/HeaderComponent";

export default class InventoryPage {

public header = new HeaderComponent();

}
11 changes: 4 additions & 7 deletions src/pages/LoginPage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ICredentials from "../interfaces/ICredentials";

class Login {
export default class LoginPage {

private get inputEmail() {
return $("~test-Username");
Expand All @@ -11,7 +11,7 @@ class Login {
}

private get logInButton() {
return $("//android.view.ViewGroup[@content-desc=\"test-LOGIN\"]/android.widget.TextView");
return $("//*[@text=\"LOGIN\"]");
}

private async enterEmail(userName: string) {
Expand All @@ -26,12 +26,9 @@ class Login {
await this.logInButton.click();
}

public async logInWithCredentials(credentials: ICredentials): Promise<void> {
const {userName, password} = credentials;
public async logInWithCredentials({ userName, password }: ICredentials) {
await this.enterEmail(userName);
await this.enterPassword(password);
await this.clickOnLogInButton();
}
}

export const LoginPage = new Login();
}
12 changes: 7 additions & 5 deletions test/specs/android/logIn_problem.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import LoginPage from "../../../src/pages/LoginPage";
import Credentials from "../../../src/Credentials";
import {AccountType} from "../../../src/AccountType";
import {LoginPage} from "../../../src/pages/LoginPage";
import { AccountType } from "../../../src/AccountType";
import InventoryPage from "../../../src/pages/InventoryPage";

describe("Log in tests", () => {

it("Log in as \"problem_user\"", async () => {
await LoginPage.logInWithCredentials(Credentials.getUserCredentials(AccountType.Problem));
const headerText = await $("//*[@text=\"PRODUCTS\"]");
await expect(await headerText.getText()).toEqual("PRODUCTS");
const loginPage = new LoginPage();
const inventoryPage = new InventoryPage();
await loginPage.logInWithCredentials(Credentials.getUserCredentials(AccountType.Problem));
await expect(await inventoryPage.header.productsTitle.getText()).toEqual("PRODUCTS");
});
});
12 changes: 7 additions & 5 deletions test/specs/android/logIn_standard.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import LoginPage from "../../../src/pages/LoginPage";
import InventoryPage from "../../../src/pages/InventoryPage";
import Credentials from "../../../src/Credentials";
import {AccountType} from "../../../src/AccountType";
import {LoginPage} from "../../../src/pages/LoginPage";
import { AccountType } from "../../../src/AccountType";

describe("Log in tests", () => {

it("Log in as \"standard_user\"", async () => {
await LoginPage.logInWithCredentials(Credentials.getUserCredentials(AccountType.Standard));
const headerText = await $("//*[@text=\"PRODUCTS\"]");
await expect(await headerText.getText()).toEqual("PRODUCTS");
const loginPage = new LoginPage();
const inventoryPage = new InventoryPage();
await loginPage.logInWithCredentials(Credentials.getUserCredentials(AccountType.Standard));
await expect(await inventoryPage.header.productsTitle.getText()).toEqual("PRODUCTS");
});
});

0 comments on commit f81180c

Please sign in to comment.