From 491a198fae4bf8b62c5281aed22983e70695111a Mon Sep 17 00:00:00 2001 From: isabelrios Date: Thu, 26 Dec 2019 23:22:40 +0100 Subject: [PATCH] For #5074 - Add UI tests for logins and passwords setting menu (#7291) * For #5074 - Add UI tests for logins and passwords setting menu * fix detekt failure * remove old file * fix scroll small screens * fix reviewer comments --- .../mozilla/fenix/ui/SettingsPrivacyTest.kt | 26 ++++++++ .../mozilla/fenix/ui/robots/SettingsRobot.kt | 8 +++ .../SettingsSubMenuLoginsAndPasswordRobot.kt | 62 +++++++++++++++++++ ...bMenuLoginsAndPasswordsSavedLoginsRobot.kt | 37 +++++++++++ .../ui/robots/SettingsTurnOnSyncRobot.kt | 42 +++++++++++++ 5 files changed, 175 insertions(+) create mode 100644 app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordRobot.kt create mode 100644 app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot.kt create mode 100644 app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsTurnOnSyncRobot.kt diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsPrivacyTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsPrivacyTest.kt index de1882f71..df4610fbe 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsPrivacyTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsPrivacyTest.kt @@ -14,6 +14,7 @@ import org.junit.Ignore import org.junit.Test import org.mozilla.fenix.helpers.AndroidAssetDispatcher import org.mozilla.fenix.helpers.HomeActivityTestRule +import org.mozilla.fenix.helpers.TestHelper import org.mozilla.fenix.ui.robots.homeScreen /** @@ -107,6 +108,31 @@ class SettingsPrivacyTest { } } + // Tests only for initial state without signing in. + // For tests after singing in, see SyncIntegration test suite + + @Test + fun loginsAndPasswordsTest() { + homeScreen { + }.openThreeDotMenu { + }.openSettings { + // Necessary to scroll a little bit for all screen sizes + TestHelper.scrollToElementByText("Logins and passwords") + }.openLoginsAndPasswordSubMenu { + verifyDefaultView() + verifyDefaultValueSyncLogins() + }.openSavedLogins { + verifySavedLoginsView() + tapSetupLater() + // Verify that logins list is empty + // Issue #7272 nothing is shown + }.goBack { + }.openSyncLogins { + verifyReadyToScanOption() + verifyUseEmailOption() + } + } + @Ignore("This is a stub test, ignore for now") @Test fun toggleTrackingProtection() { diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsRobot.kt index 108c3a781..be1c5ecff 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsRobot.kt @@ -121,6 +121,14 @@ class SettingsRobot { SettingsSubMenuEnhancedTrackingProtectionRobot().interact() return SettingsSubMenuEnhancedTrackingProtectionRobot.Transition() } + + fun openLoginsAndPasswordSubMenu(interact: SettingsSubMenuLoginsAndPasswordRobot.() -> Unit): SettingsSubMenuLoginsAndPasswordRobot.Transition { + fun loginsAndPasswordsButton() = onView(ViewMatchers.withText("Logins and passwords")) + loginsAndPasswordsButton().click() + + SettingsSubMenuLoginsAndPasswordRobot().interact() + return SettingsSubMenuLoginsAndPasswordRobot.Transition() + } } } diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordRobot.kt new file mode 100644 index 000000000..b2eb39385 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordRobot.kt @@ -0,0 +1,62 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +@file:Suppress("TooManyFunctions") + +package org.mozilla.fenix.ui.robots + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.uiautomator.UiDevice +import org.hamcrest.CoreMatchers +import org.mozilla.fenix.helpers.click + +/** + * Implementation of Robot Pattern for the Privacy Settings > logins and passwords sub menu + */ +class SettingsSubMenuLoginsAndPasswordRobot { + + fun verifyDefaultView() = assertDefaultView() + fun verifyDefaultValueSyncLogins() = asserDefaultValueSyncLogins() + + class Transition { + val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) + + fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition { + goBackButton().perform(ViewActions.click()) + + SettingsRobot().interact() + return SettingsRobot.Transition() + } + + fun openSavedLogins(interact: SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot.() -> Unit): SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot.Transition { + fun savedLoginsButton() = onView(ViewMatchers.withText("Saved logins")) + savedLoginsButton().click() + + SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot().interact() + return SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot.Transition() + } + + fun openSyncLogins(interact: SettingsTurnOnSyncRobot.() -> Unit): SettingsTurnOnSyncRobot.Transition { + fun syncLoginsButton() = onView(ViewMatchers.withText("Sync logins")) + syncLoginsButton().click() + + SettingsTurnOnSyncRobot().interact() + return SettingsTurnOnSyncRobot.Transition() + } + } +} + +private fun goBackButton() = + onView(CoreMatchers.allOf(ViewMatchers.withContentDescription("Navigate up"))) + +private fun assertDefaultView() = onView(ViewMatchers.withText("Sync logins")) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) + +private fun asserDefaultValueSyncLogins() = onView(ViewMatchers.withText("Sign in to Sync")) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot.kt new file mode 100644 index 000000000..ffb6afcef --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot.kt @@ -0,0 +1,37 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.ui.robots + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility +import org.hamcrest.CoreMatchers + +/** + * Implementation of Robot Pattern for the Privacy Settings > saved logins sub menu + */ + +class SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot { + fun verifySavedLoginsView() = assertSavedLoginsView() + + fun tapSetupLater() = onView(ViewMatchers.withText("Later")).perform(ViewActions.click()) + + class Transition { + fun goBack(interact: SettingsSubMenuLoginsAndPasswordRobot.() -> Unit): SettingsSubMenuLoginsAndPasswordRobot.Transition { + goBackButton().perform(ViewActions.click()) + + SettingsSubMenuLoginsAndPasswordRobot().interact() + return SettingsSubMenuLoginsAndPasswordRobot.Transition() + } + } +} + +private fun goBackButton() = + onView(CoreMatchers.allOf(ViewMatchers.withContentDescription("Navigate up"))) + +private fun assertSavedLoginsView() = onView(ViewMatchers.withText("Secure your logins and passwords")) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsTurnOnSyncRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsTurnOnSyncRobot.kt new file mode 100644 index 000000000..8237fe77f --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsTurnOnSyncRobot.kt @@ -0,0 +1,42 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.ui.robots + +import androidx.test.espresso.Espresso +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.assertion.ViewAssertions +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.uiautomator.UiDevice +import org.hamcrest.CoreMatchers + +/** + * Implementation of Robot Pattern for the settings turn on sync option. + */ +class SettingsTurnOnSyncRobot { + fun verifyUseEmailOption() = assertUseEmailField() + + fun verifyReadyToScanOption() = assertReadyToScan() + + class Transition { + val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) + + fun goBack(interact: SettingsSubMenuLoginsAndPasswordRobot.() -> Unit): SettingsSubMenuLoginsAndPasswordRobot.Transition { + goBackButton().perform(ViewActions.click()) + + SettingsSubMenuLoginsAndPasswordRobot().interact() + return SettingsSubMenuLoginsAndPasswordRobot.Transition() + } + } +} + +private fun goBackButton() = + Espresso.onView(CoreMatchers.allOf(ViewMatchers.withContentDescription("Navigate up"))) + +private fun assertUseEmailField() = Espresso.onView(ViewMatchers.withText("Use email instead")) + .check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) + +private fun assertReadyToScan() = Espresso.onView(ViewMatchers.withText("Ready to scan")) + .check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))