@@ -693,23 +693,25 @@ export class DeviceWrapper {
693
693
}
694
694
695
695
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 ;
699
698
700
- while ( attempt < maxRetries && ! success ) {
701
- try {
699
+ const result = await this . pollUntil (
700
+ async ( ) => {
701
+ // Find the message
702
702
const el = await this . waitForTextElementToBePresent ( {
703
703
...new MessageBody ( this , textToLookFor ) . build ( ) ,
704
704
maxWait : 1_000 ,
705
705
} ) ;
706
+
706
707
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 } ` } ;
710
709
}
711
710
712
- await this . longClick ( el , 4000 ) ;
711
+ // Attempt long click
712
+ await this . longClick ( el , 2000 ) ;
713
+
714
+ // Check if context menu appeared
713
715
const longPressSuccess = await this . waitForTextElementToBePresent ( {
714
716
strategy : 'accessibility id' ,
715
717
selector : 'Reply to message' ,
@@ -718,21 +720,22 @@ export class DeviceWrapper {
718
720
719
721
if ( longPressSuccess ) {
720
722
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 } ;
731
724
}
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 } ...` ) ,
734
735
}
735
- }
736
+ ) ;
737
+
738
+ return result ; // or whatever you want to do with it
736
739
}
737
740
738
741
public async longPressConversation ( userName : string ) {
@@ -1697,24 +1700,6 @@ export class DeviceWrapper {
1697
1700
return sentTimestamp ;
1698
1701
}
1699
1702
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
-
1718
1703
public async sendNewMessage ( user : Pick < User , 'accountID' > , message : string ) {
1719
1704
// Sender workflow
1720
1705
// Click on plus button
0 commit comments