Skip to content

Commit f1785b6

Browse files
committed
chore: tweak long message test
1 parent 6b1b648 commit f1785b6

File tree

5 files changed

+66
-53
lines changed

5 files changed

+66
-53
lines changed

run/test/specs/group_message_long_text.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ async function sendLongMessageGroup(platform: SupportedPlatformsType, testInfo:
3434
const replyMessage = await bob1.replyToMessage(alice, longText);
3535
await Promise.all(
3636
[alice1, charlie1].map(async device => {
37-
await device.scrollToBottom();
3837
await device.waitForTextElementToBePresent(new MessageBody(device, replyMessage));
3938
})
4039
);

run/test/specs/locators/conversation.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,22 @@ export class AttachmentsButton extends LocatorsInterface {
174174
}
175175
}
176176

177+
// TODO tie this to the message whose status we want to check (similar to EmojiReactsPill)
177178
export class OutgoingMessageStatusSent extends LocatorsInterface {
178179
public build() {
179-
return {
180-
strategy: 'accessibility id',
181-
selector: `Message sent status: Sent`,
182-
} as const;
180+
switch (this.platform) {
181+
case 'android':
182+
return {
183+
strategy: '-android uiautomator',
184+
selector:
185+
'new UiSelector().resourceId("network.loki.messenger.qa:id/messageStatusTextView").text("Sent")',
186+
} as const;
187+
case 'ios':
188+
return {
189+
strategy: 'accessibility id',
190+
selector: `Message sent status: Sent`,
191+
} as const;
192+
}
183193
}
184194
}
185195

run/test/specs/message_long_text.spec.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import type { TestInfo } from '@playwright/test';
22

33
import { longText } from '../../constants';
44
import { bothPlatformsItSeparate } from '../../types/sessionIt';
5-
import { MessageBody } from './locators/conversation';
5+
import {
6+
MessageBody,
7+
MessageInput,
8+
OutgoingMessageStatusSent,
9+
SendButton,
10+
} from './locators/conversation';
611
import { ConversationItem } from './locators/home';
712
import { open_Alice1_Bob1_friends } from './state_builder';
813
import { sleepFor } from './utils';
@@ -45,22 +50,35 @@ async function sendLongMessageIos(platform: SupportedPlatformsType, testInfo: Te
4550
}
4651

4752
async function sendLongMessageAndroid(platform: SupportedPlatformsType, testInfo: TestInfo) {
48-
// Sending a long text message
49-
// Open device and server
5053
const {
5154
devices: { alice1, bob1 },
52-
prebuilt: { alice },
55+
prebuilt: { bob },
5356
} = await open_Alice1_Bob1_friends({
5457
platform,
5558
focusFriendsConvo: true,
5659
testInfo,
5760
});
5861
// Send a long message from User A to User B
5962
await alice1.sendMessage(longText);
60-
// Reply to message (User B to User A)
61-
const sentMessage = await bob1.replyToMessage(alice, longText);
62-
// Check reply came through on alice1
63-
await alice1.waitForTextElementToBePresent(new MessageBody(alice1, sentMessage));
63+
// Bob replies
64+
await bob1.longPressMessage(longText);
65+
await bob1.clickOnByAccessibilityID('Reply to message');
66+
67+
const replyMessage = `${bob.userName} replied to ${longText}`;
68+
await bob1.inputText(replyMessage, new MessageInput(bob1));
69+
await bob1.clickOnElementAll(new SendButton(bob1));
70+
71+
// This is dumb. The CI doesn't scroll to bottom when ran through Github Actions.
72+
// If you start the emulators on the CI box yourself the test will pass. I have no idea why.
73+
if (process.env.GITHUB_ACTIONS) {
74+
await bob1.scrollToBottom();
75+
}
76+
77+
await bob1.waitForTextElementToBePresent({
78+
...new OutgoingMessageStatusSent(bob1).build(),
79+
maxWait: 50000,
80+
});
81+
await alice1.waitForTextElementToBePresent(new MessageBody(alice1, replyMessage));
6482
// Close app
6583
await closeApp(alice1, bob1);
6684
}

run/types/DeviceWrapper.ts

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -693,23 +693,25 @@ export class DeviceWrapper {
693693
}
694694

