@@ -72,56 +72,30 @@ async function changeUsernameLinkedAndroid(platform: SupportedPlatformsType) {
7272 await device1 . deleteText ( new UsernameInput ( device1 ) ) ;
7373 await device1 . inputText ( newUsername , new UsernameInput ( device1 ) ) ;
7474 await device1 . clickOnElementAll ( new TickButton ( device1 ) ) ;
75- const username = await device1 . waitForTextElementToBePresent ( {
76- strategy : 'accessibility id' ,
77- selector : 'Display name' ,
78- } ) ;
79- const changedUsername = await device1 . getTextFromElement ( username ) ;
75+ const usernameEl = await device1 . waitForTextElementToBePresent ( new UsernameSettings ( device1 ) ) ;
76+ const changedUsername = await device1 . getTextFromElement ( usernameEl ) ;
8077 if ( changedUsername === userA . userName ) {
8178 throw new Error ( 'Username change unsuccessful' ) ;
8279 }
8380 // Get the initial linked username from device2
84- const username2 = await device2 . waitForTextElementToBePresent ( {
85- strategy : 'accessibility id' ,
86- selector : 'Display name' ,
87- } ) ;
81+ const username2 = await device2 . waitForTextElementToBePresent ( new UsernameSettings ( device2 ) ) ;
8882 let currentLinkedUsername = await device2 . getTextFromElement ( username2 ) ;
8983
90- // If the linked username still equals the original, then enter a loop to try again.
91- if ( currentLinkedUsername === userA . userName ) {
92- let currentWait = 0 ;
93- const waitPerLoop = 500 ;
94- const maxWait = 50000 ;
95-
96- while ( currentWait < maxWait ) {
97- // Wait before trying again
98- await sleepFor ( waitPerLoop ) ;
99-
100- // Close the screen and navigate back to the User Settings
101- await device2 . closeScreen ( ) ;
102- await device2 . clickOnElementAll ( new UserSettings ( device2 ) ) ;
103-
104- currentWait += waitPerLoop ;
105-
106- // Retrieve the updated username
107- const linkedUsernameEl = await device2 . waitForTextElementToBePresent ( {
108- strategy : 'accessibility id' ,
109- selector : 'Display name' ,
110- } ) ;
111- currentLinkedUsername = await device2 . getTextFromElement ( linkedUsernameEl ) ;
112- // If the linked username now matches the changed username, break out.
113- if ( currentLinkedUsername === changedUsername ) {
114- console . log ( 'Username change successful' ) ;
115- break ;
116- }
117- }
118-
119- // After looping, if the linked username still equals the original, then fail.
120- if ( currentLinkedUsername === userA . userName ) {
121- throw new Error ( 'Username change unsuccessful' ) ;
122- }
123- } else {
124- console . log ( 'Username change successful' ) ;
84+ let currentWait = 0 ;
85+ const waitPerLoop = 500 ;
86+ const maxWait = 50000 ;
87+
88+ do {
89+ await sleepFor ( waitPerLoop ) ;
90+ // Close the screen and navigate back to the User Settings
91+ await device2 . closeScreen ( ) ;
92+ await device2 . clickOnElementAll ( new UserSettings ( device2 ) ) ;
93+ currentWait += waitPerLoop ;
94+ const linkedUsernameEl = await device2 . waitForTextElementToBePresent ( new UsernameSettings ( device2 ) ) ;
95+ currentLinkedUsername = await device2 . getTextFromElement ( linkedUsernameEl ) ;
96+
97+ } while ( currentLinkedUsername === userA . userName && currentWait < maxWait ) {
98+ console . log ( 'Username not changed yet' )
12599 }
126100 await closeApp ( device1 , device2 ) ;
127101}
0 commit comments