From bac23b9b9ed715f7f4b7b37b660ee4395803cb31 Mon Sep 17 00:00:00 2001 From: Oana Horvath Date: Fri, 24 Apr 2020 11:46:15 +0300 Subject: [PATCH] for #9407: fixed old collection tests --- .../org/mozilla/fenix/ui/CollectionTest.kt | 137 ++++-------------- .../fenix/ui/robots/HomeScreenRobot.kt | 14 ++ .../fenix/ui/robots/ThreeDotMenuMainRobot.kt | 13 ++ 3 files changed, 59 insertions(+), 105 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/CollectionTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/CollectionTest.kt index 0e4d9cf27fe1..14abdd89bf7d 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/CollectionTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/CollectionTest.kt @@ -4,27 +4,19 @@ package org.mozilla.fenix.ui -import android.net.Uri -import androidx.test.espresso.Espresso.onView import androidx.test.espresso.NoMatchingViewException -import androidx.test.espresso.assertion.ViewAssertions -import androidx.test.espresso.matcher.ViewMatchers import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.By import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.Until import okhttp3.mockwebserver.MockWebServer -import org.junit.Ignore import org.junit.Before import org.junit.After import org.junit.Test import org.junit.Rule -import org.mozilla.fenix.R import org.mozilla.fenix.helpers.AndroidAssetDispatcher import org.mozilla.fenix.helpers.HomeActivityTestRule import org.mozilla.fenix.helpers.TestAssetHelper -import org.mozilla.fenix.helpers.click -import org.mozilla.fenix.ui.robots.browserScreen import org.mozilla.fenix.ui.robots.homeScreen import org.mozilla.fenix.ui.robots.navigationToolbar @@ -35,6 +27,7 @@ import org.mozilla.fenix.ui.robots.navigationToolbar class CollectionTest { /* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping. + private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) private lateinit var mockWebServer: MockWebServer @@ -55,161 +48,95 @@ class CollectionTest { } @Test - @Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793") // open a webpage, and add currently opened tab to existing collection fun addTabToCollectionTest() { - val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2) - createCollection(firstWebPage.url, "testcollection_1") + createCollectionFromTab("testcollection_1") - // Close the open tab homeScreen { - verifyHomeScreen() - } - onView(ViewMatchers.withId(R.id.close_tab_button)).click() - - // On homeview, open another webpage - navigationToolbar { + verifyExistingTabList() + closeTab() + }.openNavigationToolbar { }.enterURLAndEnterToBrowser(secondWebPage.url) { verifyPageContent(secondWebPage.content) - } - - // Save the current page to the testcollection_1 - navigationToolbar { }.openThreeDotMenu { - // click save to collection menu item, type collection name clickBrowserViewSaveCollectionButton() - org.mozilla.fenix.ui.robots.mDevice.wait( - Until.findObject(By.text("testcollection_1")), - TestAssetHelper.waitingTime) - onView(ViewMatchers.withText("testcollection_1")).click() - mDevice.pressBack() // go to main page - } - - // close currently opened tab - homeScreen { - verifyHomeScreen() - onView(ViewMatchers.withId(R.id.close_tab_button)).click() - org.mozilla.fenix.ui.robots.mDevice.wait( - Until.findObject(By.text("testcollection_1")), - TestAssetHelper.waitingTime) - // On homeview, expand the collection and open the first saved page - onView(ViewMatchers.withText("testcollection_1")).click() - onView(ViewMatchers.withText("Test_Page_1")).click() - } - // Page content: 1 - browserScreen { - verifyPageContent("Page content: 1") - mDevice.pressBack() // go to main page - } - - // tab_in_collection_item - homeScreen { - verifyHomeScreen() - onView(ViewMatchers.withId(R.id.close_tab_button)).click() + }.selectExistingCollection("testcollection_1") { + verifySnackBarText("Tab saved!") + }.openHomeScreen { + verifyExistingTabList() + closeTab() // On homeview, expand the collection and open the first saved page - org.mozilla.fenix.ui.robots.mDevice.wait( - Until.findObject(By.text("Test_Page_2")), - TestAssetHelper.waitingTime) - onView(ViewMatchers.withText("Test_Page_2")).click() - } - - // Page content: 2 - browserScreen { - verifyPageContent("Page content: 2") + expandCollection("testcollection_1") + verifyItemInCollectionExists("Test_Page_1") + verifyItemInCollectionExists("Test_Page_2") } } @Test - @Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793") - // Rename Collection from the Homescreen fun renameCollectionTest() { - - val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) - - createCollection(firstWebPage.url, "testcollection_1") + createCollectionFromTab("testcollection_1") homeScreen { // On homeview, tap the 3-dot button to expand, select rename, rename collection clickCollectionThreeDotButton() selectRenameCollection() typeCollectionName("renamed_collection") - mDevice.wait(Until.findObject(By.text("renamed_collection")), TestAssetHelper.waitingTime) - // Verify the new name is displayed on homeview - onView(ViewMatchers.withText("renamed_collection")) - .check(ViewAssertions - .matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) + verifyCollectionIsDisplayed("renamed_collection") } } @Test - @Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793") - // Delete Collection from the Homescreen fun deleteCollectionTest() { - - val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) - - createCollection(firstWebPage.url, "testcollection_1") + createCollectionFromTab("testcollection_1") homeScreen { // Choose delete collection from homeview, and confirm clickCollectionThreeDotButton() selectDeleteCollection() confirmDeleteCollection() - - // Check for No collections caption - onView(ViewMatchers.withText("No collections")) - .check(ViewAssertions - .matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) + verifyNoCollectionsHeader() } } @Test - @Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793") - fun createCollectionTest() { - val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) - val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2) - - createCollection(firstWebPage.url, "testcollection_1") - createCollection(secondWebPage.url, "testcollection_2", false) + fun createCollectionFromTabTest() { + createCollectionFromTab("testcollection_1") + createCollectionFromTab("testcollection_2", false) - // On the main screen, swipe to bottom until the collections are shown homeScreen { // swipe to bottom until the collections are shown verifyHomeScreen() try { - onView(ViewMatchers.withText("testcollection_1")) - .check(ViewAssertions - .matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) + verifyCollectionIsDisplayed("testcollection_1") } catch (e: NoMatchingViewException) { scrollToElementByText("testcollection_1") } - onView(ViewMatchers.withText("testcollection_2")).check(ViewAssertions - .matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) + verifyCollectionIsDisplayed("testcollection_2") } } - private fun createCollection(url: Uri, collectionName: String, firstCollection: Boolean = true) { + private fun createCollectionFromTab(collectionName: String, firstCollection: Boolean = true) { val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) // Open a webpage and save to collection "testcollection_1" navigationToolbar { - }.enterURLAndEnterToBrowser(url) { + }.enterURLAndEnterToBrowser(firstWebPage.url) { verifyPageContent(firstWebPage.content) - } - navigationToolbar { }.openThreeDotMenu { // click save to collection menu item, type collection name clickBrowserViewSaveCollectionButton() if (!firstCollection) clickAddNewCollection() - }.typeCollectionName(collectionName) {} - - mDevice.pressBack() // go to main page - org.mozilla.fenix.ui.robots.mDevice.wait( - Until.findObject(By.text(collectionName)), - TestAssetHelper.waitingTime) + }.typeCollectionName(collectionName) { + verifySnackBarText("Tab saved!") + }.openHomeScreen { + mDevice.wait( + Until.findObject(By.text(collectionName)), + TestAssetHelper.waitingTime + ) + } } } diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt index 227b2123a33c..4814e8f11a20 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt @@ -149,6 +149,17 @@ class HomeScreenRobot { collectionNameTextField().perform(ViewActions.pressImeActionButton()) } + fun verifyCollectionIsDisplayed(title: String) { + mDevice.wait(findObject(text("renamed_collection")), waitingTime) + collectionTitle(title).check(matches(isDisplayed())) + } + + fun expandCollection(title: String) = collectionTitle(title).click() + + fun verifyItemInCollectionExists(title: String) = + onView(allOf(withId(R.id.list_element_title), withText(title))) + .check(matches(isDisplayed())) + fun scrollToElementByText(text: String): UiScrollable { val appView = UiScrollable(UiSelector().scrollable(true)) appView.scrollTextIntoView(text) @@ -597,6 +608,9 @@ private fun collectionThreeDotButton() = private fun collectionNameTextField() = onView(allOf(ViewMatchers.withResourceName("name_collection_edittext"))) +private fun collectionTitle(title: String) = + onView(allOf(withId(R.id.collection_title), withText(title))) + private fun closeTabViaX(title: String) { val closeButton = onView( allOf( diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt index c8bff8177d56..f7a606640f67 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt @@ -26,8 +26,10 @@ import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.By import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.Until +import org.hamcrest.CoreMatchers import org.hamcrest.Matchers.allOf import org.mozilla.fenix.R +import org.mozilla.fenix.helpers.TestAssetHelper import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime import org.mozilla.fenix.helpers.click import org.mozilla.fenix.helpers.ext.waitNotNull @@ -245,6 +247,16 @@ class ThreeDotMenuMainRobot { AddToHomeScreenRobot().interact() return AddToHomeScreenRobot.Transition() } + + fun selectExistingCollection(title: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition { + org.mozilla.fenix.ui.robots.mDevice.wait( + Until.findObject(By.text("testcollection_1")), + waitingTime) + onView(withText(title)).click() + + BrowserRobot().interact() + return BrowserRobot.Transition() + } } } @@ -374,3 +386,4 @@ private fun assertAddToFirefoxHome() { ) ).check(matches(withEffectiveVisibility(Visibility.VISIBLE))) } +