From d25cbebe08afe23510b3d3d2c61b224f1afc2fbe Mon Sep 17 00:00:00 2001 From: isabelrios Date: Tue, 14 Jan 2020 17:47:37 +0100 Subject: [PATCH] For #7563 - Sync integration logins (#7564) * sync-integration-logins-test * improve checks for logins test * fixing ktlint issues * uncomment lines * address reviewer comments * fix ui tests after robot change * fix lint --- .../syncintegration/SyncIntegrationTest.kt | 37 +++++++++++++++++-- .../fenix/syncintegration/test_integration.py | 5 +++ .../fenix/syncintegration/test_logins.js | 30 +++++++++++++++ .../mozilla/fenix/ui/robots/SettingsRobot.kt | 1 + .../SettingsSubMenuLoginsAndPasswordRobot.kt | 23 +++++++++++- ...bMenuLoginsAndPasswordsSavedLoginsRobot.kt | 11 ++++++ .../ui/robots/SettingsTurnOnSyncRobot.kt | 5 +++ 7 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_logins.js diff --git a/app/src/androidTest/java/org/mozilla/fenix/syncintegration/SyncIntegrationTest.kt b/app/src/androidTest/java/org/mozilla/fenix/syncintegration/SyncIntegrationTest.kt index 14c1fac23..39cf6db11 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/syncintegration/SyncIntegrationTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/syncintegration/SyncIntegrationTest.kt @@ -19,6 +19,7 @@ import org.junit.Test import org.mozilla.fenix.helpers.HomeActivityTestRule import org.mozilla.fenix.ui.robots.homeScreen import org.mozilla.fenix.ui.robots.accountSettings +import org.mozilla.fenix.ui.robots.settingsSubMenuLoginsAndPassword import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice @@ -28,7 +29,6 @@ import androidx.test.uiautomator.Until import org.hamcrest.Matchers.allOf import org.mozilla.fenix.R import org.mozilla.fenix.helpers.TestAssetHelper - import org.mozilla.fenix.helpers.ext.waitNotNull @Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") @@ -82,6 +82,37 @@ class SyncIntegrationTest { } } + @Test + fun checkLoginsFromDesktopTest() { + homeScreen { + }.openThreeDotMenu { + }.openSettings { + }.openLoginsAndPasswordSubMenu { + }.openSyncLogins { + // Tap to sign in from Logins menu + tapOnUseEmailToSignIn() + typeEmail() + tapOnContinueButton() + typePassword() + tapOnSignIn() + } + // Automatically goes back to Logins and passwords view + settingsSubMenuLoginsAndPassword { + verifyDefaultView() + // Sync logings option is set to Off, no synced logins yet + verifyDefaultViewBeforeSyncComplete() + }.openSavedLogins { + // Discard the secure your device message + tapSetupLater() + // Check the logins synced + verifySavedLoginsAfterSync() + }.goBack { + // After checking the synced logins + // on Logins and Passwords menu the Sync logins option is set to On + verifyDefaultViewAfterSync() + } + } + /* These tests will be running in the future // once the test above runs successfully and // the environment is stable @@ -187,7 +218,7 @@ class SyncIntegrationTest { } fun settingsAccount() = onView(allOf(withText("Turn on Sync"))).perform(click()) -fun tapInToolBar() = onView(withId(org.mozilla.fenix.R.id.toolbar_wrapper)) -fun awesomeBar() = onView(withId(org.mozilla.fenix.R.id.mozac_browser_toolbar_edit_url_view)) +fun tapInToolBar() = onView(withId(R.id.toolbar_wrapper)) +fun awesomeBar() = onView(withId(R.id.mozac_browser_toolbar_edit_url_view)) fun useEmailInsteadButton() = onView(withId(R.id.signInEmailButton)).perform(click()) fun enterAccountSettings() = onView(withId(R.id.email)).perform(click()) diff --git a/app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_integration.py b/app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_integration.py index 4305b2f3e..294812d13 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_integration.py +++ b/app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_integration.py @@ -14,3 +14,8 @@ def test_sync_bookmark_from_device(tps, gradlewbuild): os.chdir('app/src/androidTest/java/org/mozilla/fenix/syncintegration/') tps.run('test_bookmark.js') gradlewbuild.test('checkBookmarkFromDesktopTest') + +def test_sync_logins_from_device(tps, gradlewbuild): + os.chdir('app/src/androidTest/java/org/mozilla/fenix/syncintegration/') + tps.run('test_logins.js') + gradlewbuild.test('checkLoginsFromDesktopTest') diff --git a/app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_logins.js b/app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_logins.js new file mode 100644 index 000000000..16eb4bcf3 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_logins.js @@ -0,0 +1,30 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* + * The list of phases mapped to their corresponding profiles. The object + * here must be in strict JSON format, as it will get parsed by the Python + * testrunner (no single quotes, extra comma's, etc). + */ +EnableEngines(["passwords"]); + +var phases = { "phase1": "profile1" }; + + +// expected tabs state +var password_list = [{ + hostname: "https://accounts.google.com", + submitURL: "https://accounts.google.com/signin/challenge/sl/password", + realm: null, + username: "iosmztest", + password: "test15mz", + usernameField: "Email", + passwordField: "Passwd", + }]; + +// sync and verify tabs +Phase("phase1", [ + [Sync], + [Passwords.add, password_list], + [Sync] +]); \ No newline at end of file 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 fe123f8a5..7d9530d01 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 @@ -138,6 +138,7 @@ class SettingsRobot { } fun openLoginsAndPasswordSubMenu(interact: SettingsSubMenuLoginsAndPasswordRobot.() -> Unit): SettingsSubMenuLoginsAndPasswordRobot.Transition { + TestHelper.scrollToElementByText("Logins and passwords") fun loginsAndPasswordsButton() = onView(ViewMatchers.withText("Logins and passwords")) loginsAndPasswordsButton().click() 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 index b2eb39385..ee28ffc8b 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordRobot.kt @@ -12,16 +12,32 @@ 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.By import androidx.test.uiautomator.UiDevice +import androidx.test.uiautomator.Until import org.hamcrest.CoreMatchers +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 Privacy Settings > logins and passwords sub menu */ class SettingsSubMenuLoginsAndPasswordRobot { - fun verifyDefaultView() = assertDefaultView() + fun verifyDefaultView() { + mDevice.waitNotNull(Until.findObjects(By.text("Sync logins")), TestAssetHelper.waitingTime) + assertDefaultView() + } + + fun verifyDefaultViewBeforeSyncComplete() { + mDevice.waitNotNull(Until.findObjects(By.text("Off")), TestAssetHelper.waitingTime) + } + + fun verifyDefaultViewAfterSync() { + mDevice.waitNotNull(Until.findObjects(By.text("On")), TestAssetHelper.waitingTime) + } + fun verifyDefaultValueSyncLogins() = asserDefaultValueSyncLogins() class Transition { @@ -52,6 +68,11 @@ class SettingsSubMenuLoginsAndPasswordRobot { } } +fun settingsSubMenuLoginsAndPassword(interact: SettingsSubMenuLoginsAndPasswordRobot.() -> Unit): SettingsSubMenuLoginsAndPasswordRobot.Transition { + SettingsSubMenuLoginsAndPasswordRobot().interact() + return SettingsSubMenuLoginsAndPasswordRobot.Transition() +} + private fun goBackButton() = onView(CoreMatchers.allOf(ViewMatchers.withContentDescription("Navigate up"))) 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 index ffb6afcef..1040b4791 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot.kt @@ -9,7 +9,11 @@ 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.uiautomator.By +import androidx.test.uiautomator.Until import org.hamcrest.CoreMatchers +import org.mozilla.fenix.helpers.TestAssetHelper +import org.mozilla.fenix.helpers.ext.waitNotNull /** * Implementation of Robot Pattern for the Privacy Settings > saved logins sub menu @@ -18,6 +22,11 @@ import org.hamcrest.CoreMatchers class SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot { fun verifySavedLoginsView() = assertSavedLoginsView() + fun verifySavedLoginsAfterSync() { + mDevice.waitNotNull(Until.findObjects(By.text("https://accounts.google.com")), TestAssetHelper.waitingTime) + assertSavedLoginAppears() + } + fun tapSetupLater() = onView(ViewMatchers.withText("Later")).perform(ViewActions.click()) class Transition { @@ -35,3 +44,5 @@ private fun goBackButton() = private fun assertSavedLoginsView() = onView(ViewMatchers.withText("Secure your logins and passwords")) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) + +private fun assertSavedLoginAppears() = onView(ViewMatchers.withText("https://accounts.google.com")) 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 index 8237fe77f..5d8e95033 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsTurnOnSyncRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsTurnOnSyncRobot.kt @@ -11,6 +11,7 @@ import androidx.test.espresso.matcher.ViewMatchers 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 settings turn on sync option. @@ -20,6 +21,8 @@ class SettingsTurnOnSyncRobot { fun verifyReadyToScanOption() = assertReadyToScan() + fun tapOnUseEmailToSignIn() = useEmailButton().click() + class Transition { val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) @@ -40,3 +43,5 @@ private fun assertUseEmailField() = Espresso.onView(ViewMatchers.withText("Use e private fun assertReadyToScan() = Espresso.onView(ViewMatchers.withText("Ready to scan")) .check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) + +private fun useEmailButton() = Espresso.onView(ViewMatchers.withText("Use email instead"))