Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(update): update methods for activate launch app #637

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 89 additions & 62 deletions tests/helpers/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export async function createNewUser(
await createPin.unlockLayout.waitForExist();

// Enter pin for test user
await createPin.enterPin("1234");
await createPin.enterPinOnCreateAccount("1234");
await createPin.createAccountButton.waitForEnabled();
await createPin.clickOnCreateAccount();

Expand Down Expand Up @@ -142,7 +142,7 @@ export async function loginWithTestUser() {
// Enter pin for test user
const unlockScreen = await createPin.unlockLayout;
await unlockScreen.waitForExist();
await createPin.enterPin("1234");
await createPin.enterPinOnLogin("1234");
await createPin.unlockLayout.waitForExist({ reverse: true });
}

Expand Down Expand Up @@ -196,92 +196,58 @@ export async function launchApplication(
appLocation: string = WINDOWS_APP,
) {
if (process.env.DRIVER === WINDOWS_DRIVER) {
await driver.executeScript("windows: launchApp", [
{
app: join(process.cwd(), appLocation),
},
]);
await launchAppWindows(appLocation);
} else if (process.env.DRIVER === MACOS_DRIVER) {
await driver.executeScript("macos: launchApp", [
{
bundleId: bundle,
arguments: ["--discovery", "disable", "--path", homedir() + "/.uplink"],
},
]);
await launchAppMacOS(bundle);
await browser.pause(5000);
}
}

export async function launchFirstApplication() {
await driver.executeScript("macos: launchApp", [
{
bundleId: MACOS_USER_A_BUNDLE_ID,
arguments: ["--discovery", "disable", "--path", homedir() + "/.uplink"],
},
]);
await launchAppMacOS(MACOS_USER_A_BUNDLE_ID);
await browser.pause(5000);
await loginWithTestUser();
}

export async function launchSecondApplication() {
await driver.executeScript("macos: launchApp", [
{
bundleId: MACOS_USER_B_BUNDLE_ID,
arguments: [
"--discovery",
"disable",
"--path",
homedir() + "/.uplinkUserB",
],
},
]);
export async function launchSecondApplication(existingUser: boolean = true) {
await launchAppMacOS(MACOS_USER_B_BUNDLE_ID, "/.uplinkUserB");
await browser.pause(5000);
if (existingUser === true) {
await loginWithTestUser();
}
}

export async function activateFirstApplication() {
if (process.env.DRIVER === WINDOWS_DRIVER) {
await driver.executeScript("windows: activateApp", [
{
app: WINDOWS_APP,
},
]);
await activateAppWindows(WINDOWS_APP);
} else if (process.env.DRIVER === MACOS_DRIVER) {
await driver.executeScript("macos: activateApp", [
{
bundleId: MACOS_USER_A_BUNDLE_ID,
},
]);
const appState = await queryAppStateMacOS(MACOS_USER_A_BUNDLE_ID);
if (appState === 1) {
await launchFirstApplication();
} else {
await activateAppMacOS(MACOS_USER_A_BUNDLE_ID);
}
}
}

export async function activateSecondApplication() {
if (process.env.DRIVER === WINDOWS_DRIVER) {
await driver.executeScript("windows: activateApp", [
{
app: WINDOWS_APP,
},
]);
await activateAppWindows(WINDOWS_APP);
} else if (process.env.DRIVER === MACOS_DRIVER) {
await driver.executeScript("macos: activateApp", [
{
bundleId: MACOS_USER_B_BUNDLE_ID,
},
]);
const appState = await queryAppStateMacOS(MACOS_USER_B_BUNDLE_ID);
if (appState === 1) {
await launchSecondApplication();
} else {
await activateAppMacOS(MACOS_USER_B_BUNDLE_ID);
}
}
}

export async function closeApplication() {
if (process.env.DRIVER === WINDOWS_DRIVER) {
await driver.executeScript("windows: closeApp", [
{
app: WINDOWS_APP,
},
]);
await closeAppWindows(WINDOWS_APP);
} else if (process.env.DRIVER === MACOS_DRIVER) {
await driver.executeScript("macos: terminateApp", [
{
bundleId: MACOS_BUNDLE_ID,
},
]);
await closeAppMacOS(MACOS_BUNDLE_ID);
}
}

Expand Down Expand Up @@ -309,6 +275,67 @@ export async function maximizeWindow() {
}
}

export async function activateAppMacOS(bundle: string) {
await driver.executeScript("macos: activateApp", [
{
bundleId: bundle,
},
]);
}

export async function activateAppWindows(appPath: string) {
await driver.executeScript("windows: activateApp", [
{
app: appPath,
},
]);
}

export async function closeAppWindows(appPath: string) {
await driver.executeScript("windows: closeApp", [
{
app: appPath,
},
]);
}

export async function closeAppMacOS(bundle: string) {
await driver.executeScript("macos: terminateApp", [
{
bundleId: bundle,
},
]);
}

export async function launchAppMacOS(
bundle: string,
relativePath: string = "/.uplink",
) {
await driver.executeScript("macos: launchApp", [
{
bundleId: bundle,
arguments: ["--discovery", "disable", "--path", homedir() + relativePath],
},
]);
}

export async function launchAppWindows(appLocation: string) {
await driver.executeScript("windows: launchApp", [
{
app: join(process.cwd(), appLocation),
},
]);
}

export async function queryAppStateMacOS(bundle: string) {
const queryAppState = await driver.executeScript("macos: queryAppState", [
{
bundleId: bundle,
},
]);
return queryAppState;
}

// MacOS driver helper functions

export async function clickOnSwitchMacOS(element: WebdriverIO.Element) {
Expand Down Expand Up @@ -425,7 +452,7 @@ export async function leftClickOnMacOS(locator: WebdriverIO.Element) {

export async function rightClickOnMacOS(locator: WebdriverIO.Element) {
const elementId = await locator.elementId;
await driver.executeScript("macos: rightClick", [
await driver.executeScript("macos: hover", [
{
elementId: elementId,
},
Expand Down
11 changes: 6 additions & 5 deletions tests/helpers/debugging.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require("module-alias/register");
import {
launchFirstApplication,
createNewUser,
getUserKey,
launchSecondApplication,
saveTestKeys,
activateFirstApplication,
activateSecondApplication,
} from "./commands";
import CreatePinScreen from "@screenobjects/account-creation/CreatePinScreen";
import FriendsScreen from "@screenobjects/friends/FriendsScreen";
Expand Down Expand Up @@ -64,7 +65,7 @@ export async function setupBeforeCreateGroupTests() {
await friendsScreen.validateFriendsScreenIsShown();

// Launch second application
await launchSecondApplication();
await launchSecondApplication(false);

// Create a new account and go to Settings Profile
await createPin.waitForIsShown(true);
Expand Down Expand Up @@ -116,7 +117,7 @@ export async function setupBeforeCreateGroupTests() {
await friendsScreen.validateAllFriendsListIsShown();

// Switch control to User A
await launchFirstApplication();
await activateFirstApplication();

// With User A - Go to pending requests list, wait for receiving the friend request and accept it
await friendsScreen.hoverOnPendingListButton();
Expand All @@ -134,7 +135,7 @@ export async function setupBeforeCreateGroupTests() {
await friendsScreen.chatWithFriendButton.click();

// Switch control to User B
await launchSecondApplication();
await activateSecondApplication();

// With User B - Go to pending requests list, wait for receiving the friend request and accept it
await friendsScreen.waitUntilUserAcceptedFriendRequest();
Expand All @@ -145,7 +146,7 @@ export async function setupBeforeCreateGroupTests() {
await friendsScreen.validateAllFriendsListIsNotEmpty();

// Switch control to User A
await launchFirstApplication();
await activateFirstApplication();
await chatsTopbar.validateTopbarExists();
}

Expand Down
17 changes: 14 additions & 3 deletions tests/screenobjects/account-creation/CreatePinScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,20 @@ export default class CreatePinScreen extends UplinkMainScreen {
return $(SELECTORS.UNLOCK_LAYOUT).$(SELECTORS.UNLOCK_WARNING_PARAGRAPH);
}

async enterPin(pin: string) {
(await this.pinInput).click();
await this.pinInput.setValue(pin);
async enterPinOnLogin(pin: string) {
const pinInput = await this.pinInput;
await pinInput.setValue(pin);
}

async enterPinOnCreateAccount(pin: string) {
await this.pinInput.waitForExist();
const pinInput = await this.pinInput;
await pinInput.clearValue();
await pinInput.setValue(pin);
const addSomeoneInputText = await pinInput.getText();
if (addSomeoneInputText !== pin) {
await this.enterPinOnCreateAccount(pin);
}
}

async clickOnCreateAccount() {
Expand Down
10 changes: 5 additions & 5 deletions tests/specs/01-create-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default async function createAccountTests() {

it("Enter Pin Screen - Enter an empty pin", async () => {
await createPin.unlockWarningParagraph.waitForExist();
await createPin.enterPin("1");
await createPin.enterPinOnCreateAccount("1");

await createPin.pinInput.clearValue();

Expand All @@ -71,7 +71,7 @@ export default async function createAccountTests() {
});

it("Enter Pin Screen - Enter a pin with less than 4 characters", async () => {
await createPin.enterPin("123");
await createPin.enterPinOnCreateAccount("123");
await createPin.inputError.waitForExist();
const inputErrorText = await createPin.inputErrorText;
await expect(inputErrorText).toHaveText(
Expand All @@ -84,7 +84,7 @@ export default async function createAccountTests() {

// Skipping test failing when appium stops typing
xit("Enter Pin Screen - Enter a pin with more than 32 characters", async () => {
await createPin.enterPin("12345678901234567890123456789012");
await createPin.enterPinOnCreateAccount("12345678901234567890123456789012");

await createPin.inputError.waitForExist();
const inputErrorText = await createPin.inputErrorText;
Expand All @@ -100,7 +100,7 @@ export default async function createAccountTests() {
xit("Enter Pin Screen - Enter a pin with spaces", async () => {
// Enter pin value with spaces
await createPin.pinInput.click();
await createPin.enterPin("1234" + " ");
await createPin.enterPinOnCreateAccount("1234" + " ");
await createPin.inputError.waitForExist();
const inputErrorText = await createPin.inputErrorText;
await expect(inputErrorText).toHaveText("Spaces are not allowed.");
Expand All @@ -110,7 +110,7 @@ export default async function createAccountTests() {
});

it("Enter Pin Screen - Enter a valid pin and continue creating a username", async () => {
await createPin.enterPin("1234");
await createPin.enterPinOnCreateAccount("1234");
await createPin.waitUntilCreateAccountButtonIsEnabled();
const statusOfButton = await createPin.getStatusOfCreateAccountButton();
await expect(statusOfButton).toEqual("true");
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/16-import-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async function importAccountTests() {

// Validate Enter Pin Screen is displayed and enter a valid pin
await createPin.waitForIsShown(true);
await createPin.enterPin("1234");
await createPin.enterPinOnCreateAccount("1234");
await createPin.waitUntilCreateAccountButtonIsEnabled();
await createPin.clickOnCreateAccount();
});
Expand Down
Loading
Loading