Oana Horvath 4 years ago committed by GitHub
parent 866c60385e
commit aab5a54889

@ -4,27 +4,19 @@
package org.mozilla.fenix.ui package org.mozilla.fenix.ui
import android.net.Uri
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.NoMatchingViewException 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.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until import androidx.test.uiautomator.Until
import okhttp3.mockwebserver.MockWebServer import okhttp3.mockwebserver.MockWebServer
import org.junit.Ignore
import org.junit.Before
import org.junit.After import org.junit.After
import org.junit.Test import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.mozilla.fenix.R import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper 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.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar import org.mozilla.fenix.ui.robots.navigationToolbar
@ -35,8 +27,11 @@ import org.mozilla.fenix.ui.robots.navigationToolbar
class CollectionTest { class CollectionTest {
/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping. /* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.
private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private lateinit var mockWebServer: MockWebServer private lateinit var mockWebServer: MockWebServer
private val firstCollectionName = "testcollection_1"
private val secondCollectionName = "testcollection_2"
@get:Rule @get:Rule
val activityTestRule = HomeActivityTestRule() val activityTestRule = HomeActivityTestRule()
@ -55,161 +50,299 @@ class CollectionTest {
} }
@Test @Test
@Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793") fun verifyCreateFirstCollectionFlowItems() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
}.openHomeScreen {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
}.openHomeScreen {
clickSaveCollectionButton()
verifySelectTabsView()
selectAllTabsForCollection()
verifyTabsSelectedCounterText(2)
deselectAllTabsForCollection()
verifyTabsSelectedCounterText(0)
selectTabForCollection(firstWebPage.title)
verifyTabsSelectedCounterText(1)
selectAllTabsForCollection()
saveTabsSelectedForCollection()
verifyNameCollectionView()
verifyDefaultCollectionName("Collection 1")
typeCollectionName(firstCollectionName)
verifySnackBarText("Tabs saved!")
verifyExistingOpenTabs(firstWebPage.title)
verifyExistingOpenTabs(secondWebPage.title)
}
}
@Test
// open a webpage, and add currently opened tab to existing collection // open a webpage, and add currently opened tab to existing collection
fun addTabToCollectionTest() { fun addTabToExistingCollectionTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2) val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
createCollection(firstWebPage.url, "testcollection_1") createCollection(firstCollectionName)
// Close the open tab
homeScreen { homeScreen {
verifyHomeScreen() verifyExistingTabList()
} closeTab()
onView(ViewMatchers.withId(R.id.close_tab_button)).click() }.openNavigationToolbar {
// On homeview, open another webpage
navigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) { }.enterURLAndEnterToBrowser(secondWebPage.url) {
verifyPageContent(secondWebPage.content) verifyPageContent(secondWebPage.content)
}
// Save the current page to the testcollection_1
navigationToolbar {
}.openThreeDotMenu { }.openThreeDotMenu {
// click save to collection menu item, type collection name
clickBrowserViewSaveCollectionButton() clickBrowserViewSaveCollectionButton()
org.mozilla.fenix.ui.robots.mDevice.wait( }.selectExistingCollection(firstCollectionName) {
Until.findObject(By.text("testcollection_1")), verifySnackBarText("Tab saved!")
TestAssetHelper.waitingTime) }.openHomeScreen {
onView(ViewMatchers.withText("testcollection_1")).click() verifyExistingTabList()
mDevice.pressBack() // go to main page expandCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title)
verifyItemInCollectionExists(secondWebPage.title)
} }
}
@Test
fun collectionMenuAddTabButtonTest() {
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
createCollection(firstCollectionName)
// 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 { homeScreen {
verifyHomeScreen() closeTab()
onView(ViewMatchers.withId(R.id.close_tab_button)).click() }.openNavigationToolbar {
// On homeview, expand the collection and open the first saved page }.enterURLAndEnterToBrowser(secondWebPage.url) {
org.mozilla.fenix.ui.robots.mDevice.wait( }.openHomeScreen {
Until.findObject(By.text("Test_Page_2")), expandCollection(firstCollectionName)
TestAssetHelper.waitingTime) clickCollectionThreeDotButton()
onView(ViewMatchers.withText("Test_Page_2")).click() selectAddTabToCollection()
verifyTabsSelectedCounterText(1)
saveTabsSelectedForCollection()
verifySnackBarText("Tab saved!")
verifyItemInCollectionExists(secondWebPage.title)
} }
}
@Test
fun collectionMenuOpenAllTabsTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
createCollection(firstCollectionName)
// Page content: 2 homeScreen {
browserScreen { closeTab()
verifyPageContent("Page content: 2") expandCollection(firstCollectionName)
clickCollectionThreeDotButton()
selectOpenTabs()
verifyExistingOpenTabs(firstWebPage.title)
} }
} }
@Test @Test
@Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793")
// Rename Collection from the Homescreen
fun renameCollectionTest() { fun renameCollectionTest() {
createCollection(firstCollectionName)
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
createCollection(firstWebPage.url, "testcollection_1")
homeScreen { homeScreen {
// On homeview, tap the 3-dot button to expand, select rename, rename collection // On homeview, tap the 3-dot button to expand, select rename, rename collection
expandCollection(firstCollectionName)
clickCollectionThreeDotButton() clickCollectionThreeDotButton()
selectRenameCollection() selectRenameCollection()
typeCollectionName("renamed_collection") typeCollectionName("renamed_collection")
mDevice.wait(Until.findObject(By.text("renamed_collection")), TestAssetHelper.waitingTime) verifyCollectionIsDisplayed("renamed_collection")
// Verify the new name is displayed on homeview
onView(ViewMatchers.withText("renamed_collection"))
.check(ViewAssertions
.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
} }
} }
@Test @Test
@Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793")
// Delete Collection from the Homescreen
fun deleteCollectionTest() { fun deleteCollectionTest() {
createCollection(firstCollectionName)
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
createCollection(firstWebPage.url, "testcollection_1")
homeScreen { homeScreen {
// Choose delete collection from homeview, and confirm expandCollection(firstCollectionName)
clickCollectionThreeDotButton() clickCollectionThreeDotButton()
selectDeleteCollection() selectDeleteCollection()
confirmDeleteCollection() confirmDeleteCollection()
verifyNoCollectionsHeader()
// Check for No collections caption
onView(ViewMatchers.withText("No collections"))
.check(ViewAssertions
.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
} }
} }
@Test @Test
@Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793") fun createCollectionFromTabTest() {
fun createCollectionTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
createCollection(firstWebPage.url, "testcollection_1") createCollection(firstCollectionName)
createCollection(secondWebPage.url, "testcollection_2", false)
// On the main screen, swipe to bottom until the collections are shown
homeScreen { homeScreen {
// swipe to bottom until the collections are shown // swipe to bottom until the collections are shown
verifyHomeScreen() verifyExistingOpenTabs(firstWebPage.title)
try { try {
onView(ViewMatchers.withText("testcollection_1")) verifyCollectionIsDisplayed(firstCollectionName)
.check(ViewAssertions
.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
} catch (e: NoMatchingViewException) { } catch (e: NoMatchingViewException) {
scrollToElementByText("testcollection_1") scrollToElementByText(firstCollectionName)
} }
onView(ViewMatchers.withText("testcollection_2")).check(ViewAssertions
.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
} }
} }
private fun createCollection(url: Uri, collectionName: String, firstCollection: Boolean = true) { @Test
fun verifyExpandedCollectionItemsTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
// Open a webpage and save to collection "testcollection_1" createCollection(firstCollectionName)
homeScreen {
verifyCollectionIsDisplayed(firstCollectionName)
verifyCollectionIcon()
expandCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title)
verifyCollectionItemLogo()
verifyCollectionItemUrl()
verifyShareCollectionButtonIsVisible(true)
verifyCollectionMenuIsVisible(true)
verifyCollectionItemRemoveButtonIsVisible(firstWebPage.title, true)
collapseCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title, false)
verifyShareCollectionButtonIsVisible(false)
verifyCollectionMenuIsVisible(false)
verifyCollectionItemRemoveButtonIsVisible(firstWebPage.title, false)
}
}
@Test
fun shareCollectionTest() {
createCollection(firstCollectionName)
homeScreen {
expandCollection(firstCollectionName)
clickShareCollectionButton()
verifyShareTabsOverlay()
}
}
@Test
fun removeTabFromCollectionTest() {
val webPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
createCollection(firstCollectionName)
homeScreen {
closeTab()
expandCollection(firstCollectionName)
removeTabFromCollection(webPage.title)
verifyItemInCollectionExists(webPage.title, false)
}
createCollection(firstCollectionName)
homeScreen {
closeTab()
expandCollection(firstCollectionName)
swipeCollectionItemLeft(webPage.title)
verifyItemInCollectionExists(webPage.title, false)
}
createCollection(firstCollectionName)
homeScreen {
closeTab()
expandCollection(firstCollectionName)
swipeCollectionItemRight(webPage.title)
verifyItemInCollectionExists(webPage.title, false)
}
}
@Test
fun selectTabOnLongTapTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
navigationToolbar { navigationToolbar {
}.enterURLAndEnterToBrowser(url) { }.enterURLAndEnterToBrowser(firstWebPage.url) {
verifyPageContent(firstWebPage.content) }.openHomeScreen {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
}.openHomeScreen {
longTapSelectTab(firstWebPage.title)
verifySelectTabsView()
verifyTabsSelectedCounterText(1)
selectTabForCollection(secondWebPage.title)
verifyTabsSelectedCounterText(2)
saveTabsSelectedForCollection()
typeCollectionName(firstCollectionName)
verifySnackBarText("Tabs saved!")
closeTabViaXButton(firstWebPage.title)
closeTabViaXButton(secondWebPage.title)
expandCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title)
verifyItemInCollectionExists(secondWebPage.title)
} }
}
@Test
fun tabsOverflowMenuSaveCollectionTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
}.openHomeScreen {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
}.openHomeScreen {
}.openTabsListThreeDotMenu {
verifySaveCollection()
}.clickOpenTabsMenuSaveCollection {
verifySelectTabsView()
verifyTabsSelectedCounterText(0)
selectAllTabsForCollection()
verifyTabsSelectedCounterText(2)
saveTabsSelectedForCollection()
typeCollectionName(firstCollectionName)
closeTabViaXButton(firstWebPage.title)
closeTabViaXButton(secondWebPage.title)
expandCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title)
verifyItemInCollectionExists(secondWebPage.title)
}
}
@Test
fun navigateBackInCollectionFlowTest() {
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
createCollection(firstCollectionName)
navigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
}.openHomeScreen {
longTapSelectTab(secondWebPage.title)
verifySelectTabsView()
saveTabsSelectedForCollection()
verifySelectCollectionView()
clickAddNewCollection()
verifyNameCollectionView()
goBackCollectionFlow()
verifySelectCollectionView()
goBackCollectionFlow()
verifySelectTabsView()
goBackCollectionFlow()
verifyHomeComponent()
}
}
private fun createCollection(collectionName: String, firstCollection: Boolean = true) {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
navigationToolbar { navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
verifyPageContent(firstWebPage.content)
}.openThreeDotMenu { }.openThreeDotMenu {
// click save to collection menu item, type collection name
clickBrowserViewSaveCollectionButton() clickBrowserViewSaveCollectionButton()
if (!firstCollection) if (!firstCollection)
clickAddNewCollection() clickAddNewCollection()
}.typeCollectionName(collectionName) {} }.typeCollectionName(collectionName) {
verifySnackBarText("Tab saved!")
mDevice.pressBack() // go to main page }.openHomeScreen {
org.mozilla.fenix.ui.robots.mDevice.wait( mDevice.wait(
Until.findObject(By.text(collectionName)), Until.findObject(By.text(collectionName)),
TestAssetHelper.waitingTime) TestAssetHelper.waitingTime
)
}
} }
} }

@ -237,13 +237,6 @@ class BrowserRobot {
menuSaveImage.click() menuSaveImage.click()
} }
fun waitForCollectionSavedPopup() {
mDevice.wait(
Until.findObject(text("Tab saved!")),
waitingTime
)
}
fun createBookmark(url: Uri) { fun createBookmark(url: Uri) {
navigationToolbar { navigationToolbar {
}.enterURLAndEnterToBrowser(url) { }.enterURLAndEnterToBrowser(url) {

@ -9,8 +9,12 @@ package org.mozilla.fenix.ui.robots
import android.graphics.Bitmap import android.graphics.Bitmap
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onView import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.action.ViewActions import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.longClick
import androidx.test.espresso.action.ViewActions.swipeLeft
import androidx.test.espresso.action.ViewActions.swipeRight
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions import androidx.test.espresso.contrib.RecyclerViewActions
@ -18,6 +22,7 @@ import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem
import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.Visibility import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.hasSibling
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
@ -125,40 +130,193 @@ class HomeScreenRobot {
// Collections element // Collections element
fun clickCollectionThreeDotButton() { fun clickCollectionThreeDotButton() {
collectionThreeDotButton().click() collectionThreeDotButton().click()
mDevice.waitNotNull(Until.findObject(By.text("Delete collection")), waitingTime) mDevice.waitNotNull(findObject(text("Delete collection")), waitingTime)
}
fun selectOpenTabs() {
onView(allOf(withText("Open tabs"))).click()
} }
fun selectRenameCollection() { fun selectRenameCollection() {
onView(allOf(ViewMatchers.withText("Rename collection"))).click() onView(allOf(withText("Rename collection"))).click()
mDevice.waitNotNull(Until.findObject(By.res("name_collection_edittext"))) mDevice.waitNotNull(findObject(text("Rename collection")))
}
fun selectAddTabToCollection() {
onView(allOf(withText("Add tab"))).click()
mDevice.waitNotNull(findObject(text("Select Tabs")))
} }
fun selectDeleteCollection() { fun selectDeleteCollection() {
onView(allOf(ViewMatchers.withText("Delete collection"))).click() onView(allOf(withText("Delete collection"))).click()
mDevice.waitNotNull(Until.findObject(By.res("message")), waitingTime) mDevice.waitNotNull(findObject(By.res("android:id/message")), waitingTime)
} }
fun confirmDeleteCollection() { fun confirmDeleteCollection() {
onView(allOf(ViewMatchers.withText("DELETE"))).click() onView(allOf(withText("DELETE"))).click()
mDevice.waitNotNull(Until.findObject(By.res("collections_header")), waitingTime) mDevice.waitNotNull(findObject(By.res("org.mozilla.fenix.debug:id/collections_header")), waitingTime)
} }
fun typeCollectionName(name: String) { fun typeCollectionName(name: String) {
mDevice.wait(Until.findObject(By.res("name_collection_edittext")), waitingTime) mDevice.wait(findObject(By.res("org.mozilla.fenix.debug:id/name_collection_edittext")), waitingTime)
collectionNameTextField().perform(ViewActions.replaceText(name)) collectionNameTextField().perform(ViewActions.replaceText(name))
collectionNameTextField().perform(ViewActions.pressImeActionButton()) collectionNameTextField().perform(ViewActions.pressImeActionButton())
mDevice.waitNotNull(Until.gone(text("Name collection")))
}
fun saveTabsSelectedForCollection() = onView(withId(R.id.save_button)).click()
fun verifyCollectionIsDisplayed(title: String) {
mDevice.wait(findObject(text(title)), waitingTime)
collectionTitle(title).check(matches(isDisplayed()))
}
fun verifyCollectionIcon() =
onView(withId(R.id.collection_icon)).check(matches(isDisplayed()))
fun expandCollection(title: String) {
try {
mDevice.waitNotNull(findObject(text(title)), waitingTime)
collectionTitle(title).click()
} catch (e: NoMatchingViewException) {
scrollToElementByText(title)
}
}
fun collapseCollection(title: String) {
try {
mDevice.waitNotNull(findObject(text(title)), waitingTime)
onView(allOf(withId(R.id.chevron), hasSibling(withText(title)))).click()
} catch (e: NoMatchingViewException) {
scrollToElementByText(title)
}
}
fun clickSaveCollectionButton() = saveCollectionButton().click()
fun verifyItemInCollectionExists(title: String, visible: Boolean = true) {
try {
collectionItem(title)
.check(
if (visible) matches(isDisplayed()) else doesNotExist()
)
} catch (e: NoMatchingViewException) {
scrollToElementByText(title)
}
}
fun verifyCollectionItemLogo() =
onView(withId(R.id.list_item_favicon)).check(matches(isDisplayed()))
fun verifyCollectionItemUrl() =
onView(withId(R.id.list_item_url)).check(matches(isDisplayed()))
fun verifyShareCollectionButtonIsVisible(visible: Boolean) {
shareCollectionButton()
.check(
if (visible) matches(withEffectiveVisibility(Visibility.VISIBLE))
else matches(withEffectiveVisibility(Visibility.GONE))
)
} }
fun verifyCollectionMenuIsVisible(visible: Boolean) {
collectionThreeDotButton()
.check(
if (visible) matches(withEffectiveVisibility(Visibility.VISIBLE))
else matches(withEffectiveVisibility(Visibility.GONE))
)
}
fun verifyCollectionItemRemoveButtonIsVisible(title: String, visible: Boolean) {
removeTabFromCollectionButton(title)
.check(
if (visible) matches(withEffectiveVisibility(Visibility.VISIBLE))
else doesNotExist()
)
}
fun verifySelectTabsView(vararg tabTitles: String) {
onView(allOf(withId(R.id.back_button), withText("Select Tabs")))
.check(matches(isDisplayed()))
for (title in tabTitles)
onView(withId(R.id.tab_list)).check(matches(hasItem(withText(title))))
}
fun verifyTabsSelectedCounterText(tabsSelected: Int) {
when (tabsSelected) {
0 -> onView(withId(R.id.bottom_bar_text)).check(matches(withText("Select tabs to save")))
1 -> onView(withId(R.id.bottom_bar_text)).check(matches(withText("1 tab selected")))
else -> onView(withId(R.id.bottom_bar_text)).check(matches(withText("$tabsSelected tabs selected")))
}
}
fun selectAllTabsForCollection() {
onView(withId(R.id.select_all_button))
.check(matches(withText("Select All")))
.click()
}
fun deselectAllTabsForCollection() {
onView(withId(R.id.select_all_button))
.check(matches(withText("Deselect All")))
.click()
}
fun selectTabForCollection(title: String) {
tab(title).click()
}
fun clickAddNewCollection() =
onView(allOf(withText("Add new collection"))).click()
fun verifyNameCollectionView() {
onView(allOf(withId(R.id.back_button), withText("Name collection")))
.check(matches(isDisplayed()))
}
fun verifyDefaultCollectionName(name: String) =
onView(withId(R.id.name_collection_edittext)).check(matches(withText(name)))
fun verifySelectCollectionView() {
onView(allOf(withId(R.id.back_button), withText("Select collection")))
.check(matches(isDisplayed()))
}
fun verifyShareTabsOverlay() = assertShareTabsOverlay()
fun clickShareCollectionButton() = onView(withId(R.id.collection_share_button)).click()
fun removeTabFromCollection(title: String) = removeTabFromCollectionButton(title).click()
fun swipeCollectionItemRight(title: String) {
try {
collectionItem(title).perform(swipeRight())
} catch (e: NoMatchingViewException) {
scrollToElementByText(title)
}
}
fun swipeCollectionItemLeft(title: String) {
try {
collectionItem(title).perform(swipeLeft())
} catch (e: NoMatchingViewException) {
scrollToElementByText(title)
}
}
fun longTapSelectTab(title: String) {
tab(title).perform(longClick())
}
fun goBackCollectionFlow() = collectionFlowBackButton().click()
fun scrollToElementByText(text: String): UiScrollable { fun scrollToElementByText(text: String): UiScrollable {
val appView = UiScrollable(UiSelector().scrollable(true)) val appView = UiScrollable(UiSelector().scrollable(true))
appView.scrollTextIntoView(text) appView.scrollTextIntoView(text)
return appView return appView
} }
fun swipeUpToDismissFirstRun() {
scrollToElementByText("Start browsing")
}
fun closeTab() { fun closeTab() {
closeTabButton().click() closeTabButton().click()
} }
@ -174,16 +332,16 @@ class HomeScreenRobot {
onView(withId(R.id.sessionControlRecyclerView)).perform(ViewActions.swipeDown()) onView(withId(R.id.sessionControlRecyclerView)).perform(ViewActions.swipeDown())
fun swipeTabRight(title: String) = fun swipeTabRight(title: String) =
onView(allOf(withId(R.id.tab_title), withText(title))).perform(ViewActions.swipeRight()) tab(title).perform(ViewActions.swipeRight())
fun swipeTabLeft(title: String) = fun swipeTabLeft(title: String) =
onView(allOf(withId(R.id.tab_title), withText(title))).perform(ViewActions.swipeLeft()) tab(title).perform(ViewActions.swipeLeft())
fun closeTabViaXButton(title: String) = closeTabViaX(title) fun closeTabViaXButton(title: String) = closeTabViaX(title)
fun verifySnackBarText(expectedText: String) { fun verifySnackBarText(expectedText: String) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(Until.findObject(By.text(expectedText)), TestAssetHelper.waitingTime) mDevice.waitNotNull(findObject(By.text(expectedText)), TestAssetHelper.waitingTime)
} }
fun snackBarButtonClick(expectedText: String) { fun snackBarButtonClick(expectedText: String) {
@ -228,10 +386,6 @@ class HomeScreenRobot {
openThreeDotMenu { }.openSettings { }.goBack { } openThreeDotMenu { }.openSettings { }.goBack { }
} }
fun addNewTab() {
openSearch { }.openBrowser { }.openHomeScreen { }
}
fun togglePrivateBrowsingMode() { fun togglePrivateBrowsingMode() {
onView(ViewMatchers.withResourceName("privateBrowsingButton")) onView(ViewMatchers.withResourceName("privateBrowsingButton"))
.perform(click()) .perform(click())
@ -315,12 +469,7 @@ class HomeScreenRobot {
fun openTab(title: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition { fun openTab(title: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
mDevice.waitNotNull(findObject(text(title))) mDevice.waitNotNull(findObject(text(title)))
onView( tab(title).click()
allOf(
withId(R.id.tab_title),
withText(title)
)
).click()
BrowserRobot().interact() BrowserRobot().interact()
return BrowserRobot.Transition() return BrowserRobot.Transition()
@ -582,12 +731,20 @@ private fun assertExistingTabList() =
onView(allOf(withId(R.id.item_tab))) onView(allOf(withId(R.id.item_tab)))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertExistingOpenTabs(title: String) = private fun assertExistingOpenTabs(title: String) {
onView(withId(R.id.sessionControlRecyclerView)).perform( try {
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>( tab(title).check(matches(isDisplayed()))
ViewMatchers.hasDescendant(withText(title)) } catch (e: NoMatchingViewException) {
) onView(withId(R.id.sessionControlRecyclerView)).perform(
).check(matches(withEffectiveVisibility(Visibility.VISIBLE))) RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
allOf(
withId(R.id.tab_title),
withText(title)
)
)
).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}
}
private fun tabsListThreeDotButton() = onView(allOf(withId(R.id.tabs_overflow_button))) private fun tabsListThreeDotButton() = onView(allOf(withId(R.id.tabs_overflow_button)))
@ -597,6 +754,9 @@ private fun collectionThreeDotButton() =
private fun collectionNameTextField() = private fun collectionNameTextField() =
onView(allOf(ViewMatchers.withResourceName("name_collection_edittext"))) 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) { private fun closeTabViaX(title: String) {
val closeButton = onView( val closeButton = onView(
allOf( allOf(
@ -626,13 +786,45 @@ private fun assertTopSiteContextMenuItems() {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.text("Open in private tab")), findObject(By.text("Open in private tab")),
waitingTime waitingTime
) )
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.text("Remove")), findObject(By.text("Remove")),
waitingTime waitingTime
) )
} }
private fun assertShareTabsOverlay() {
onView(withId(R.id.shared_site_list)).check(matches(isDisplayed()))
onView(withId(R.id.share_tab_title)).check(matches(isDisplayed()))
onView(withId(R.id.share_tab_favicon)).check(matches(isDisplayed()))
onView(withId(R.id.share_tab_url)).check(matches(isDisplayed()))
}
private fun tabMediaControlButton() = onView(withId(R.id.play_pause_button)) private fun tabMediaControlButton() = onView(withId(R.id.play_pause_button))
private fun collectionItem(title: String) =
onView(allOf(withId(R.id.list_element_title), withText(title)))
private fun saveCollectionButton() = onView(withId(R.id.save_tab_group_button))
private fun shareCollectionButton() = onView(withId(R.id.collection_share_button))
private fun removeTabFromCollectionButton(title: String) =
onView(
allOf(
withId(R.id.list_item_action_button),
hasSibling(withText(title))
)
)
private fun collectionFlowBackButton() = onView(withId(R.id.back_button))
private fun tab(title: String) =
onView(
allOf(
withId(R.id.tab_title),
withText(title)
)
)

@ -15,7 +15,6 @@ import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.Visibility import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.hasFocus
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
@ -57,6 +56,7 @@ class ThreeDotMenuMainRobot {
fun verifyShareTabButton() = assertShareTabButton() fun verifyShareTabButton() = assertShareTabButton()
fun verifySaveCollection() = assertSaveCollectionButton() fun verifySaveCollection() = assertSaveCollectionButton()
fun clickBrowserViewSaveCollectionButton() { fun clickBrowserViewSaveCollectionButton() {
browserViewSaveCollectionButton().click() browserViewSaveCollectionButton().click()
} }
@ -198,11 +198,12 @@ class ThreeDotMenuMainRobot {
waitingTime waitingTime
) )
collectionNameTextField().check(matches(hasFocus()))
collectionNameTextField().perform( collectionNameTextField().perform(
ViewActions.replaceText(name), ViewActions.replaceText(name),
ViewActions.pressImeActionButton() ViewActions.pressImeActionButton()
) )
// wait for the collection creation wrapper to be dismissed
mDevice.waitNotNull(Until.gone(By.res("org.mozilla.fenix.debug:id/createCollectionWrapper")))
BrowserRobot().interact() BrowserRobot().interact()
return BrowserRobot.Transition() return BrowserRobot.Transition()
@ -236,6 +237,21 @@ class ThreeDotMenuMainRobot {
AddToHomeScreenRobot().interact() AddToHomeScreenRobot().interact()
return AddToHomeScreenRobot.Transition() return AddToHomeScreenRobot.Transition()
} }
fun selectExistingCollection(title: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
mDevice.waitNotNull(Until.findObject(By.text(title)), waitingTime)
onView(withText(title)).click()
BrowserRobot().interact()
return BrowserRobot.Transition()
}
fun clickOpenTabsMenuSaveCollection(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
saveCollectionButton().click()
HomeScreenRobot().interact()
return HomeScreenRobot.Transition()
}
} }
} }

Loading…
Cancel
Save