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 #636

Merged
merged 5 commits into from
Feb 22, 2024
Merged
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
147 changes: 87 additions & 60 deletions tests/helpers/commands.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
require("module-alias/register");
import {
activateFirstApplication,
activateSecondApplication,
closeFirstApplication,
closeSecondApplication,
createNewUser,
getUserKey,
launchFirstApplication,
launchSecondApplication,
saveTestKeys,
} from "@helpers/commands";
Expand Down Expand Up @@ -87,7 +90,7 @@ export default async function createChatAccountsTests() {

it("Chat User B - Create Account", async () => {
// 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 @@ -147,7 +150,7 @@ export default async function createChatAccountsTests() {

it("Chat User A - Accept friend request from User A and go to chat button", async () => {
// 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 @@ -167,7 +170,7 @@ export default async function createChatAccountsTests() {

it("Chat User B - Validate friend request was accepted", async () => {
// 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 @@ -180,7 +183,7 @@ export default async function createChatAccountsTests() {

it("Chat User A - Chat screen displays Messages secured text displayed on top of conversation", async () => {
// Switch control to User A
await launchFirstApplication();
await activateFirstApplication();
await chatsTopbar.validateTopbarExists();

// Validate E2E message is displayed on top of chat
Expand Down Expand Up @@ -280,7 +283,7 @@ export default async function createChatAccountsTests() {

it("Chat User B - Wait until the other user is connected", async () => {
// Switch control to User B
await launchSecondApplication();
await activateSecondApplication();

// Go to the current list of All friends and then open a Chat conversation with ChatUserA
await friendsScreen.chatWithFriendButton.waitForExist();
Expand Down Expand Up @@ -312,4 +315,9 @@ export default async function createChatAccountsTests() {
);
await expect(timeAgo).toHaveTextContaining("ChatUserA");
});

after(async () => {
await closeFirstApplication();
await closeSecondApplication();
});
}
16 changes: 8 additions & 8 deletions tests/specs/reusable-accounts/02-chat-replies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import MessageLocal from "@screenobjects/chats/MessageLocal";
import MessageRemote from "@screenobjects/chats/MessageRemote";
import ReplyPrompt from "@screenobjects/chats/ReplyPrompt";
import {
activateFirstApplication,
closeFirstApplication,
closeSecondApplication,
launchFirstApplication,
launchSecondApplication,
loginWithTestUser,
} from "@helpers/commands";
const chatsContextMenu = new ContextMenu();
const chatsInput = new InputBar();
Expand All @@ -23,17 +23,12 @@ const messageRemote = new MessageRemote();

export default async function repliesTests() {
before(async () => {
await closeSecondApplication();
await closeFirstApplication();
await launchSecondApplication();
await loginWithTestUser();
await launchFirstApplication();
await loginWithTestUser();
await launchSecondApplication();
});

it("Chat User B - Reply popup - Validate contents and close it", async () => {
// Open Context Menu on Last Message Received and select Reply
await launchSecondApplication();
await messageRemote.openContextMenuOnLastReceived();
await chatsContextMenu.validateContextMenuIsOpen();
await chatsContextMenu.selectContextOptionReply();
Expand Down Expand Up @@ -84,7 +79,7 @@ export default async function repliesTests() {

it("Chat User A - Validate reply message contents", async () => {
// Switch control to User A
await launchFirstApplication();
await activateFirstApplication();

// With User A - Validate that reply message is received
await messageRemote.chatMessageReply.waitForExist();
Expand Down Expand Up @@ -137,4 +132,9 @@ export default async function repliesTests() {
const message = await messageLocal.getLastMessageSentText();
await expect(message).toHaveTextContaining("SelfReply");
});

after(async () => {
await closeFirstApplication();
await closeSecondApplication();
});
}
Loading
Loading