Skip to content

Commit

Permalink
screenobject(update): update waitUntil methods and click on emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
luisecm committed Nov 7, 2023
1 parent 8f2123a commit 446e3f4
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 79 deletions.
28 changes: 14 additions & 14 deletions tests/helpers/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
const { readFileSync, rmSync, writeFileSync } = require("fs");
const { execSync } = require("child_process");
const fsp = require("fs").promises;
const { mouse, Button } = require("@nut-tree/nut-js")
const { mouse, Button } = require("@nut-tree/nut-js");
let createPinFirstUser = new CreatePinScreen(USER_A_INSTANCE);
let createPinSecondUser = new CreatePinScreen(USER_B_INSTANCE);
let createUserFirstUser = new CreateUserScreen(USER_A_INSTANCE);
Expand All @@ -35,7 +35,7 @@ export async function deleteCache() {
console.log("Deleted user cache successfully");
} catch (error) {
console.error(
`Got an error trying to delete the user cache files: ${error.message}`
`Got an error trying to delete the user cache files: ${error.message}`,
);
}
}
Expand All @@ -50,7 +50,7 @@ export async function grabCacheFolder(username: string, instance: string) {
console.log("Copied user cache successfully");
} catch (error) {
console.error(
`Got an error trying to copy the user cache files: ${error.message}`
`Got an error trying to copy the user cache files: ${error.message}`,
);
}
}
Expand All @@ -67,7 +67,7 @@ export async function loadTestUserData(user: string, instance: string) {
console.log("Copied user cache successfully");
} catch (error) {
console.error(
`Got an error trying to copy the user cache files: ${error.message}`
`Got an error trying to copy the user cache files: ${error.message}`,
);
}
}
Expand All @@ -88,7 +88,7 @@ export async function getUserKey(username: string, instance: string) {
export async function saveTestKeys(
username: string,
didkey: string,
instance: string
instance: string,
) {
// Save JSON file with keys
const currentDriver = await driver[instance].capabilities.automationName;
Expand Down Expand Up @@ -263,7 +263,7 @@ export async function maximizeWindow(instance: string) {

export async function clickOnSwitchMacOS(
element: WebdriverIO.Element,
instance: string
instance: string,
) {
const currentInstance = await browser.getInstance(instance);
const elementLocator = await currentInstance.$(element);
Expand All @@ -288,7 +288,7 @@ export async function getClipboardMacOS() {

export async function hoverOnMacOS(
locator: WebdriverIO.Element,
instance: string
instance: string,
) {
// Hover on X and Y coordinates previously retrieved
await driver[instance].executeScript("macos: hover", [
Expand Down Expand Up @@ -323,7 +323,7 @@ export async function saveFileOnMacOS(filename: string, instance: string) {

export async function selectFileOnMacos(
relativePath: string,
instance: string
instance: string,
) {
const currentInstance = await browser.getInstance(instance);

Expand Down Expand Up @@ -366,7 +366,7 @@ export async function selectFileOnMacos(

export async function rightClickOnMacOS(
locator: WebdriverIO.Element,
instance: string
instance: string,
) {
await driver[instance].executeScript("macos: rightClick", [
{
Expand All @@ -379,14 +379,14 @@ export async function rightClickOnMacOS(

export async function hoverOnWindows(
locator: WebdriverIO.Element,
instance: string
instance: string,
) {
await driver[instance].moveToElement(locator.elementId);
}

export async function rightClickOnWindows(
locator: WebdriverIO.Element,
instance: string
instance: string,
) {
await driver[instance].moveToElement(locator.elementId);
await mouse.click(Button.RIGHT);
Expand All @@ -395,7 +395,7 @@ export async function rightClickOnWindows(
export async function saveFileOnWindows(
filename: string,
uplinkContext: string,
instance: string
instance: string,
) {
// Get the filepath to select on browser
const filepath = join(process.cwd(), "\\tests\\fixtures\\", filename);
Expand All @@ -415,7 +415,7 @@ export async function saveFileOnWindows(

// Type file location and hit enter
const editInput = await driver[instance].$(
"/Window/Pane[1]/ComboBox[1]/Edit"
"/Window/Pane[1]/ComboBox[1]/Edit",
);
await editInput.clearValue();
await editInput.setValue(filename + "\uE007");
Expand All @@ -429,7 +429,7 @@ export async function saveFileOnWindows(
export async function selectFileOnWindows(
relativePath: string,
uplinkContext: string,
instance: string
instance: string,
) {
// Get the filepath to select on browser
const filepath = join(process.cwd(), relativePath);
Expand Down
2 changes: 1 addition & 1 deletion tests/screenobjects/chats/ChatsLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class ChatsLayout extends UplinkMainScreen {
async validateChatLayoutIsShown() {
await driver[this.executor].waitUntil(
async () => {
return await this.chatLayout;
return await this.chatLayout.waitForExist();
},
{
timeout: 15000,
Expand Down
10 changes: 7 additions & 3 deletions tests/screenobjects/chats/ChatsSidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export default class ChatsSidebar extends UplinkMainScreen {
async waitForReceivingMessageOnSidebar() {
await driver[this.executor].waitUntil(
async () => {
return await this.sidebarChatsUserStatusValue;
return await this.sidebarChatsUserStatusValue.waitForExist();
},
{
timeout: 60000,
Expand Down Expand Up @@ -456,7 +456,10 @@ export default class ChatsSidebar extends UplinkMainScreen {
const element = await this.getExistingElementByAriaLabel(groupname);
await driver[this.executor].waitUntil(
async () => {
return await this.instance.$(SELECTORS.SIDEBAR).$(element);
return await this.instance
.$(SELECTORS.SIDEBAR)
.$(element)
.waitForExist();
},
{
timeout: 60000,
Expand Down Expand Up @@ -548,7 +551,8 @@ export default class ChatsSidebar extends UplinkMainScreen {
return await userLocator
.$(SELECTORS.SIDEBAR_CHATS_USER_IMAGE_WRAP)
.$(SELECTORS.SIDEBAR_CHATS_USER_IMAGE)
.$(SELECTORS.SIDEBAR_CHATS_USER_ONLINE_INDICATOR);
.$(SELECTORS.SIDEBAR_CHATS_USER_ONLINE_INDICATOR)
.waitForExist();
},
{
timeout: 60000,
Expand Down
22 changes: 11 additions & 11 deletions tests/screenobjects/chats/ComposeAttachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,25 @@ export default class ComposeAttachments extends UplinkMainScreen {

get composeAttachmentsFileIcon() {
return this.composeAttachmentsFileEmbed.$(
SELECTORS.COMPOSE_ATTACHMENTS_FILE_ICON
SELECTORS.COMPOSE_ATTACHMENTS_FILE_ICON,
);
}

get composeAttachmentsFileInfo() {
return this.composeAttachmentsFileEmbed.$(
SELECTORS.COMPOSE_ATTACHMENTS_FILE_INFO
SELECTORS.COMPOSE_ATTACHMENTS_FILE_INFO,
);
}

get composeAttachmentsFileMeta() {
return this.composeAttachmentsFileEmbed.$(
SELECTORS.COMPOSE_ATTACHMENTS_FILE_META
SELECTORS.COMPOSE_ATTACHMENTS_FILE_META,
);
}

get composeAttachmentsFileName() {
return this.composeAttachmentsFileEmbed.$(
SELECTORS.COMPOSE_ATTACHMENTS_FILE_NAME
SELECTORS.COMPOSE_ATTACHMENTS_FILE_NAME,
);
}

Expand All @@ -92,17 +92,17 @@ export default class ComposeAttachments extends UplinkMainScreen {

get composeAttachmentsInputErrorText() {
return this.composeAttachmentsInputError.$(
SELECTORS.COMPOSE_ATTACHMENTS_INPUT_ERROR_TEXT
SELECTORS.COMPOSE_ATTACHMENTS_INPUT_ERROR_TEXT,
);
}

async clickOnDeleteAttachment(attachment: number) {
// Get the locator of attachment to delete by passing the index
const attachmentToDelete = await this.instance.$$(
SELECTORS.COMPOSE_ATTACHMENTS_FILE_EMBED
SELECTORS.COMPOSE_ATTACHMENTS_FILE_EMBED,
)[attachment];
const deleteAttachmentButton = await attachmentToDelete.$(
SELECTORS.COMPOSE_ATTACHMENTS_BUTTON
SELECTORS.COMPOSE_ATTACHMENTS_BUTTON,
);
await deleteAttachmentButton.click();
}
Expand All @@ -116,7 +116,7 @@ export default class ComposeAttachments extends UplinkMainScreen {
const composeAttachments = await this.composeAttachments;
await composeAttachments.waitForExist();
const filesAttached = await this.instance.$$(
SELECTORS.COMPOSE_ATTACHMENTS_FILE_EMBED
SELECTORS.COMPOSE_ATTACHMENTS_FILE_EMBED,
);
let results = [];
for (let fileAttached of filesAttached) {
Expand All @@ -134,18 +134,18 @@ export default class ComposeAttachments extends UplinkMainScreen {
const composeAttachmentsFileEmbed = await this.composeAttachmentsFileEmbed;
await driver[this.executor].waitUntil(
async () => {
return await composeAttachmentsFileEmbed;
return await composeAttachmentsFileEmbed.waitForExist();
},
{
timeout: 15000,
timeoutMsg: "Attachment file was not added after 15 seconds",
}
},
);
}

async validateAttachmentWithFileNameIsAdded(
fileName: string,
expectedAssertion: boolean
expectedAssertion: boolean,
) {
const attachmentsList = await this.getListOfAttachmentsEmbed();
const includesAttachment = await attachmentsList.includes(fileName);
Expand Down
20 changes: 11 additions & 9 deletions tests/screenobjects/chats/CreateGroupChat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {keyboard, Key} = require("@nut-tree/nut-js");
const { keyboard, Key } = require("@nut-tree/nut-js");
import "module-alias/register";
import { getClipboardMacOS } from "@helpers/commands";
import {
Expand Down Expand Up @@ -187,7 +187,7 @@ export default class CreateGroupChat extends UplinkMainScreen {
async getFriendFromListIndicatorOffline(username: string) {
const friendLocator = await this.getFriendFromListLocator(username);
const indicatorOffline = await friendLocator.$(
SELECTORS.FRIEND_INDICATOR_OFFLINE
SELECTORS.FRIEND_INDICATOR_OFFLINE,
);
await indicatorOffline.waitForExist();
return indicatorOffline;
Expand All @@ -197,25 +197,27 @@ export default class CreateGroupChat extends UplinkMainScreen {
const friendLocator = await this.getFriendFromListLocator(username);
await driver[this.executor].waitUntil(
async () => {
return await friendLocator.$(SELECTORS.FRIEND_INDICATOR_ONLINE);
return await friendLocator
.$(SELECTORS.FRIEND_INDICATOR_ONLINE)
.waitForExist();
},
{
timeout: 15000,
timeoutMsg:
"Expected indicator online was never displayed on Create Group Users List after 15 seconds",
}
},
);

const indicatorOnline = await friendLocator.$(
SELECTORS.FRIEND_INDICATOR_ONLINE
SELECTORS.FRIEND_INDICATOR_ONLINE,
);
return indicatorOnline;
}

async getFriendFromListUserImageProfile(username: string) {
const friendLocator = await this.getFriendFromListLocator(username);
const userImageProfile = await friendLocator.$(
SELECTORS.FRIEND_USER_IMAGE_PROFILE
SELECTORS.FRIEND_USER_IMAGE_PROFILE,
);
await userImageProfile.waitForExist();
return userImageProfile;
Expand All @@ -231,7 +233,7 @@ export default class CreateGroupChat extends UplinkMainScreen {
.$(
'//XCUIElementTypeGroup[@label="friend-name"]/XCUIElementTypeStaticText[contains(@value, "' +
username +
'")]/../..'
'")]/../..',
);
} else if (currentDriver === WINDOWS_DRIVER) {
friendLocator = await this.instance
Expand All @@ -240,7 +242,7 @@ export default class CreateGroupChat extends UplinkMainScreen {
.$(
'//Group[@Name="friend-name"]/Text[contains(@Name, "' +
username +
'")]/../..'
'")]/../..',
);
}
return friendLocator;
Expand All @@ -256,7 +258,7 @@ export default class CreateGroupChat extends UplinkMainScreen {
async getFriendFromListUserImageWrap(username: string) {
const friendLocator = await this.getFriendFromListLocator(username);
const userImageWrap = await friendLocator.$(
SELECTORS.FRIEND_USER_IMAGE_WRAP
SELECTORS.FRIEND_USER_IMAGE_WRAP,
);
await userImageWrap.waitForExist();
return userImageWrap;
Expand Down
12 changes: 8 additions & 4 deletions tests/screenobjects/chats/EditGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export default class EditGroup extends UplinkMainScreen {
)[0];
await driver[this.executor].waitUntil(
async () => {
return await firstAddButton;
return await firstAddButton.waitForExist();
},
{
timeout: 15000,
Expand All @@ -268,7 +268,7 @@ export default class EditGroup extends UplinkMainScreen {
)[0];
await driver[this.executor].waitUntil(
async () => {
return await removeParticipantButton;
return await removeParticipantButton.waitForExist();
},
{
timeout: 15000,
Expand Down Expand Up @@ -348,7 +348,9 @@ export default class EditGroup extends UplinkMainScreen {
const userLocator = await this.getParticipantContainerLocator(participant);
await driver[this.executor].waitUntil(
async () => {
return await userLocator.$(SELECTORS.PARTICIPANT_USER_INDICATOR_ONLINE);
return await userLocator
.$(SELECTORS.PARTICIPANT_USER_INDICATOR_ONLINE)
.waitForExist();
},
{
timeout: 60000,
Expand Down Expand Up @@ -440,7 +442,9 @@ export default class EditGroup extends UplinkMainScreen {
async validateParticipantIndicatorOnline(username: string) {
await driver[this.executor].waitUntil(
async () => {
return await this.getParticipantIndicatorOnline(username);
return await this.getParticipantIndicatorOnline(
username,
).waitForExist();
},
{
timeout: 60000,
Expand Down
3 changes: 2 additions & 1 deletion tests/screenobjects/chats/EmojiSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
USER_A_INSTANCE,
} from "@helpers/constants";
import UplinkMainScreen from "@screenobjects/UplinkMainScreen";
const { mouse, Button } = require("@nut-tree/nut-js");

const currentOS = driver[USER_A_INSTANCE].capabilities.automationName;
let SELECTORS = {};
Expand Down Expand Up @@ -72,6 +73,6 @@ export default class EmojiSelector extends UplinkMainScreen {
.$(emojiLocator);
}
await this.hoverOnElement(emojiElement);
await emojiElement.click();
await mouse.click(Button.LEFT);
}
}
Loading

0 comments on commit 446e3f4

Please sign in to comment.