Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
run #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Horvath committed Feb 17, 2022
1 parent 8714f47 commit 5687701
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class HistoryTest {
historyListIdlingResource =
RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.history_list), 1)
IdlingRegistry.getInstance().register(historyListIdlingResource!!)
clickDeleteHistoryButton()
clickDeleteHistoryButton(firstWebPage.url.toString())
IdlingRegistry.getInstance().unregister(historyListIdlingResource!!)
verifyDeleteSnackbarText("Deleted")
verifyEmptyHistoryView()
Expand Down
82 changes: 62 additions & 20 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
package org.mozilla.fenix.ui

import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.core.net.toUri
import androidx.test.espresso.Espresso
import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu
import mozilla.components.browser.icons.IconRequest
import mozilla.components.browser.icons.generator.DefaultIconGenerator
import mozilla.components.browser.state.search.SearchEngine
import mozilla.components.feature.search.ext.createSearchEngine
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
Expand All @@ -16,14 +18,15 @@ import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.helpers.FeatureSettingsHelper
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.SearchDispatcher
import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.helpers.TestHelper.exitMenu
import org.mozilla.fenix.helpers.TestHelper.longTapSelectItem
import org.mozilla.fenix.helpers.TestHelper.setCustomSearchEngine
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.searchSettingsScreen
import org.mozilla.fenix.ui.robots.multipleSelectionToolbar

