Skip to content

Commit

Permalink
For mozilla-mobile#21002: improves the share tabs smoke tests coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Horvath authored and pkirakosyan committed Mar 7, 2022
1 parent cb0b9d3 commit c86683f
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 133 deletions.
13 changes: 13 additions & 0 deletions app/src/androidTest/java/org/mozilla/fenix/ui/ContextMenusTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,17 @@ class ContextMenusTest {
verifyNoLinkImageContextMenuItems(imageResource.url)
}
}

@SmokeTest
@Test
fun shareSelectedTextTest() {
val genericURL = TestAssetHelper.getGenericAsset(mockWebServer, 1)

navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
longClickMatchingText(genericURL.content)
}.clickShareSelectedText {
verifyAndroidShareLayout()
}
}
}
65 changes: 0 additions & 65 deletions app/src/androidTest/java/org/mozilla/fenix/ui/ShareButtonTest.kt

This file was deleted.

64 changes: 42 additions & 22 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,10 @@ class SmokeTest {
navigationToolbar {
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
}.openThreeDotMenu {
}.sharePage {
verifyShareAppsLayout()
}.clickShareButton {
verifyShareTabLayout()
verifySendToDeviceTitle()
verifyShareALinkTitle()
}
}

Expand Down Expand Up @@ -879,22 +881,28 @@ class SmokeTest {

@Test
fun shareCollectionTest() {
val webPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val firstWebsite = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebsite = TestAssetHelper.getGenericAsset(mockWebServer, 2)
val sharingApp = "Gmail"
val urlString = "${secondWebsite.url}\n\n${firstWebsite.url}"

navigationToolbar {
}.enterURLAndEnterToBrowser(webPage.url) {
}.enterURLAndEnterToBrowser(firstWebsite.url) {
verifyPageContent(firstWebsite.content)
}.openTabDrawer {
createCollection(webPage.title, collectionName)
snackBarButtonClick("VIEW")
}

homeScreen {
createCollection(firstWebsite.title, collectionName)
}.openNewTab {
}.submitQuery(secondWebsite.url.toString()) {
verifyPageContent(secondWebsite.content)
}.openThreeDotMenu {
}.openSaveToCollection {
}.selectExistingCollection(collectionName) {
}.goToHomescreen {
}.expandCollection(collectionName) {
clickShareCollectionButton()
}

homeScreen {
verifyShareTabsOverlay()
}.clickShareCollectionButton {
verifyShareTabsOverlay(firstWebsite.title, secondWebsite.title)
selectAppToShareWith(sharingApp)
verifySharedTabsIntent(urlString, collectionName)
}
}

Expand Down Expand Up @@ -964,21 +972,33 @@ class SmokeTest {

@Test
fun shareTabsFromTabsTrayTest() {
val website = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val firstWebsite = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebsite = TestAssetHelper.getGenericAsset(mockWebServer, 2)
val firstWebsiteTitle = firstWebsite.title
val secondWebsiteTitle = secondWebsite.title
val sharingApp = "Gmail"
val sharedUrlsString = "${firstWebsite.url}\n\n${secondWebsite.url}"

homeScreen {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(website.url) {
mDevice.waitForIdle()
}.enterURLAndEnterToBrowser(firstWebsite.url) {
verifyPageContent(firstWebsite.content)
}.openTabDrawer {
}.openNewTab {
}.submitQuery(secondWebsite.url.toString()) {
verifyPageContent(secondWebsite.content)
}.openTabDrawer {
verifyNormalModeSelected()
verifyExistingTabList()
verifyExistingOpenTabs("Test_Page_1")
verifyTabTrayOverflowMenu(true)
verifyExistingOpenTabs("Test_Page_2")
}.openTabsListThreeDotMenu {
verifyShareAllTabsButton()
clickShareAllTabsButton()
verifyShareTabsOverlay()
}.clickShareAllTabsButton {
verifyShareTabsOverlay(firstWebsiteTitle, secondWebsiteTitle)
selectAppToShareWith(sharingApp)
verifySharedTabsIntent(
sharedUrlsString,
"$firstWebsiteTitle, $secondWebsiteTitle"
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,14 @@ class BrowserRobot {
HomeScreenRobot().interact()
return HomeScreenRobot.Transition()
}

fun clickShareSelectedText(interact: ShareOverlayRobot.() -> Unit): ShareOverlayRobot.Transition {
val shareTextButton = org.mozilla.fenix.ui.robots.mDevice.findObject(By.textContains("Share"))
shareTextButton.click()

ShareOverlayRobot().interact()
return ShareOverlayRobot.Transition()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class CollectionRobot {
)
}

fun clickShareCollectionButton() = onView(withId(R.id.collection_share_button)).click()

fun verifyCollectionMenuIsVisible(visible: Boolean) {
collectionThreeDotButton()
.check(
Expand Down Expand Up @@ -240,6 +238,13 @@ class CollectionRobot {
BrowserRobot().interact()
return BrowserRobot.Transition()
}

fun clickShareCollectionButton(interact: ShareOverlayRobot.() -> Unit): ShareOverlayRobot.Transition {
shareCollectionButton().click()

ShareOverlayRobot().interact()
return ShareOverlayRobot.Transition()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ class HomeScreenRobot {

fun verifyCollectionIcon() = onView(withId(R.id.collection_icon)).check(matches(isDisplayed()))

fun verifyShareTabsOverlay() = assertShareTabsOverlay()

fun togglePrivateBrowsingModeOnOff() {
onView(ViewMatchers.withResourceName("privateBrowsingButton"))
.perform(click())
Expand Down Expand Up @@ -584,13 +582,6 @@ private fun assertTopSiteContextMenuItems() {
)
}

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 assertJumpBackInSectionIsDisplayed() = jumpBackInSection().check(matches(isDisplayed()))

private fun assertJumpBackInSectionIsNotDisplayed() = jumpBackInSection().check(doesNotExist())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class SearchRobot {

fun submitQuery(query: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
sessionLoadedIdlingResource = SessionLoadedIdlingResource()
mDevice.waitForIdle()
searchWrapper().waitForExists(waitingTime)
browserToolbarEditView().setText(query)
mDevice.pressEnter()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package org.mozilla.fenix.ui.robots

import android.content.Intent
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers
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.withId
import androidx.test.espresso.matcher.ViewMatchers.withResourceName
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.hamcrest.Matchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.ext.waitNotNull

class ShareOverlayRobot {

// This function verifies the share layout when more than one tab is shared - a list of tabs is shown
fun verifyShareTabsOverlay(vararg tabsTitles: String) {
onView(withId(R.id.shared_site_list))
.check(matches(isDisplayed()))
for (tabs in tabsTitles) {
onView(withText(tabs))
.check(
matches(
allOf(
hasSibling(withId(R.id.share_tab_favicon)),
hasSibling(withId(R.id.share_tab_url))
)
)
)
}
}

// This function verifies the share layout when a single tab is shared - no tab info shown
fun verifyShareTabLayout() = assertShareTabLayout()

// this verifies the Android sharing layout - not customized for sharing tabs
fun verifyAndroidShareLayout() {
mDevice.waitNotNull(Until.findObject(By.res("android:id/resolver_list")))
}

fun selectAppToShareWith(appName: String) =
mDevice.findObject(UiSelector().text(appName)).clickAndWaitForNewWindow()

fun verifySendToDeviceTitle() = assertSendToDeviceTitle()

fun verifyShareALinkTitle() = assertShareALinkTitle()

fun verifySharedTabsIntent(text: String, subject: String) {
Intents.intended(
allOf(
IntentMatchers.hasExtra(Intent.EXTRA_TEXT, text),
IntentMatchers.hasExtra(Intent.EXTRA_SUBJECT, subject)
)
)
}

class Transition
}

private fun shareTabsLayout() = onView(withResourceName("shareWrapper"))

private fun assertShareTabLayout() =
shareTabsLayout().check(matches(isDisplayed()))

private fun sendToDeviceTitle() =
onView(
allOf(
withText("SEND TO DEVICE"),
withResourceName("accountHeaderText")
)
)

private fun assertSendToDeviceTitle() = sendToDeviceTitle()
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))

private fun shareALinkTitle() =
onView(
allOf(
withText("ALL ACTIONS"),
withResourceName("apps_link_header")
)
)

private fun assertShareALinkTitle() = shareALinkTitle()
Loading

0 comments on commit c86683f

Please sign in to comment.