From 10f20747493ae5c2158915ed1a004d77b82a349e Mon Sep 17 00:00:00 2001 From: AndiAJ Date: Fri, 24 Sep 2021 16:30:25 +0300 Subject: [PATCH] Fix disabled shortcutButtonTest UI test --- .../mozilla/fenix/helpers/ext/WaitNotNull.kt | 6 ++++++ .../java/org/mozilla/fenix/ui/SearchTest.kt | 3 +-- .../org/mozilla/fenix/ui/robots/SearchRobot.kt | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/helpers/ext/WaitNotNull.kt b/app/src/androidTest/java/org/mozilla/fenix/helpers/ext/WaitNotNull.kt index f726a3ac8a..6732d950f9 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/helpers/ext/WaitNotNull.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/helpers/ext/WaitNotNull.kt @@ -6,6 +6,7 @@ package org.mozilla.fenix.helpers.ext import androidx.test.uiautomator.SearchCondition import androidx.test.uiautomator.UiDevice +import androidx.test.uiautomator.UiObject import org.junit.Assert.assertNotNull import org.mozilla.fenix.helpers.TestAssetHelper @@ -18,3 +19,8 @@ fun UiDevice.waitNotNull( searchCondition: SearchCondition<*>, waitTime: Long = TestAssetHelper.waitingTime ) = assertNotNull(wait(searchCondition, waitTime)) + +fun UiDevice.waitForAwesomeBarContent(obj: UiObject, waitingTime: Long = TestAssetHelper.waitingTime) { + this.waitForIdle() + assertNotNull(obj.waitForExists(waitingTime)) +} diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt index 3861805dc0..b1074b3296 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt @@ -52,7 +52,6 @@ class SearchTest { } } - @Ignore("Currently failing at assertSearchEngineResults, will need a re-check") @Test fun shortcutButtonTest() { homeScreen { @@ -63,7 +62,7 @@ class SearchTest { }.goBack { }.goBack { }.openSearch { -// verifySearchWithText() + verifySearchBarEmpty() clickSearchEngineButton(activityTestRule, "DuckDuckGo") typeSearch("mozilla") verifySearchEngineResults(activityTestRule, "DuckDuckGo", 4) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SearchRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SearchRobot.kt index a2d8de1277..dabfb71c9c 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SearchRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SearchRobot.kt @@ -45,6 +45,7 @@ import org.mozilla.fenix.helpers.TestAssetHelper import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime import org.mozilla.fenix.helpers.TestHelper.packageName import org.mozilla.fenix.helpers.click +import org.mozilla.fenix.helpers.ext.waitForAwesomeBarContent import org.mozilla.fenix.helpers.ext.waitNotNull /** @@ -98,9 +99,18 @@ class SearchRobot { fun typeSearch(searchTerm: String) { browserToolbarEditView().setText(searchTerm) + mDevice.waitForIdle() } fun clickSearchEngineButton(rule: ComposeTestRule, searchEngineName: String) { + rule.waitForIdle() + + mDevice.waitForAwesomeBarContent( + mDevice.findObject( + UiSelector().textContains(searchEngineName) + ) + ) + rule.onNodeWithText(searchEngineName) .assertExists() .assertHasClickAction() @@ -242,6 +252,14 @@ private fun assertSearchEngineURL(searchEngineName: String) { } private fun assertSearchEngineResults(rule: ComposeTestRule, searchEngineName: String, count: Int) { + rule.waitForIdle() + + mDevice.waitForAwesomeBarContent( + mDevice.findObject( + UiSelector().textContains(searchEngineName) + ) + ) + rule.onAllNodesWithText(searchEngineName) .assertCountEquals(count) }