Skip to content

Commit 3f3ff0f

Browse files
authored
dismiss widget dialog when running privacy instrumentation tests (#8685)
Task/Issue URL: https://app.asana.com/1/137249556945/project/414730916066338/task/1215115320142558?focus=true ### Description Dismiss widget pop-up when running privacy instrumentation tests. ### Steps to test this PR QA optional, running the test on CI in https://github.com/duckduckgo/Android/actions/runs/26440610428. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Changes only Android instrumentation test utilities; no production app behavior. > > **Overview** > Centralizes Espresso handling for the **home screen widget promo** bottom sheet so instrumentation tests are less flaky on fresh installs. > > The dismissal logic moves from a private helper in `BasicJourneyTest` into shared **`dismissWidgetPromoIfPresent()`** in `EspressoUtils.kt` (with a short comment tying it to `CtaViewModel.canShowWidgetCta`). **`preparationsForPrivacyTest()`** now calls that helper after the browser menu is ready, so privacy tests get the same dialog cleanup as the basic journey test. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 3272d28. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 9a05611 commit 3f3ff0f

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

app/src/androidTest/java/com/duckduckgo/espresso/BasicJourneyTest.kt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package com.duckduckgo.espresso
1818

1919
import androidx.test.espresso.Espresso.onView
2020
import androidx.test.espresso.action.ViewActions.click
21-
import androidx.test.espresso.matcher.RootMatchers.isDialog
2221
import androidx.test.espresso.matcher.ViewMatchers.isClickable
2322
import androidx.test.espresso.matcher.ViewMatchers.isRoot
2423
import androidx.test.espresso.matcher.ViewMatchers.withId
@@ -41,8 +40,7 @@ class BasicJourneyTest {
4140

4241
@Test @UserJourney
4342
fun browser_openPopUp() {
44-
// dismiss any first-run dialogs (e.g., widget promo)
45-
dismissBlockingDialogs()
43+
dismissWidgetPromoIfPresent()
4644

4745
// since we use a fake toolbar, we want to wait until the real one is visible
4846
onView(isRoot()).perform(waitForView(withId(R.id.browserMenu)))
@@ -53,13 +51,4 @@ class BasicJourneyTest {
5351
// check that the forward button is visible
5452
clickMenuItem(withId(BrowserUiR.id.forwardMenuItem))
5553
}
56-
57-
private fun dismissBlockingDialogs() {
58-
// dismiss the home screen widget promo if present
59-
runCatching {
60-
onView(isRoot()).inRoot(isDialog())
61-
.perform(waitForView(withId(R.id.homeScreenWidgetBottomSheetDialogGhostButton), timeout = 3000))
62-
onView(withId(R.id.homeScreenWidgetBottomSheetDialogGhostButton)).perform(click())
63-
}
64-
}
6554
}

app/src/androidTest/java/com/duckduckgo/espresso/EspressoUtils.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ package com.duckduckgo.espresso
1818

1919
import android.view.*
2020
import androidx.test.espresso.*
21+
import androidx.test.espresso.Espresso.onView
22+
import androidx.test.espresso.action.ViewActions.click
2123
import androidx.test.espresso.matcher.*
24+
import androidx.test.espresso.matcher.RootMatchers.isDialog
25+
import androidx.test.espresso.matcher.ViewMatchers.isRoot
26+
import androidx.test.espresso.matcher.ViewMatchers.withId
27+
import com.duckduckgo.app.browser.R
2228
import org.hamcrest.*
2329

2430
// used to introduce a delay not blocking main thread
@@ -31,3 +37,13 @@ fun waitFor(delay: Long): ViewAction {
3137
}
3238
}
3339
}
40+
41+
// The Home screen widget promo bottom sheet (CtaViewModel.canShowWidgetCta) can appear on top of
42+
// BrowserActivity on fresh installs and obscure the activity's own root, breaking unrelated tests.
43+
fun dismissWidgetPromoIfPresent() {
44+
runCatching {
45+
onView(isRoot()).inRoot(isDialog())
46+
.perform(waitForView(withId(R.id.homeScreenWidgetBottomSheetDialogGhostButton), timeout = 3000))
47+
onView(withId(R.id.homeScreenWidgetBottomSheetDialogGhostButton)).perform(click())
48+
}
49+
}

app/src/androidTest/java/com/duckduckgo/espresso/privacy/PrivacyTestExtensions.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import androidx.test.espresso.matcher.ViewMatchers.isRoot
2525
import androidx.test.espresso.matcher.ViewMatchers.withId
2626
import androidx.test.espresso.matcher.ViewMatchers.withText
2727
import com.duckduckgo.app.browser.R
28+
import com.duckduckgo.espresso.dismissWidgetPromoIfPresent
2829
import com.duckduckgo.espresso.waitFor
2930
import com.duckduckgo.espresso.waitForView
3031
import java.util.concurrent.TimeUnit
@@ -34,6 +35,8 @@ fun preparationsForPrivacyTest() {
3435
IdlingPolicies.setMasterPolicyTimeout(waitTime * 10, TimeUnit.MILLISECONDS)
3536
IdlingPolicies.setIdlingResourceTimeout(waitTime * 10, TimeUnit.MILLISECONDS)
3637

38+
dismissWidgetPromoIfPresent()
39+
3740
onView(isRoot()).perform(waitForView(withId(R.id.browserMenu)))
3841
onView(isRoot()).perform(waitFor(2000))
3942

0 commit comments

Comments
 (0)