2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/18053 Change and fix Intermittent UI test verifyReaderViewToggle

This commit is contained in:
AndiAJ 2021-02-26 12:22:07 +02:00 committed by Oana Horvath
parent 9dbe4620d4
commit 9e6f2b7c64
2 changed files with 54 additions and 14 deletions

View File

@ -5,22 +5,22 @@
package org.mozilla.fenix.ui package org.mozilla.fenix.ui
import android.view.View import android.view.View
import androidx.test.espresso.IdlingRegistry
import okhttp3.mockwebserver.MockWebServer import okhttp3.mockwebserver.MockWebServer
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Ignore
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.ui.robots.navigationToolbar
import androidx.test.espresso.IdlingRegistry
import org.junit.Ignore
import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.AndroidAssetDispatcher import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.ViewVisibilityIdlingResource
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestAssetHelper import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.ViewVisibilityIdlingResource
import org.mozilla.fenix.ui.robots.browserScreen import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.mDevice import org.mozilla.fenix.ui.robots.mDevice
import org.mozilla.fenix.ui.robots.navigationToolbar
/** /**
* Tests for verifying basic functionality of content context menus * Tests for verifying basic functionality of content context menus
@ -125,6 +125,15 @@ class ReaderViewTest {
toggleReaderView() toggleReaderView()
mDevice.waitForIdle() mDevice.waitForIdle()
} }
browserScreen {
verifyPageContent(estimatedReadingTime)
}
navigationToolbar {
verifyCloseReaderViewDetected(true)
toggleReaderView()
mDevice.waitForIdle()
verifyReaderViewDetected(true)
}
if (!FeatureFlags.toolbarMenuFeature) { if (!FeatureFlags.toolbarMenuFeature) {
browserScreen { browserScreen {
@ -134,6 +143,7 @@ class ReaderViewTest {
}.closeBrowserMenuToBrowser { } }.closeBrowserMenuToBrowser { }
} }
if (!FeatureFlags.toolbarMenuFeature) {
navigationToolbar { navigationToolbar {
toggleReaderView() toggleReaderView()
mDevice.waitForIdle() mDevice.waitForIdle()
@ -141,6 +151,7 @@ class ReaderViewTest {
verifyReaderViewAppearance(false) verifyReaderViewAppearance(false)
}.close { } }.close { }
} }
}
@Test @Test
@Ignore("To be re-implemented in https://github.com/mozilla-mobile/fenix/issues/17971") @Ignore("To be re-implemented in https://github.com/mozilla-mobile/fenix/issues/17971")

View File

@ -11,7 +11,6 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onView import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.IdlingRegistry import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.IdlingResource import androidx.test.espresso.IdlingResource
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.action.ViewActions import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.pressImeActionButton import androidx.test.espresso.action.ViewActions.pressImeActionButton
import androidx.test.espresso.action.ViewActions.replaceText import androidx.test.espresso.action.ViewActions.replaceText
@ -60,12 +59,21 @@ class NavigationToolbarRobot {
fun verifyTabButtonShortcutMenuItems() = assertTabButtonShortcutMenuItems() fun verifyTabButtonShortcutMenuItems() = assertTabButtonShortcutMenuItems()
fun verifyReaderViewDetected(visible: Boolean = false): ViewInteraction = fun verifyReaderViewDetected(visible: Boolean = false) =
assertReaderViewDetected(visible) assertReaderViewDetected(visible)
fun verifyCloseReaderViewDetected(visible: Boolean = false) =
assertCloseReaderViewDetected(visible)
fun typeSearchTerm(searchTerm: String) = awesomeBar().perform(typeText(searchTerm)) fun typeSearchTerm(searchTerm: String) = awesomeBar().perform(typeText(searchTerm))
fun toggleReaderView() = readerViewToggle().click() fun toggleReaderView() {
mDevice.findObject(UiSelector()
.resourceId("$packageName:id/mozac_browser_toolbar_page_actions"))
.waitForExists(waitingTime)
readerViewToggle().click()
}
class Transition { class Transition {
@ -312,7 +320,11 @@ private fun goBackButton() = mDevice.pressBack()
private fun readerViewToggle() = private fun readerViewToggle() =
onView(withParent(withId(R.id.mozac_browser_toolbar_page_actions))) onView(withParent(withId(R.id.mozac_browser_toolbar_page_actions)))
private fun assertReaderViewDetected(visible: Boolean) = private fun assertReaderViewDetected(visible: Boolean) {
mDevice.findObject(UiSelector()
.description("Reader view"))
.waitForExists(waitingTime)
onView( onView(
allOf( allOf(
withParent(withId(R.id.mozac_browser_toolbar_page_actions)), withParent(withId(R.id.mozac_browser_toolbar_page_actions)),
@ -322,6 +334,23 @@ private fun assertReaderViewDetected(visible: Boolean) =
if (visible) matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)) if (visible) matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))
else ViewAssertions.doesNotExist() else ViewAssertions.doesNotExist()
) )
}
private fun assertCloseReaderViewDetected(visible: Boolean) {
mDevice.findObject(UiSelector()
.description("Close reader view"))
.waitForExists(waitingTime)
onView(
allOf(
withParent(withId(R.id.mozac_browser_toolbar_page_actions)),
withContentDescription("Close reader view")
)
).check(
if (visible) matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))
else ViewAssertions.doesNotExist()
)
}
inline fun runWithIdleRes(ir: IdlingResource?, pendingCheck: () -> Unit) { inline fun runWithIdleRes(ir: IdlingResource?, pendingCheck: () -> Unit) {
try { try {