For #4094 - Improved original PR to fix screenshots tests API21 (#4144)

use robot for three dot menu screenshot
This commit is contained in:
isabelrios 2019-07-22 18:58:53 +02:00 committed by Richard Pappalardo
parent 5ecdce6ba6
commit a984bb4799
3 changed files with 19 additions and 52 deletions

View File

@ -16,6 +16,7 @@ import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.UiDevice
import androidx.test.espresso.matcher.ViewMatchers.Visibility import androidx.test.espresso.matcher.ViewMatchers.Visibility
import org.hamcrest.CoreMatchers import org.hamcrest.CoreMatchers
import org.mozilla.fenix.R
/** /**
* Implementation of Robot Pattern for the settings menu. * Implementation of Robot Pattern for the settings menu.
@ -50,3 +51,5 @@ private fun assertAdvancedHeading() = onView(ViewMatchers.withText("Advanced"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun goBackButton() = onView(CoreMatchers.allOf(withContentDescription("Navigate up"))) private fun goBackButton() = onView(CoreMatchers.allOf(withContentDescription("Navigate up")))
fun swipeToBottom() = onView(ViewMatchers.withId(R.id.recycler_view)).perform(ViewActions.swipeUp())

View File

@ -39,7 +39,7 @@ class ThreeDotMenuRobot {
private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
fun openSettings(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition { fun openSettings(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {
mDevice.wait(Until.findObject(By.text("Settings")), waitingTime) mDevice.wait(Until.findObject(By.text("R.string.settings")), waitingTime)
settingsButton().click() settingsButton().click()
SettingsRobot().interact() SettingsRobot().interact()
@ -47,7 +47,7 @@ class ThreeDotMenuRobot {
} }
fun openLibrary(interact: LibraryRobot.() -> Unit): LibraryRobot.Transition { fun openLibrary(interact: LibraryRobot.() -> Unit): LibraryRobot.Transition {
mDevice.wait(Until.findObject(By.text("Library")), waitingTime) mDevice.wait(Until.findObject(By.text("R.string.Library")), waitingTime)
libraryButton().click() libraryButton().click()
LibraryRobot().interact() LibraryRobot().interact()
@ -90,7 +90,7 @@ class ThreeDotMenuRobot {
private fun threeDotMenuRecyclerViewExists() { private fun threeDotMenuRecyclerViewExists() {
onView(withId(R.id.mozac_browser_menu_recyclerView)).check(matches(isDisplayed())) onView(withId(R.id.mozac_browser_menu_recyclerView)).check(matches(isDisplayed()))
} }
private fun settingsButton() = onView(allOf(withText("Settings"))) private fun settingsButton() = onView(allOf(withText(R.string.settings)))
private fun assertSettingsButton() = settingsButton() private fun assertSettingsButton() = settingsButton()
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) .check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))

View File

@ -9,19 +9,14 @@ import org.junit.Test
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.HomeActivityTestRule import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import tools.fastlane.screengrab.Screengrab import tools.fastlane.screengrab.Screengrab
import tools.fastlane.screengrab.locale.LocaleTestRule import tools.fastlane.screengrab.locale.LocaleTestRule
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.swipeUp
import androidx.test.espresso.matcher.ViewMatchers.withId
import br.com.concretesolutions.kappuccino.actions.ClickActions import br.com.concretesolutions.kappuccino.actions.ClickActions
import org.hamcrest.Matchers.allOf
import org.mozilla.fenix.ui.robots.homeScreen import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.swipeToBottom
class ThreeDotMenuScreenShotTest : ScreenshotTest() { class ThreeDotMenuScreenShotTest : ScreenshotTest() {
@Rule @JvmField @Rule @JvmField
@ -37,7 +32,8 @@ class ThreeDotMenuScreenShotTest : ScreenshotTest() {
@Test @Test
fun threeDotMenu() { fun threeDotMenu() {
onView(allOf(withId(R.id.menuButton))).perform(click()) homeScreen {
}.openThreeDotMenu { }
Screengrab.screenshot("three-dot-menu") Screengrab.screenshot("three-dot-menu")
device.pressBack() device.pressBack()
} }
@ -46,11 +42,10 @@ class ThreeDotMenuScreenShotTest : ScreenshotTest() {
fun settingsTest() { fun settingsTest() {
homeScreen { homeScreen {
}.openThreeDotMenu { }.openThreeDotMenu {
} }.openSettings { }
settingsButton2()
Screengrab.screenshot("settings") Screengrab.screenshot("settings")
SystemClock.sleep(1000) SystemClock.sleep(TestAssetHelper.waitingTime)
settingsAccount() settingsAccount()
Screengrab.screenshot("settings-sync") Screengrab.screenshot("settings-sync")
device.pressBack() device.pressBack()
@ -76,58 +71,29 @@ class ThreeDotMenuScreenShotTest : ScreenshotTest() {
fun settingsAfterScrollMenusTest() { fun settingsAfterScrollMenusTest() {
homeScreen { homeScreen {
}.openThreeDotMenu { }.openThreeDotMenu {
}.openSettings {
swipeToBottom()
} }
settingsButton2() Screengrab.screenshot("settings-scroll-to-bottom")
SystemClock.sleep(1000) SystemClock.sleep(TestAssetHelper.waitingTime)
onView(withId(R.id.switch_widget)).perform(ViewActions.swipeUp())
onView(withId(R.id.switch_widget)).perform(ViewActions.swipeUp())
Screengrab.screenshot("settings-scroll")
SystemClock.sleep(2000)
settingsRemoveData() settingsRemoveData()
Screengrab.screenshot("settings-delete-browsing-data") Screengrab.screenshot("settings-delete-browsing-data")
device.pressBack() device.pressBack()
SystemClock.sleep(TestAssetHelper.waitingTime)
SystemClock.sleep(1000)
onView(withId(R.id.switch_widget)).perform(ViewActions.swipeUp())
onView(withId(R.id.switch_widget)).perform(ViewActions.swipeUp())
Screengrab.screenshot("settings-scroll")
SystemClock.sleep(3000)
settingsTelemetry() settingsTelemetry()
Screengrab.screenshot("settings-telemetry") Screengrab.screenshot("settings-telemetry")
device.pressBack() device.pressBack()
} }
@Test
fun settingsScrollToBottomTest() {
homeScreen {
}.openThreeDotMenu {
}
settingsButton2()
SystemClock.sleep(1000)
onView(withId(R.id.switch_widget)).perform(ViewActions.swipeUp())
onView(withId(R.id.switch_widget)).perform(ViewActions.swipeUp())
onView(withId(R.id.switch_widget)).perform(ViewActions.swipeUp())
Screengrab.screenshot("settings-scroll2")
SystemClock.sleep(1000)
onView(withId(R.id.switch_widget)).perform(ViewActions.swipeUp())
onView(withId(R.id.switch_widget)).perform(ViewActions.swipeUp())
Screengrab.screenshot("settings-scroll3")
SystemClock.sleep(1000)
onView(withId(R.id.recycler_view)).perform(swipeUp())
Screengrab.screenshot("settings-scroll4")
}
@Test @Test
fun libraryTest() { fun libraryTest() {
homeScreen { homeScreen {
}.openThreeDotMenu { }.openThreeDotMenu {
} }.openLibrary { }
libraryButton()
Screengrab.screenshot("library") Screengrab.screenshot("library")
bookmarksButton() bookmarksButton()
Screengrab.screenshot("library-bookmarks") Screengrab.screenshot("library-bookmarks")
device.pressBack() device.pressBack()
@ -136,8 +102,6 @@ class ThreeDotMenuScreenShotTest : ScreenshotTest() {
} }
} }
fun settingsButton2() = ClickActions.click { text(R.string.settings) }
fun libraryButton() = ClickActions.click { text(R.string.browser_menu_your_library) }
fun bookmarksButton() = ClickActions.click { text(R.string.library_bookmarks) } fun bookmarksButton() = ClickActions.click { text(R.string.library_bookmarks) }
fun historyButton() = ClickActions.click { text(R.string.library_history) } fun historyButton() = ClickActions.click { text(R.string.library_history) }
fun settingsAccount() = ClickActions.click { text(R.string.preferences_sync) } fun settingsAccount() = ClickActions.click { text(R.string.preferences_sync) }