/**
* Tests for verifying the search fragment
Expand All @@ -44,15 +47,6 @@ class SearchTest {

private val featureSettingsHelper = FeatureSettingsHelper()
lateinit var searchMockServer: MockWebServer
// private fun searchMockServer() = MockWebServer().apply {
// dispatcher = SearchDispatcher()
// }

// private val customSearchEngine = createSearchEngine(
// name = "TestSearchEngine",
// url = "http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}",
// icon = DefaultIconGenerator().generate(appContext, IconRequest("http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}")).bitmap
// )

@Before
fun setUp() {
Expand Down Expand Up @@ -143,6 +137,7 @@ class SearchTest {
fun searchGroupShowsInRecentlyVisitedTest() {
val firstPage = searchMockServer.url("generic1.html").toString()
val secondPage = searchMockServer.url("generic2.html").toString()
// setting our custom mockWebServer search URL
val searchString = "http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}"
val customSearchEngine = createSearchEngine(
name = "TestSearchEngine",
Expand All @@ -154,29 +149,30 @@ class SearchTest {
// Performs a search and opens 2 dummy search results links to create a search group
homeScreen {
}.openSearch {
}.submitQuery("test") {
}.submitQuery("test search") {
longClickMatchingText("Link 1")
clickContextOpenLinkInNewTab()
longClickMatchingText("Link 2")
clickContextOpenLinkInNewTab()
}.goToHomescreen {
verifyJumpBackInSectionIsDisplayed()
verifyCurrentSearchGroupIsDisplayed(true,"test",3)
verifyRecentlyVisitedSearchGroupDisplayed(false, "test", 3)
verifyCurrentSearchGroupIsDisplayed(true,"test search",3)
verifyRecentlyVisitedSearchGroupDisplayed(false, "test search", 3)
}.openTabDrawer {
}.openTabFromGroup(firstPage) {
}.openTabDrawer {
}.openTabFromGroup(secondPage) {
}.openTabDrawer {
}.openTabsListThreeDotMenu {
}.closeAllTabs {
verifyRecentlyVisitedSearchGroupDisplayed(true,"test", 3)
verifyRecentlyVisitedSearchGroupDisplayed(true,"test search", 3)
}
}

@SmokeTest
@Test
fun noCurrentSearchGroupFromPrivateBrowsingTest() {
// setting our custom mockWebServer search URL
val searchString = "http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}"
val customSearchEngine = createSearchEngine(
name = "TestSearchEngine",
Expand All @@ -188,13 +184,13 @@ class SearchTest {
// Performs a search and opens 2 dummy search results links to create a search group
homeScreen {
}.openSearch {
}.submitQuery("test") {
}.submitQuery("test search") {
longClickMatchingText("Link 1")
clickContextOpenLinkInPrivateTab()
longClickMatchingText("Link 2")
clickContextOpenLinkInPrivateTab()
}.goToHomescreen {
verifyCurrentSearchGroupIsDisplayed(false, "test", 3)
verifyCurrentSearchGroupIsDisplayed(false, "test search", 3)
}.openThreeDotMenu {
}.openHistory {
verifyHistoryItemExists(false, "3 sites")
Expand All @@ -206,6 +202,7 @@ class SearchTest {
fun noRecentlyVisitedSearchGroupInPrivateBrowsingTest() {
val firstPage = searchMockServer.url("generic1.html").toString()
val secondPage = searchMockServer.url("generic2.html").toString()
// setting our custom mockWebServer search URL
val searchString = "http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}"
val customSearchEngine = createSearchEngine(
name = "TestSearchEngine",
Expand All @@ -219,7 +216,7 @@ class SearchTest {
}.togglePrivateBrowsingMode()
homeScreen {
}.openSearch {
}.submitQuery("test") {
}.submitQuery("test search") {
longClickMatchingText("Link 1")
clickContextOpenLinkInPrivateTab()
longClickMatchingText("Link 2")
Expand All @@ -233,7 +230,52 @@ class SearchTest {
}.closeAllTabs {
homeScreen {
}.togglePrivateBrowsingMode()
verifyRecentlyVisitedSearchGroupDisplayed(false, "test", 3)
verifyRecentlyVisitedSearchGroupDisplayed(false, "test search", 3)
}
}

@SmokeTest
@Test
fun deleteItemsFromSearchGroupsHistoryTest() {
val firstPage = searchMockServer.url("generic1.html").toString()
val secondPage = searchMockServer.url("generic2.html").toString()
// setting our custom mockWebServer search URL
val searchString = "http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}"
val customSearchEngine = createSearchEngine(
name = "TestSearchEngine",
url = searchString,
icon = DefaultIconGenerator().generate(appContext, IconRequest(searchString)).bitmap
)
setCustomSearchEngine(customSearchEngine)

// Performs a search and opens 2 dummy search results links to create a search group
homeScreen {
}.openSearch {
}.submitQuery("test search") {
longClickMatchingText("Link 1")
clickContextOpenLinkInNewTab()
longClickMatchingText("Link 2")
clickContextOpenLinkInNewTab()
}.openTabDrawer {
}.openTabFromGroup(firstPage) {
}.openTabDrawer {
}.openTabFromGroup(secondPage) {
}.openTabDrawer {
}.openTabsListThreeDotMenu {
}.closeAllTabs {
verifyRecentlyVisitedSearchGroupDisplayed(true, "test search", 3)
}.openRecentlyVisitedSearchGroupHistoryList("test search") {
clickDeleteHistoryButton(firstPage)
longTapSelectItem(secondPage.toUri())
multipleSelectionToolbar {
openActionBarOverflowOrOptionsMenu(activityTestRule.activity)
clickMultiSelectionDelete()
}
exitMenu()
}
homeScreen {
// checking that the group is removed when only 1 item is left
verifyRecentlyVisitedSearchGroupDisplayed(false, "test search", 1)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.hasSibling
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
Expand Down Expand Up @@ -66,8 +67,8 @@ class HistoryRobot {

fun verifyHomeScreen() = HomeScreenRobot().verifyHomeScreen()

fun clickDeleteHistoryButton() {
deleteButton().click()
fun clickDeleteHistoryButton(item: String) {
deleteButton(item).click()
}

fun clickDeleteAllHistoryButton() = deleteAllButton().click()
Expand Down Expand Up @@ -100,7 +101,8 @@ private fun testPageTitle() = onView(allOf(withId(R.id.title), withText("Test_Pa

private fun pageUrl() = onView(withId(R.id.url))

private fun deleteButton() = onView(withId(R.id.overflow_menu))
private fun deleteButton(title: String) =
onView(allOf(withId(R.id.overflow_menu), hasSibling(withText(title))))

private fun deleteAllButton() = onView(withId(R.id.history_delete_all))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.TestHelper.hasCousin
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText
import org.mozilla.fenix.helpers.click
Expand Down Expand Up @@ -126,7 +127,7 @@ class HomeScreenRobot {

fun verifyRecentlyVisitedSearchGroupDisplayed(shouldBeDisplayed: Boolean, searchTerm: String, groupSize: Int) {
// checks if the search group exists in the Recently visited section
recentlyVisitedList.waitForExists(waitingTime)
mDevice.findObject(UiSelector().text("Recently visited")).waitForExists(waitingTime)
scrollToElementByText("Recently visited")

if (shouldBeDisplayed) {
Expand Down Expand Up @@ -384,6 +385,15 @@ class HomeScreenRobot {
CollectionRobot().interact()
return CollectionRobot.Transition()
}

fun openRecentlyVisitedSearchGroupHistoryList(title: String, interact: HistoryRobot.() -> Unit): HistoryRobot.Transition {
recentlyVisitedList.getChildByText(UiSelector().text(title), title, true)
.waitForExists(waitingTimeShort)
mDevice.findObject(UiSelector().text(title)).click()

HistoryRobot().interact()
return HistoryRobot.Transition()
}
}
}

Expand Down Expand Up @@ -692,5 +702,6 @@ val deleteFromHistory =

private val recentlyVisitedList =
UiScrollable(
UiSelector().className("android.widget.HorizontalScrollView")
).setAsHorizontalList()
UiSelector()
.className("android.widget.HorizontalScrollView")
).setAsHorizontalList()
1 change: 1 addition & 0 deletions automation/taskcluster/androidTest/flank-x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ gcloud:
- class org.mozilla.fenix.ui.SearchTest#searchGroupShowsInRecentlyVisitedTest
- class org.mozilla.fenix.ui.SearchTest#noCurrentSearchGroupFromPrivateBrowsingTest
- class org.mozilla.fenix.ui.SearchTest#noRecentlyVisitedSearchGroupInPrivateBrowsingTest
- class org.mozilla.fenix.ui.SearchTest#deleteItemsFromSearchGroupsHistoryTest
- class org.mozilla.fenix.ui.SettingsSearchTest#editCustomSearchEngineTest

device:
Expand Down

0 comments on commit 5687701

Please sign in to comment.