1
0
Fork 0

Added multi-selection tests for bookmarks (#6475)

Updated bookmarking method

Fixed flaky tests

Added wait to create bookmark
master
Oana Horvath 2019-12-03 12:44:54 +02:00 committed by GitHub
parent 85d222d2b1
commit 85dd56e12d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 187 additions and 25 deletions

View File

@ -7,11 +7,14 @@ package org.mozilla.fenix.helpers
import android.net.Uri
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.longClick
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.hamcrest.CoreMatchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.ext.waitNotNull
import org.mozilla.fenix.ui.robots.mDevice
@ -27,6 +30,11 @@ object TestHelper {
Until.findObject(By.text(url.toString())),
TestAssetHelper.waitingTime
)
onView(withText(url.toString())).perform(longClick())
onView(
allOf(
withId(R.id.url),
withText(url.toString())
)
).perform(longClick())
}
}

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.ui
import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu
import kotlinx.coroutines.runBlocking
import mozilla.appservices.places.BookmarkRoot
import okhttp3.mockwebserver.MockWebServer
@ -15,8 +16,11 @@ import org.mozilla.fenix.ext.bookmarkStorage
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.longTapSelectItem
import org.mozilla.fenix.ui.robots.bookmarksMenu
import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.multipleSelectionToolbar
import org.mozilla.fenix.ui.robots.navigationToolbar
/**
@ -199,6 +203,116 @@ class BookmarksTest {
}
}
@Test
fun multiSelectionToolbarItemsTest() {
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
browserScreen {
createBookmark(defaultWebPage.url)
}.openThreeDotMenu {
}.openLibrary {
}.openBookmarks {
longTapSelectItem(defaultWebPage.url)
}
multipleSelectionToolbar {
verifyMultiSelectionCheckmark()
verifyMultiSelectionCounter()
verifyShareBookmarksButton()
verifyCloseToolbarButton()
}.closeToolbarReturnToBookmarks {
verifyBookmarksMenuView()
}
}
@Test
fun openSelectionInNewTabTest() {
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
browserScreen {
createBookmark(defaultWebPage.url)
}.openHomeScreen {
closeTab()
}.openThreeDotMenu {
}.openLibrary {
}.openBookmarks {
longTapSelectItem(defaultWebPage.url)
openActionBarOverflowOrOptionsMenu(activityTestRule.activity)
}
multipleSelectionToolbar {
}.clickOpenNewTab {
verifyExistingTabList()
verifyOpenTabsHeader()
}
}
@Test
fun openSelectionInPrivateTabTest() {
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
browserScreen {
createBookmark(defaultWebPage.url)
}.openThreeDotMenu {
}.openLibrary {
}.openBookmarks {
longTapSelectItem(defaultWebPage.url)
openActionBarOverflowOrOptionsMenu(activityTestRule.activity)
}
multipleSelectionToolbar {
}.clickOpenPrivateTab {
verifyExistingTabList()
verifyPrivateSessionHeader()
}
}
@Test
fun deleteMultipleSelectionTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
browserScreen {
createBookmark(firstWebPage.url)
createBookmark(secondWebPage.url)
}.openThreeDotMenu {
}.openLibrary {
}.openBookmarks {
longTapSelectItem(firstWebPage.url)
longTapSelectItem(secondWebPage.url)
openActionBarOverflowOrOptionsMenu(activityTestRule.activity)
}
multipleSelectionToolbar {
clickMultiSelectionDelete()
}
bookmarksMenu {
verifyEmptyBookmarksList()
}
}
@Test
fun shareButtonTest() {
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
browserScreen {
createBookmark(defaultWebPage.url)
}.openThreeDotMenu {
}.openLibrary {
}.openBookmarks {
longTapSelectItem(defaultWebPage.url)
}
multipleSelectionToolbar {
clickShareBookmarksButton()
verifyShareOverlay()
verifyShareTabFavicon()
verifyShareTabTitle()
verifyShareTabUrl()
}
}
@Test
fun multipleBookmarkDeletions() {
homeScreen {

View File

@ -18,6 +18,7 @@ import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.longTapSelectItem
import org.mozilla.fenix.ui.robots.historyMenu
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.multipleSelectionToolbar
import org.mozilla.fenix.ui.robots.navigationToolbar
@ -129,7 +130,7 @@ class HistoryTest {
multipleSelectionToolbar {
verifyMultiSelectionCheckmark()
verifyMultiSelectionCounter()
verifyShareButton()
verifyShareHistoryButton()
verifyCloseToolbarButton()
}.closeToolbarReturnToHistory {
verifyHistoryMenuView()
@ -200,7 +201,10 @@ class HistoryTest {
}
multipleSelectionToolbar {
}.clickMultiSelectionDelete {
clickMultiSelectionDelete()
}
historyMenu {
verifyEmptyHistoryView()
}
}
@ -219,7 +223,7 @@ class HistoryTest {
}
multipleSelectionToolbar {
clickShareButton()
clickShareHistoryButton()
verifyShareOverlay()
verifyShareTabFavicon()
verifyShareTabTitle()

View File

@ -17,13 +17,17 @@ import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withParent
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.containsString
import org.junit.Assert.assertEquals
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.helpers.ext.waitNotNull
/**
* Implementation of Robot Pattern for the bookmarks menu.
@ -38,7 +42,13 @@ class BookmarksRobot {
fun verifyBookmarkedURL(url: Uri) = assertBookmarkURL(url)
fun verifyFolderTitle(title: String) = assertFolderTitle(title)
fun verifyFolderTitle(title: String) {
mDevice.waitNotNull(
Until.findObject(By.text(title)),
TestAssetHelper.waitingTime
)
assertFolderTitle(title)
}
fun verifyDeleteSnackBarText() = assertDeleteSnackBarText()
@ -52,8 +62,6 @@ class BookmarksRobot {
fun verifyParentFolderSelector() = assertBookmarkFolderSelector()
fun verifyHomeScreen() = HomeScreenRobot().verifyHomeScreen()
fun verifyKeyboardHidden() = assertKeyboardVisibility(isExpectedToBeVisible = false)
fun verifyKeyboardVisible() = assertKeyboardVisibility(isExpectedToBeVisible = true)
@ -82,11 +90,11 @@ class BookmarksRobot {
}
class Transition {
fun goBack(interact: BookmarksRobot.() -> Unit): Transition {
fun goBack(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
goBackButton().click()
BookmarksRobot().interact()
return Transition()
HomeScreenRobot().interact()
return HomeScreenRobot.Transition()
}
fun openThreeDotMenu(interact: ThreeDotMenuBookmarksRobot.() -> Unit): ThreeDotMenuBookmarksRobot.Transition {

View File

@ -95,6 +95,11 @@ class HistoryRobot {
}
}
fun historyMenu(interact: HistoryRobot.() -> Unit): HistoryRobot.Transition {
HistoryRobot().interact()
return HistoryRobot.Transition()
}
private fun goBackButton() = onView(withContentDescription("Navigate up"))
private fun testPageTitle() = onView(allOf(withId(R.id.title), withText("Test_Page_1")))

View File

@ -26,7 +26,9 @@ class LibrarySubMenusMultipleSelectionToolbarRobot {
fun verifyMultiSelectionCounter() = assertMultiSelectionCounter()
fun verifyShareButton() = assertShareButton()
fun verifyShareHistoryButton() = assertShareHistoryButton()
fun verifyShareBookmarksButton() = assertShareBookmarksButton()
fun verifyShareOverlay() = assertShareOverlay()
@ -38,8 +40,8 @@ class LibrarySubMenusMultipleSelectionToolbarRobot {
fun verifyCloseToolbarButton() = assertCloseToolbarButton()
fun clickShareButton() {
shareButton().click()
fun clickShareHistoryButton() {
shareHistoryButton().click()
mDevice.waitNotNull(
Until.findObject(
@ -48,6 +50,20 @@ class LibrarySubMenusMultipleSelectionToolbarRobot {
)
}
fun clickShareBookmarksButton() {
shareBookmarksButton().click()
mDevice.waitNotNull(
Until.findObject(
By.text("SHARE A LINK")
), waitingTime
)
}
fun clickMultiSelectionDelete() {
deleteButton().click()
}
class Transition {
fun closeToolbarReturnToHistory(interact: HistoryRobot.() -> Unit): HistoryRobot.Transition {
closeToolbarButton().click()
@ -81,13 +97,6 @@ class LibrarySubMenusMultipleSelectionToolbarRobot {
HomeScreenRobot().interact()
return HomeScreenRobot.Transition()
}
fun clickMultiSelectionDelete(interact: HistoryRobot.() -> Unit): HistoryRobot.Transition {
multiSelectionDeleteButton().click()
HistoryRobot().interact()
return HistoryRobot.Transition()
}
}
}
@ -99,13 +108,15 @@ fun multipleSelectionToolbar(interact: LibrarySubMenusMultipleSelectionToolbarRo
private fun closeToolbarButton() = onView(withContentDescription("Navigate up"))
private fun shareButton() = onView(withId(R.id.share_history_multi_select))
private fun shareHistoryButton() = onView(withId(R.id.share_history_multi_select))
private fun shareBookmarksButton() = onView(withId(R.id.share_bookmark_multi_select))
private fun openInNewTabButton() = onView(withText("Open in new tab"))
private fun openInPrivateTabButton() = onView(withText("Open in private tab"))
private fun multiSelectionDeleteButton() = onView(withText("Delete"))
private fun deleteButton() = onView(withText("Delete"))
private fun assertMultiSelectionCheckmark() =
onView(withId(R.id.checkmark))
@ -114,8 +125,11 @@ private fun assertMultiSelectionCheckmark() =
private fun assertMultiSelectionCounter() =
onView(withText("1 selected")).check(matches(isDisplayed()))
private fun assertShareButton() =
shareButton().check(matches(isDisplayed()))
private fun assertShareHistoryButton() =
shareHistoryButton().check(matches(isDisplayed()))
private fun assertShareBookmarksButton() =
shareBookmarksButton().check(matches(isDisplayed()))
private fun assertShareOverlay() =
onView(withId(R.id.shareWrapper)).check(matches(isDisplayed()))

View File

@ -53,10 +53,19 @@ class ThreeDotMenuMainRobot {
fun clickBrowserViewSaveCollectionButton() {
browserViewSaveCollectionButton().click()
}
fun clickAddNewCollection() {
addNewCollectionButton().click()
}
fun clickAddBookmarkButton() = addBookmarkButton().click()
fun clickAddBookmarkButton() {
mDevice.waitNotNull(
Until.findObject(By.desc("Bookmark")),
waitingTime
)
addBookmarkButton().click()
}
fun verifyCollectionNameTextField() = assertCollectionNameTextField()
fun verifyFindInPageButton() = assertFindInPageButton()
fun verifyShareScrim() = assertShareScrim()