@@ -229,19 +229,33 @@ class InAppMessageIntegrationTest : BaseIntegrationTest() {
229229
230230 // Step 5: Click the "No Thanks" button in the WebView
231231 Log .d(TAG , " 🎯 Step 5: Clicking 'No Thanks' button in the in-app message..." )
232+
233+ // Try to find and click the "No Thanks" button with retry logic
234+ var noThanksButton: androidx.test.uiautomator.UiObject2 ? = null
235+ var attempts = 0
236+ val maxAttempts = 5
232237
233- // Wait for WebView to fully render
234- Thread .sleep(2000 )
235-
236- // Find and click the "No Thanks" button using By.textContains selector
237- val noThanksButton = uiDevice.findObject(By .textContains(" No Thanks" ))
238+ while (noThanksButton == null && attempts < maxAttempts) {
239+ attempts++
240+ Log .d(TAG , " Attempt $attempts : Looking for 'No Thanks' button..." )
241+
242+ // Try different text variations
243+ noThanksButton = uiDevice.findObject(By .textContains(" No Thanks" ))
244+ ? : uiDevice.findObject(By .text(" No Thanks" ))
245+ ? : uiDevice.findObject(By .textContains(" no thanks" ))
246+ ? : uiDevice.findObject(By .textContains(" NO THANKS" ))
247+
248+ if (noThanksButton == null ) {
249+ Log .d(TAG , " Button not found, waiting 1 second before retry..." )
250+ Thread .sleep(1000 )
251+ }
252+ }
238253
239254 if (noThanksButton != null ) {
240255 noThanksButton.click()
241256 Log .d(TAG , " ✅ Clicked 'No Thanks' button" )
242257 } else {
243- Log .e(TAG , " ❌ 'No Thanks' button not found in the in-app message WebView" )
244- Assert .fail(" 'No Thanks' button not found in the in-app message WebView" )
258+ Assert .fail(" 'No Thanks' button not found in the in-app message WebView after $maxAttempts attempts" )
245259 }
246260
247261 // Step 6: Verify URL handler was called
0 commit comments