You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// RESUMED fires before view inflation completes; waitForExists handles the race.
65
73
val pushButton = uiDevice.findObject(UiSelector().resourceId("com.iterable.integration.tests:id/btnPushNotifications"))
66
-
if (!pushButton.exists()) {
74
+
if (!pushButton.waitForExists(5000)) {
67
75
Assert.fail("Push Notifications button not found in MainActivity")
68
76
}
69
77
pushButton.click()
70
78
Thread.sleep(2000)
71
79
}
72
80
73
81
@Test
74
-
@Ignore("SDK-115 follow-up: foreground assertion after openNotification() is unreliable on the BCIT CI emulator (notification taps don't always resume the test app). Re-enable once the open path is stable.")
75
82
funtestPushNotificationMVP() {
76
83
Assert.assertTrue("User should be signed in", testUtils.ensureUserSignedIn(TestConstants.TEST_USER_EMAIL))
77
84
Assert.assertTrue("Notification permission should be granted", hasNotificationPermission())
78
-
79
-
// Test 1: Trigger campaign, minimize app, open notification, verify app opens
80
-
Log.d(TAG, "Test 1: Push notification open action")
85
+
86
+
if (!isRunningInCI) {
87
+
// Local-mode only: wait for token registration + a backend cool-down before
88
+
// triggering the real campaign. CI uses [injectPushMessage] and skips both.
89
+
Assert.assertTrue(
90
+
"Device token should be registered with Iterable SDK before triggering a campaign",
91
+
waitForDeviceTokenRegistered(timeoutSeconds =20)
92
+
)
93
+
Thread.sleep(5_000)
94
+
}
95
+
96
+
Log.d(TAG, "MVP: Push notification open action")
81
97
triggerCampaignAndWait()
82
98
uiDevice.pressHome()
83
99
Thread.sleep(1000)
84
-
100
+
85
101
uiDevice.openNotification()
86
102
Thread.sleep(1000)
87
-
val notification1 = findNotification()
88
-
Assert.assertNotNull("Notification should be found", notification1)
89
-
90
-
notification1?.click()
91
-
Thread.sleep(2000) // Wait for app to open
92
-
93
-
// Verify app is in foreground by checking current package name
103
+
val notification = findNotification()
104
+
Assert.assertNotNull("Notification should be found", notification)
105
+
106
+
notification?.click()
107
+
Thread.sleep(2000)
108
+
94
109
val isAppInForeground = waitForCondition({
95
-
val currentPackage = uiDevice.currentPackageName
96
-
currentPackage =="com.iterable.integration.tests"
110
+
uiDevice.currentPackageName ==APP_PACKAGE
97
111
}, timeoutSeconds =5)
98
112
Assert.assertTrue("App should be in foreground after opening notification", isAppInForeground)
99
-
navigateToPushNotificationTestActivity()
100
-
101
-
// Test 2: Trigger campaign again, tap first action button (Google), verify URL handler
102
-
Log.d(TAG, "Test 2: Action button with URL handler")
113
+
}
114
+
115
+
@Test
116
+
@Ignore("SDK-115 follow-up: action buttons aren't laid out in the collapsed notification shade; UiAutomator can't reliably expand it. Re-enable with an expand-on-find helper.")
117
+
funtestPushNotificationActionButtons() {
118
+
Assert.assertTrue("User should be signed in", testUtils.ensureUserSignedIn(TestConstants.TEST_USER_EMAIL))
119
+
Assert.assertTrue("Notification permission should be granted", hasNotificationPermission())
120
+
if (!isRunningInCI) {
121
+
Assert.assertTrue(
122
+
"Device token should be registered with Iterable SDK before triggering a campaign",
123
+
waitForDeviceTokenRegistered(timeoutSeconds =20)
124
+
)
125
+
Thread.sleep(5_000)
126
+
}
127
+
128
+
// URL handler via the "Google" action button
129
+
Log.d(TAG, "Action button with URL handler")
103
130
triggerCampaignAndWait()
104
131
uiDevice.pressHome()
105
132
Thread.sleep(1000)
106
-
107
133
uiDevice.openNotification()
108
134
Thread.sleep(2000)
109
-
val notification2 = findNotification()
110
-
Assert.assertNotNull("Notification should be found", notification2)
111
-
135
+
Assert.assertNotNull("Notification should be found", findNotification())
136
+
112
137
resetUrlHandlerTracking()
113
138
val googleButton = uiDevice.findObject(By.text("Google"))
114
139
Assert.assertNotNull("Google button should be found", googleButton)
115
140
googleButton?.click()
116
141
Thread.sleep(2000)
117
-
118
142
Assert.assertTrue("URL handler should be called", waitForUrlHandler(timeoutSeconds =5))
119
143
Assert.assertNotNull("Handled URL should not be null", getLastHandledUrl())
120
-
121
-
// Navigate back to PushNotificationTestActivity for next test (in case action button opened app)
144
+
122
145
Thread.sleep(1000)
123
146
navigateToPushNotificationTestActivity()
124
-
125
-
//Test 3: Trigger campaign again, tap second action button (Deeplink), verify custom action handler
126
-
Log.d(TAG, "Test 3: Action button with custom action handler")
147
+
148
+
//Custom action handler via the "Deeplink" action button
149
+
Log.d(TAG, "Action button with custom action handler")
127
150
triggerCampaignAndWait()
128
151
uiDevice.pressHome()
129
152
Thread.sleep(1000)
130
-
131
153
uiDevice.openNotification()
132
154
Thread.sleep(2000)
133
-
val notification3 = findNotification()
134
-
Assert.assertNotNull("Notification should be found", notification3)
135
-
155
+
Assert.assertNotNull("Notification should be found", findNotification())
156
+
136
157
resetCustomActionHandlerTracking()
137
158
val deeplinkButton = uiDevice.findObject(By.text("Deeplink"))
138
159
Assert.assertNotNull("Deeplink button should be found", deeplinkButton)
139
160
deeplinkButton?.click()
140
161
Thread.sleep(2000)
141
-
142
162
Assert.assertTrue("Custom action handler should be called", waitForCustomActionHandler(timeoutSeconds =5))
143
163
Assert.assertNotNull("Action type should not be null", getLastHandledActionType())
144
-
145
-
// Navigate back to PushNotificationTestActivity (in case action button opened app)
146
-
Thread.sleep(1000)
147
-
navigateToPushNotificationTestActivity()
148
-
149
-
// Note: trackPushOpen() is called internally by the SDK when notifications are opened
150
-
// It's automatically invoked by IterablePushNotificationUtil.executeAction() which is called
151
-
// by the trampoline activity when handling push notification clicks
152
-
Log.d(TAG, "Test completed successfully")
153
164
}
154
165
155
166
privatefuntriggerCampaignAndWait() {
167
+
if (isRunningInCI) {
168
+
injectSimulatedBcitPush()
169
+
} else {
170
+
triggerCampaignViaBackendAndWait()
171
+
}
172
+
}
173
+
174
+
// CI path: locally constructed payload mirroring the BCIT push template, injected
175
+
// via IterableFirebaseMessagingService.handleMessageReceived. Bypasses FCM.
Copy file name to clipboardExpand all lines: integration-tests/src/main/java/com/iterable/integration/tests/services/IntegrationFirebaseMessagingService.kt
0 commit comments