@@ -62,19 +62,31 @@ class InAppMessageIntegrationTests: IntegrationTestBase {
6262        checkMessagesButton. tap ( ) 
6363        //screenshotCapture.captureScreenshot(named: "02b-check-messages-tapped")
6464
65-         // Step 2: Wait for in-app message to display
65+         // Step 2: Wait for in-app message to display with smart retry 
6666        var  webView  =  app. descendants ( matching:  . webView) . element ( boundBy:  0 ) 
67-         print ( " ⏳ First Waiting for in-app message... " ) 
68-         var  count  =  0 
69-         while  webView. exists ==  false  { 
70-             print ( " ⏳ Waiting for in-app message  \( count) ... " ) 
71-             count +=  1 
72-             checkMessagesButton. tap ( ) 
67+         print ( " ⏳ Waiting for in-app message to display... " ) 
68+         
69+         // Smart retry: wait for button to be ready, then tap with delay
70+         var  retryCount  =  0 
71+         let  maxRetries  =  5 
72+         while  !webView. exists && retryCount <  maxRetries { 
73+             // Wait for button to be enabled before retapping
74+             if  checkMessagesButton. isEnabled { 
75+                 print ( " 🔄 Retry  \( retryCount +  1 ) / \( maxRetries) : Tapping check-messages-button... " ) 
76+                 checkMessagesButton. tap ( ) 
77+                 retryCount +=  1 
78+                 
79+                 // Give time for network request to complete before checking again
80+                 sleep ( 2 ) 
81+             }  else  { 
82+                 print ( " ⏸️ Button not enabled, waiting... " ) 
83+                 sleep ( 1 ) 
84+             } 
7385        } 
7486
7587        XCTAssertTrue ( 
76-             webView. waitForExistence ( timeout:  standardTimeout ) , 
77-             " In-app message should appear " 
88+             webView. waitForExistence ( timeout:  5 ) , 
89+             " In-app message should appear after retries  " 
7890        ) 
7991        //screenshotCapture.captureScreenshot(named: "03-inapp-display-inapp-displayed")
8092
@@ -145,20 +157,30 @@ class InAppMessageIntegrationTests: IntegrationTestBase {
145157        checkMessagesButton. tap ( ) 
146158        //screenshotCapture.captureScreenshot(named: "02b-check-messages-tapped")
147159
148-         // Step 2: Wait for in-app message to display
160+         // Step 2: Wait for in-app message to display with smart retry 
149161        webView =  app. descendants ( matching:  . webView) . element ( boundBy:  0 ) 
150-         
151-         print ( " ⏳ First Waiting for in-app message... " ) 
152-         count =  0 
153-         while  webView. exists ==  false  { 
154-             print ( " ⏳ Waiting for in-app message  \( count) ... " ) 
155-             count +=  1 
156-             checkMessagesButton. tap ( ) 
162+         print ( " ⏳ Waiting for TestView in-app message to display... " ) 
163+         
164+         // Smart retry: wait for button to be ready, then tap with delay
165+         retryCount =  0 
166+         while  !webView. exists && retryCount <  maxRetries { 
167+             // Wait for button to be enabled before retapping
168+             if  checkMessagesButton. isEnabled { 
169+                 print ( " 🔄 Retry  \( retryCount +  1 ) / \( maxRetries) : Tapping check-messages-button... " ) 
170+                 checkMessagesButton. tap ( ) 
171+                 retryCount +=  1 
172+                 
173+                 // Give time for network request to complete before checking again
174+                 sleep ( 2 ) 
175+             }  else  { 
176+                 print ( " ⏸️ Button not enabled, waiting... " ) 
177+                 sleep ( 1 ) 
178+             } 
157179        } 
158180
159181        XCTAssertTrue ( 
160-             webView. waitForExistence ( timeout:  standardTimeout ) , 
161-             " In-app message should appear " 
182+             webView. waitForExistence ( timeout:  5 ) , 
183+             " In-app message should appear after retries  " 
162184        ) 
163185        //screenshotCapture.captureScreenshot(named: "03-testview-inapp-displayed")
164186
@@ -321,21 +343,30 @@ class InAppMessageIntegrationTests: IntegrationTestBase {
321343        checkMessagesButton. tap ( ) 
322344        //screenshotCapture.captureScreenshot(named: "03-check-messages-tapped")
323345
324-         // Step 2: Wait for in-app message to display
346+         // Step 2: Wait for in-app message to display with smart retry 
325347        print ( " ⏳ Waiting for in-app message... " ) 
326348        webView =  app. descendants ( matching:  . webView) . element ( boundBy:  0 ) 
327349
328-         print ( " ⏳ First Waiting for in-app message... " ) 
329-         count =  0 
330-         while  webView. exists ==  false  { 
331-             print ( " ⏳ Waiting for in-app message  \( count) ... " ) 
332-             count +=  1 
333-             checkMessagesButton. tap ( ) 
350+         // Smart retry: wait for button to be ready, then tap with delay
351+         retryCount =  0 
352+         while  !webView. exists && retryCount <  maxRetries { 
353+             // Wait for button to be enabled before retapping
354+             if  checkMessagesButton. isEnabled { 
355+                 print ( " 🔄 Retry  \( retryCount +  1 ) / \( maxRetries) : Tapping check-messages-button... " ) 
356+                 checkMessagesButton. tap ( ) 
357+                 retryCount +=  1 
358+                 
359+                 // Give time for network request to complete before checking again
360+                 sleep ( 2 ) 
361+             }  else  { 
362+                 print ( " ⏸️ Button not enabled, waiting... " ) 
363+                 sleep ( 1 ) 
364+             } 
334365        } 
335366
336367        XCTAssertTrue ( 
337-             webView. waitForExistence ( timeout:  standardTimeout ) , 
338-             " In-app message should appear " 
368+             webView. waitForExistence ( timeout:  5 ) , 
369+             " In-app message should appear after retries  " 
339370        ) 
340371        //screenshotCapture.captureScreenshot(named: "04-inapp-displayed")
341372
@@ -490,21 +521,30 @@ class InAppMessageIntegrationTests: IntegrationTestBase {
490521        checkMessagesButton. tap ( ) 
491522        //screenshotCapture.captureScreenshot(named: "02b-check-messages-tapped")
492523
493-         // Step 2: Wait for in-app message to display
494-         print ( " ⏳ Waiting for TestView  in-app message... " ) 
524+         // Step 2: Wait for in-app message to display with smart retry 
525+         print ( " ⏳ Waiting for Custom Action  in-app message... " ) 
495526        webView =  app. descendants ( matching:  . webView) . element ( boundBy:  0 ) 
496527
497-         print ( " ⏳ First Waiting for in-app message... " ) 
498-         count =  0 
499-         while  webView. exists ==  false  { 
500-             print ( " ⏳ Waiting for in-app message  \( count) ... " ) 
501-             count +=  1 
502-             checkMessagesButton. tap ( ) 
528+         // Smart retry: wait for button to be ready, then tap with delay
529+         retryCount =  0 
530+         while  !webView. exists && retryCount <  maxRetries { 
531+             // Wait for button to be enabled before retapping
532+             if  checkMessagesButton. isEnabled { 
533+                 print ( " 🔄 Retry  \( retryCount +  1 ) / \( maxRetries) : Tapping check-messages-button... " ) 
534+                 checkMessagesButton. tap ( ) 
535+                 retryCount +=  1 
536+                 
537+                 // Give time for network request to complete before checking again
538+                 sleep ( 2 ) 
539+             }  else  { 
540+                 print ( " ⏸️ Button not enabled, waiting... " ) 
541+                 sleep ( 1 ) 
542+             } 
503543        } 
504544
505545        XCTAssertTrue ( 
506-             webView. waitForExistence ( timeout:  standardTimeout ) , 
507-             " In-app message should appear " 
546+             webView. waitForExistence ( timeout:  5 ) , 
547+             " In-app message should appear after retries  " 
508548        ) 
509549        //screenshotCapture.captureScreenshot(named: "03-testview-inapp-displayed")
510550
0 commit comments