Skip to content

Commit

Permalink
Merge pull request #649 from Satellite-im/luis/chats-new-ui
Browse files Browse the repository at this point in the history
screenobject(update): improving chat message locators
  • Loading branch information
luisecm authored Mar 2, 2024
2 parents e4c16a6 + bf922b6 commit 641fd2b
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 81 deletions.
2 changes: 1 addition & 1 deletion tests/helpers/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export async function createNewUser(
await createUser.clickOnCreateAccount();

// Ensure Main Screen is displayed
await welcomeScreen.welcomeLayout.waitForExist();
await welcomeScreen.welcomeLayout.waitForExist({ timeout: 60000 });

// Workaround to ensure that user clicks on Add Someone
await welcomeScreen.clickAddSomeone();
Expand Down
68 changes: 33 additions & 35 deletions tests/screenobjects/chats/MessageLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const SELECTORS_WINDOWS = {
CHAT_MESSAGE_LOCAL: '[name="message-local"]',
CHAT_MESSAGE_REPLY: '[name="message-reply"]',
CHAT_MESSAGE_REPLY_TEXT: "<Text>",
CHAT_MESSAGE_TEXT_GROUP: '//Group[starts-with(@Name, "indicator")]',
CHAT_MESSAGE_TEXT_GROUP: '//Group[starts-with(@Name, "message-text")]',
CHAT_MESSAGE_TEXT_VALUE: "<Text>",
};

Expand Down Expand Up @@ -225,12 +225,12 @@ export default class MessageLocal extends UplinkMainScreen {
let codeMessageLocator: string = "";
if (currentDriver === MACOS_DRIVER) {
codeMessageLocator =
'//XCUIElementTypeGroup[contains(@label, "local")]//XCUIElementTypeStaticText[contains(@value, "' +
'//XCUIElementTypeGroup[(@label, "message-local")]//XCUIElementTypeStaticText[(@value, "' +
expectedLanguage +
'")]';
} else if (currentDriver === WINDOWS_DRIVER) {
codeMessageLocator =
'//Group[contains(@Name, "local")]//Text[contains(@Name, "' +
'//Group[(@Name, "message-local")]//Text[contains(@Name, "' +
expectedLanguage +
'")]';
}
Expand All @@ -243,16 +243,12 @@ export default class MessageLocal extends UplinkMainScreen {
await driver.waitUntil(
async () => {
if (currentDriver === MACOS_DRIVER) {
return await $(
'-ios class chain:**/XCUIElementTypeGroup[`label BEGINSWITH "message-text"`]/**/XCUIElementTypeStaticText[`value BEGINSWITH "' +
expectedMessage +
'"`]',
).waitForExist({ reverse: true });
return await $(`~message-text-${expectedMessage}`).waitForExist({
reverse: true,
});
} else if (currentDriver === WINDOWS_DRIVER) {
return await $(
'//Group[contains(@Name, "message-text")]//Text[contains(@Name, "' +
expectedMessage +
'")]',
`[name="message-text-${expectedMessage}"]`,
).waitForExist({ reverse: true });
}
},
Expand All @@ -267,13 +263,9 @@ export default class MessageLocal extends UplinkMainScreen {
const currentDriver = await this.getCurrentDriver();
let linkSentLocator: string = "";
if (currentDriver === MACOS_DRIVER) {
linkSentLocator =
'-ios class chain:**/XCUIElementTypeLink/XCUIElementTypeStaticText[`value BEGINSWITH "' +
expectedMessage +
'"`]';
linkSentLocator = `~message-text-${expectedMessage}`;
} else if (currentDriver === WINDOWS_DRIVER) {
linkSentLocator =
'//HyperLink[contains(@Name, "' + expectedMessage + '")]';
linkSentLocator = `[name="message-text-${expectedMessage}"]`;
}
await driver.waitUntil(async () => {
return await $(linkSentLocator).waitForExist({
Expand All @@ -287,19 +279,13 @@ export default class MessageLocal extends UplinkMainScreen {
const currentDriver = await this.getCurrentDriver();
let messageSentLocator: string = "";
if (currentDriver === MACOS_DRIVER) {
messageSentLocator =
'-ios class chain:**/XCUIElementTypeGroup[`label BEGINSWITH "message-local"`]/**/XCUIElementTypeStaticText[`value BEGINSWITH "' +
expectedMessage +
'"`]';
messageSentLocator = `~message-text-${expectedMessage}`;
} else if (currentDriver === WINDOWS_DRIVER) {
messageSentLocator =
'//Group[contains(@Name, "local")]//Text[contains(@Name, "' +
expectedMessage +
'")]';
messageSentLocator = `[name="message-text-${expectedMessage}"]`;
}
await driver.waitUntil(
async () => {
const updatedElement = await driver.$(messageSentLocator);
const updatedElement = await $(messageSentLocator);
return await updatedElement.waitForExist();
},
{
Expand All @@ -309,6 +295,24 @@ export default class MessageLocal extends UplinkMainScreen {
);
}

async getMessageLocator(expectedMessage: string) {
const currentDriver = await this.getCurrentDriver();
let messageSentLocator: string = "";
if (currentDriver === MACOS_DRIVER) {
messageSentLocator = `~message-text-${expectedMessage}`;
} else if (currentDriver === WINDOWS_DRIVER) {
messageSentLocator = `[name="message-text-${expectedMessage}"]`;
}
const messageSent = await $(messageSentLocator);
return messageSent;
}

async getMessageContents(expectedMessage: string) {
const message = await this.getMessageLocator(expectedMessage);
const messageText = await message.$(SELECTORS.CHAT_MESSAGE_TEXT_VALUE);
return messageText;
}

// Messages Sent Methods

async clickOnCopyCodeOfLastMessageSent() {
Expand Down Expand Up @@ -362,17 +366,11 @@ export default class MessageLocal extends UplinkMainScreen {
const currentDriver = await this.getCurrentDriver();
let messageSentLocator: string = "";
if (currentDriver === MACOS_DRIVER) {
messageSentLocator =
'//XCUIElementTypeGroup[contains, (@label, "local")]//XCUIElementTypeStaticText[contains(@value, "' +
expectedMessage +
'")]/../..';
messageSentLocator = `~message-text-${expectedMessage}`;
} else if (currentDriver === WINDOWS_DRIVER) {
messageSentLocator =
'//Group[contains, (@Name, "local")]//Text[contains(@Name, "' +
expectedMessage +
'")]/../..';
messageSentLocator = `[name="message-text-${expectedMessage}"]`;
}
const messageSent = await $(messageSentLocator);
const messageSent = await $(messageSentLocator).$("/../..");
await messageSent.waitForExist();
return messageSent;
}
Expand Down
58 changes: 28 additions & 30 deletions tests/screenobjects/chats/MessageRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,9 @@ export default class MessageRemote extends UplinkMainScreen {
const currentDriver = await this.getCurrentDriver();
let locator: string = "";
if (currentDriver === MACOS_DRIVER) {
locator =
'-ios class chain:**/XCUIElementTypeGroup[`label BEGINSWITH "message-remote"`]/**/XCUIElementTypeStaticText[`value BEGINSWITH "' +
expectedMessage +
'"`]';
locator = `~message-text-${expectedMessage}`;
} else if (currentDriver === WINDOWS_DRIVER) {
locator =
'//Group[contains(@Name, "remote"]//Text[contains(@Name, "' +
expectedMessage +
'")]/../..';
locator = `[name="message-text-${expectedMessage}"]`;
}
const messageReceived = await $(locator);
await messageReceived.waitForExist();
Expand Down Expand Up @@ -321,16 +315,12 @@ export default class MessageRemote extends UplinkMainScreen {
await driver.waitUntil(
async () => {
if (currentDriver === MACOS_DRIVER) {
return await $(
'-ios class chain:**/XCUIElementTypeGroup[`label BEGINSWITH "message-text"`]/**/XCUIElementTypeStaticText[`value BEGINSWITH "' +
expectedMessage +
'"`]',
).waitForExist({ reverse: true });
return await $(`~message-text-${expectedMessage}`).waitForExist({
reverse: true,
});
} else if (currentDriver === WINDOWS_DRIVER) {
return await $(
'//Group[contains(@Name, "message-text")]//Text[contains(@Name, "' +
expectedMessage +
'")]',
`[name="message-text-${expectedMessage}"]`,
).waitForExist({ reverse: true });
}
},
Expand Down Expand Up @@ -368,13 +358,9 @@ export default class MessageRemote extends UplinkMainScreen {
const currentDriver = await this.getCurrentDriver();
let linkReceivedLocator: string = "";
if (currentDriver === MACOS_DRIVER) {
linkReceivedLocator =
'-ios class chain:**/XCUIElementTypeLink/XCUIElementTypeStaticText[`value BEGINSWITH "' +
expectedMessage +
'"`]';
linkReceivedLocator = `~message-text-${expectedMessage}`;
} else if (currentDriver === WINDOWS_DRIVER) {
linkReceivedLocator =
'//HyperLink[contains(@Name, "' + expectedMessage + '")]';
linkReceivedLocator = `[name="message-text-${expectedMessage}"]`;
}
await driver.waitUntil(async () => {
return await $(linkReceivedLocator).waitForExist({
Expand All @@ -388,15 +374,9 @@ export default class MessageRemote extends UplinkMainScreen {
const currentDriver = await this.getCurrentDriver();
let receivedMessageLocator: string = "";
if (currentDriver === MACOS_DRIVER) {
receivedMessageLocator =
'-ios class chain:**/XCUIElementTypeGroup[`label BEGINSWITH "message-remote"`]/**/XCUIElementTypeStaticText[`value BEGINSWITH "' +
expectedMessage +
'"`]';
receivedMessageLocator = `~message-text-${expectedMessage}`;
} else if (currentDriver === WINDOWS_DRIVER) {
receivedMessageLocator =
'//Group[contains(@Name, "remote")]//Text[contains(@Name, "' +
expectedMessage +
'")]';
receivedMessageLocator = `[name="message-text-${expectedMessage}"]`;
}
await driver.waitUntil(async () => {
return await $(receivedMessageLocator).waitForExist({
Expand All @@ -406,6 +386,24 @@ export default class MessageRemote extends UplinkMainScreen {
});
}

async getMessageLocator(expectedMessage: string) {
const currentDriver = await this.getCurrentDriver();
let messageSentLocator: string = "";
if (currentDriver === MACOS_DRIVER) {
messageSentLocator = `~message-text-${expectedMessage}`;
} else if (currentDriver === WINDOWS_DRIVER) {
messageSentLocator = `[name="message-text-${expectedMessage}"]`;
}
const messageSent = await $(messageSentLocator);
return messageSent;
}

async getMessageContents(expectedMessage: string) {
const message = await this.getMessageLocator(expectedMessage);
const messageText = await message.$(SELECTORS.CHAT_MESSAGE_TEXT_VALUE);
return messageText;
}

// Replies Methods

async getLastReply() {
Expand Down
7 changes: 1 addition & 6 deletions tests/screenobjects/friends/FriendsScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,12 +693,7 @@ export default class FriendsScreen extends UplinkMainScreen {

async goToChatWithFriend() {
const chatWithFriendButton = await this.chatWithFriendButton;
const currentDriver = await this.getCurrentDriver();
if (currentDriver === MACOS_DRIVER) {
await leftClickOnMacOS(chatWithFriendButton);
} else if (currentDriver === WINDOWS_DRIVER) {
await leftClickOnWindows(chatWithFriendButton);
}
await chatWithFriendButton.click();
}

async goToPendingFriendsList() {
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/01-create-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export default async function createAccountTests() {
const statusOfButton = await createPin.getStatusOfCreateAccountButton();
await expect(statusOfButton).toEqual("true");
await createUser.clickOnCreateAccount();
await welcomeScreen.waitForIsShown(true);
await welcomeScreen.welcomeLayout.waitForExist({ timeout: 60000 });

// If current driver is Windows, then maximize screen
const currentDriver = await welcomeScreen.getCurrentDriver();
Expand Down
24 changes: 17 additions & 7 deletions tests/specs/reusable-accounts/04-message-input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,18 @@ export default async function messageInputTests() {
await chatsInput.clearInputBar();
await chatsInput.typeMessageOnInput("**Bolds1**");
await chatsInput.clickOnSendMessage();
await messageLocal.waitForMessageSentToExist("Bolds1");
await messageLocal.waitForMessageSentToExist("**Bolds1**");
const messageContents = await messageLocal.getMessageContents("**Bolds1**");
await expect(messageContents).toHaveText("Bolds1");
});

it("Chat Input Text - Validate texts with __ markdown are sent in bolds", async () => {
// With Chat User A, send a message with __ markdown
await chatsInput.typeMessageOnInput("__Bolds2__");
await chatsInput.clickOnSendMessage();
await messageLocal.waitForMessageSentToExist("Bolds2");
await messageLocal.waitForMessageSentToExist("__Bolds2__");
const messageContents = await messageLocal.getMessageContents("__Bolds2__");
await expect(messageContents).toHaveText("Bolds2");
});

// Needs research to implement on MacOS
Expand Down Expand Up @@ -161,10 +165,16 @@ export default async function messageInputTests() {
// With Chat User B, validate message with with ** markdown was received in bolds
await activateSecondApplication();
await chatsInput.waitForIsShown(true);
await messageRemote.waitForReceivingMessage("Bolds1");
await messageRemote.waitForReceivingMessage("**Bolds1**");
const messageContentsBolds1 =
await messageRemote.getMessageContents("**Bolds1**");
await expect(messageContentsBolds1).toHaveText("Bolds1");

// With Chat User B, validate message with with __ markdown was received in bolds
await messageRemote.waitForReceivingMessage("Bolds2");
await messageRemote.waitForReceivingMessage("__Bolds2__");
const messageContentsBolds2 =
await messageRemote.getMessageContents("__Bolds2__");
await expect(messageContentsBolds2).toHaveText("Bolds2");
});

// Needs research to implement on MacOS
Expand All @@ -191,7 +201,7 @@ export default async function messageInputTests() {
});

it("Chat User - Chat Messages containing links contents on local side", async () => {
await messageLocal.waitForLinkSentToExist("Apple");
await messageLocal.waitForLinkSentToExist("www.apple.com");

// Validate link embed contents on chat message
const linkEmbedSent = await messageLocal.getLastMessageSentLinkEmbed();
Expand All @@ -212,10 +222,10 @@ export default async function messageInputTests() {
// With Chat User B, validate message with URL starting with https:// was received as link
await activateSecondApplication();
await chatsInput.waitForIsShown(true);
await messageRemote.waitForReceivingLink("Google");
await messageRemote.waitForReceivingLink("https://www.google.com");

// With Chat User B, validate message with URL starting with www. was received as link
await messageRemote.waitForReceivingLink("Apple");
await messageRemote.waitForReceivingLink("www.apple.com");
});

it("Chat User - Chat Messages containing links contents on remote side", async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/reusable-accounts/08-sidebar-chats.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default async function sidebarChatsTests() {
await chatsInput.clickOnSendMessage();

// Message is formatted with markdown on chat conversation
await messageLocal.waitForMessageSentToExist("hello");
await messageLocal.waitForMessageSentToExist("__hello__");

// Validate last message on Sidebar is not formatted with markdown
await chatsSidebar.validateLastMessageDisplayed("__hello__");
Expand Down

0 comments on commit 641fd2b

Please sign in to comment.