Skip to content

Commit

Permalink
Fix disabled toggleSearchSuggestions UI Tets and refactoring work
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiAJ authored and mergify[bot] committed Sep 28, 2021
1 parent ab13ae0 commit 06292ac
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiObject
import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import kotlinx.coroutines.runBlocking
import mozilla.components.support.ktx.android.content.appName
import org.hamcrest.CoreMatchers
import org.hamcrest.CoreMatchers.allOf
import org.junit.Assert
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.ext.waitNotNull
Expand Down Expand Up @@ -224,4 +226,9 @@ object TestHelper {
!urlBar.waitForExists(waitingTime)
)
}

fun UiDevice.waitForObjects(obj: UiObject, waitingTime: Long = TestAssetHelper.waitingTime) {
this.waitForIdle()
Assert.assertNotNull(obj.waitForExists(waitingTime))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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

Expand All @@ -19,8 +18,3 @@ 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))
}
33 changes: 7 additions & 26 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
package org.mozilla.fenix.ui

import android.view.View
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.onNodeWithText
import androidx.core.net.toUri
import androidx.test.espresso.IdlingRegistry
import androidx.test.platform.app.InstrumentationRegistry
Expand Down Expand Up @@ -578,43 +576,26 @@ class SmokeTest {
}
}

@Ignore("Disabled for failing with new Compose Awesomebar")
@Test
// Test running on beta/release builds in CI:
// caution when making changes to it, so they don't block the builds
// Goes through the settings and changes the search suggestion toggle, then verifies it changes.
fun toggleSearchSuggestions() {

homeScreen {
}.openNavigationToolbar {
typeSearchTerm("mozilla")
val awesomeBarView = getAwesomebarView()
awesomeBarView?.let {
awesomeBar = ViewVisibilityIdlingResource(it, View.VISIBLE)
}
IdlingRegistry.getInstance().register(awesomeBar!!)

activityTestRule.waitForIdle()

activityTestRule
.onNodeWithText("mozilla firefox")
.assertExists()
.assertIsDisplayed()
}.goBack {
}.openSearch {
typeSearch("mozilla")
verifySearchEngineSuggestionResults(activityTestRule, "mozilla firefox")
}.dismissSearchBar {
}.openThreeDotMenu {
}.openSettings {
}.openSearchSubMenu {
disableShowSearchSuggestions()
}.goBack {
}.goBack {
}.openNavigationToolbar {
typeSearchTerm("mozilla")

activityTestRule.waitForIdle()

activityTestRule
.onNodeWithText("mozilla firefox")
.assertDoesNotExist()
}.openSearch {
typeSearch("mozilla")
verifyNoSuggestionsAreDisplayed(activityTestRule, "mozilla firefox")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import org.mozilla.fenix.helpers.SessionLoadedIdlingResource
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.TestHelper.waitForObjects
import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.helpers.ext.waitForAwesomeBarContent
import org.mozilla.fenix.helpers.ext.waitNotNull

/**
Expand All @@ -59,6 +59,10 @@ class SearchRobot {
fun verifySearchWithText() = assertSearchWithText()
fun verifySearchEngineResults(rule: ComposeTestRule, searchEngineName: String, count: Int) =
assertSearchEngineResults(rule, searchEngineName, count)
fun verifySearchEngineSuggestionResults(rule: ComposeTestRule, searchSuggestion: String) =
assertSearchEngineSuggestionResults(rule, searchSuggestion)
fun verifyNoSuggestionsAreDisplayed(rule: ComposeTestRule, searchSuggestion: String) =
assertNoSuggestionsAreDisplayed(rule, searchSuggestion)

fun verifySearchEngineURL(searchEngineName: String) = assertSearchEngineURL(searchEngineName)
fun verifySearchSettings() = assertSearchSettings()
Expand Down Expand Up @@ -105,7 +109,7 @@ class SearchRobot {
fun clickSearchEngineButton(rule: ComposeTestRule, searchEngineName: String) {
rule.waitForIdle()

mDevice.waitForAwesomeBarContent(
mDevice.waitForObjects(
mDevice.findObject(
UiSelector().textContains(searchEngineName)
)
Expand Down Expand Up @@ -254,7 +258,7 @@ private fun assertSearchEngineURL(searchEngineName: String) {
private fun assertSearchEngineResults(rule: ComposeTestRule, searchEngineName: String, count: Int) {
rule.waitForIdle()

mDevice.waitForAwesomeBarContent(
mDevice.waitForObjects(
mDevice.findObject(
UiSelector().textContains(searchEngineName)
)
Expand All @@ -264,6 +268,26 @@ private fun assertSearchEngineResults(rule: ComposeTestRule, searchEngineName: S
.assertCountEquals(count)
}

private fun assertSearchEngineSuggestionResults(rule: ComposeTestRule, searchResult: String) {
rule.waitForIdle()

mDevice.waitForObjects(
mDevice.findObject(
UiSelector().textContains(searchResult)
)
)

rule.onNodeWithText(searchResult)
.assertExists()
}

private fun assertNoSuggestionsAreDisplayed(rule: ComposeTestRule, searchTerm: String) {
rule.waitForIdle()

rule.onNodeWithText(searchTerm)
.assertDoesNotExist()
}

private fun assertSearchView() =
assertTrue(
mDevice.findObject(
Expand Down

0 comments on commit 06292ac

Please sign in to comment.