695695
public async longPressMessage(textToLookFor: string) {
696-
const maxRetries = 3;
697-
let attempt = 0;
698-
let success = false;
696+
const truncatedText =
697+
textToLookFor.length > 50 ? textToLookFor.substring(0, 50) + '...' : textToLookFor;
699698

700-
while (attempt < maxRetries && !success) {
701-
try {
699+
const result = await this.pollUntil(
700+
async () => {
701+
// Find the message
702702
const el = await this.waitForTextElementToBePresent({
703703
...new MessageBody(this, textToLookFor).build(),
704704
maxWait: 1_000,
705705
});
706+
706707
if (!el) {
707-
throw new Error(
708-
`longPress on message: ${textToLookFor} unsuccessful, couldn't find message`
709-
);
708+
return { success: false, error: `Couldn't find message: ${truncatedText}` };
710709
}
711710

712-
await this.longClick(el, 4000);
711+
// Attempt long click
712+
await this.longClick(el, 2000);
713+
714+
// Check if context menu appeared
713715
const longPressSuccess = await this.waitForTextElementToBePresent({
714716
strategy: 'accessibility id',
715717
selector: 'Reply to message',
@@ -718,21 +720,22 @@ export class DeviceWrapper {
718720

719721
if (longPressSuccess) {
720722
this.log('LongClick successful');
721-
success = true; // Exit the loop if successful
722-
} else {
723-
throw new Error(`longPress on message: ${textToLookFor} unsuccessful`);
724-
}
725-
} catch (error) {
726-
attempt++;
727-
if (attempt >= maxRetries) {
728-
throw new Error(
729-
`Longpress on message: ${textToLookFor} unsuccessful after ${maxRetries} attempts, ${(error as Error).toString()}`
730-
);
723+
return { success: true, data: el };
731724
}
732-
this.log(`Longpress attempt ${attempt} failed. Retrying...`);
733-
await sleepFor(1000);
725+
726+
return {
727+
success: false,
728+
error: `Long press didn't show context menu for: ${truncatedText}`,
729+
};
730+
},
731+
{
732+
maxWait: 10_000,
733+
pollInterval: 1000,
734+
onAttempt: attempt => this.log(`Longpress attempt ${attempt}...`),
734735
}
735-
}
736+
);
737+
738+
return result; // or whatever you want to do with it
736739
}
737740

738741
public async longPressConversation(userName: string) {
@@ -1697,24 +1700,6 @@ export class DeviceWrapper {
16971700
return sentTimestamp;
16981701
}
16991702

1700-
public async waitForSentConfirmation() {
1701-
let pendingStatus = await this.waitForTextElementToBePresent({
1702-
strategy: 'accessibility id',
1703-
selector: 'Message sent status: Sending',
1704-
});
1705-
const failedStatus = await this.waitForTextElementToBePresent({
1706-
strategy: 'accessibility id',
1707-
selector: 'Message sent status: Failed to send',
1708-
});
1709-
if (pendingStatus || failedStatus) {
1710-
await sleepFor(100);
1711-
pendingStatus = await this.waitForTextElementToBePresent({
1712-
strategy: 'accessibility id',
1713-
selector: 'Message sent status: Sending',
1714-
});
1715-
}
1716-
}
1717-
17181703
public async sendNewMessage(user: Pick<User, 'accountID'>, message: string) {
17191704
// Sender workflow
17201705
// Click on plus button

run/types/testing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export type UiAutomatorQuery =
166166
| 'new UiScrollable(new UiSelector().className("android.widget.ScrollView")).scrollIntoView(new UiSelector().resourceId("path-menu-item"))'
167167
| 'new UiScrollable(new UiSelector().className("android.widget.ScrollView")).scrollIntoView(new UiSelector().text("Select app icon"))'
168168
| 'new UiScrollable(new UiSelector().className("android.widget.ScrollView")).scrollIntoView(new UiSelector().textStartsWith("Version"))'
169+
| 'new UiSelector().resourceId("network.loki.messenger.qa:id/messageStatusTextView").text("Sent")'
169170
| 'new UiSelector().text("Enter your display name")'
170171
| `new UiSelector().resourceId("Conversation header name").childSelector(new UiSelector().resourceId("pro-badge-text"))`
171172
| `new UiSelector().text(${string})`;

0 commit comments

Comments
 (0)