From ee544dd3f182efca0182a158dc9fd5205e68d3ab Mon Sep 17 00:00:00 2001 From: isabelrios Date: Tue, 11 Feb 2020 20:19:31 +0100 Subject: [PATCH] sync-integration-history-bookmark-fenix-desktop (#7808) clean code remove unused import fix reviewer comments --- .../syncintegration/SyncIntegrationTest.kt | 97 ++++++++++++------- .../syncintegration/test_bookmark_desktop.js | 25 +++++ .../syncintegration/test_history_desktop.js | 28 ++++++ .../fenix/syncintegration/test_integration.py | 8 +- .../mozilla/fenix/ui/robots/SettingsRobot.kt | 8 ++ 5 files changed, 126 insertions(+), 40 deletions(-) create mode 100644 app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_bookmark_desktop.js create mode 100644 app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_history_desktop.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 39cf6db11..29374db66 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/syncintegration/SyncIntegrationTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/syncintegration/SyncIntegrationTest.kt @@ -9,35 +9,54 @@ import android.widget.EditText import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.click -import androidx.test.espresso.action.ViewActions.replaceText -import androidx.test.espresso.action.ViewActions.pressImeActionButton import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import org.junit.Rule 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 import androidx.test.uiautomator.UiSelector import androidx.test.uiautomator.By import androidx.test.uiautomator.Until +import okhttp3.mockwebserver.MockWebServer import org.hamcrest.Matchers.allOf +import org.junit.After +import org.junit.Before import org.mozilla.fenix.R +import org.mozilla.fenix.helpers.AndroidAssetDispatcher import org.mozilla.fenix.helpers.TestAssetHelper +import org.mozilla.fenix.helpers.ext.toUri import org.mozilla.fenix.helpers.ext.waitNotNull +import org.mozilla.fenix.ui.robots.homeScreen +import org.mozilla.fenix.ui.robots.accountSettings +import org.mozilla.fenix.ui.robots.settingsSubMenuLoginsAndPassword +import org.mozilla.fenix.ui.robots.navigationToolbar +import org.mozilla.fenix.ui.robots.browserScreen @Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") class SyncIntegrationTest { val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) + private lateinit var mockWebServer: MockWebServer @get:Rule val activityTestRule = HomeActivityTestRule() + @Before + fun setUp() { + mockWebServer = MockWebServer().apply { + setDispatcher(AndroidAssetDispatcher()) + start() + } + } + + @After + fun tearDown() { + mockWebServer.shutdown() + } + // History item Desktop -> Fenix @Test fun checkHistoryFromDesktopTest() { @@ -82,6 +101,7 @@ class SyncIntegrationTest { } } + // Login item Desktop -> Fenix @Test fun checkLoginsFromDesktopTest() { homeScreen { @@ -113,30 +133,46 @@ class SyncIntegrationTest { } } - /* These tests will be running in the future - // once the test above runs successfully and - // the environment is stable + // Bookmark item Fenix -> Desktop + @Test + fun checkBookmarkFromDeviceTest() { + val defaultWebPage = "example.com".toUri()!! + navigationToolbar { + }.enterURLAndEnterToBrowser(defaultWebPage) { + }.openThreeDotMenu { + verifyAddBookmarkButton() + clickAddBookmarkButton() + } + browserScreen { + }.openThreeDotMenu { + }.openSettings { + }.openTurnOnSyncMenu { + useEmailInsteadButton() + typeEmail() + tapOnContinueButton() + typePassword() + sleep(TestAssetHelper.waitingTimeShort) + tapOnSignIn() + } + } // History item Fenix -> Desktop @Test - fun checkBookmarkFromDeviceTest() { - tapInToolBar() - typeInToolBar() - seeBookmark() - mDevice.pressBack() - signInFxSync() - } - - // Bookmark item Fenix -> Desktop - @Test fun checkHistoryFromDeviceTest() { - tapInToolBar() - typeInToolBar() - sleep(TestAssetHelper.waitingTime) - mDevice.pressBack() - signInFxSync() + val defaultWebPage = "example.com".toUri()!! + navigationToolbar { + }.enterURLAndEnterToBrowser(defaultWebPage) { + }.openThreeDotMenu { + }.openSettings { + }.openTurnOnSyncMenu { + useEmailInsteadButton() + typeEmail() + tapOnContinueButton() + typePassword() + sleep(TestAssetHelper.waitingTimeShort) + tapOnSignIn() + } } - */ // Useful functions for the tests fun typeEmail() { @@ -170,11 +206,6 @@ class SyncIntegrationTest { mDevice.pressEnter() } - fun typeInToolBar() { - awesomeBar().perform(replaceText("example.com"), - pressImeActionButton()) - } - fun historyAfterSyncIsShown() { val historyEntry = mDevice.findObject(By.text("http://www.example.com/")) historyEntry.isEnabled() @@ -185,12 +216,6 @@ class SyncIntegrationTest { bookmarkEntry.isEnabled() } - fun seeBookmark() { - mDevice.waitNotNull(Until.findObjects(By.text("Bookmark")), TestAssetHelper.waitingTime) - val bookmarkButton = mDevice.findObject(By.text("Bookmark")) - bookmarkButton.click() - } - fun tapReturnToPreviousApp() { mDevice.waitNotNull(Until.findObjects(By.text("Settings")), TestAssetHelper.waitingTime) mDevice.pressBack() @@ -218,7 +243,5 @@ class SyncIntegrationTest { } fun settingsAccount() = onView(allOf(withText("Turn on Sync"))).perform(click()) -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_bookmark_desktop.js b/app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_bookmark_desktop.js new file mode 100644 index 000000000..a6a42aa6d --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_bookmark_desktop.js @@ -0,0 +1,25 @@ +/* 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(["bookmarks"]); + +var phases = { "phase1": "profile1" }; + + +// expected bookmark state +var bookmarksExpected = { +"mobile": [{ + uri: "http://www.example.com/", + title: "Example Domain"}] +}; + +// sync and verify bookmarks +Phase("phase1", [ + [Sync], + [Bookmarks.verify, bookmarksExpected], +]); diff --git a/app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_history_desktop.js b/app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_history_desktop.js new file mode 100644 index 000000000..5dfdd1aa4 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/syncintegration/test_history_desktop.js @@ -0,0 +1,28 @@ +/* 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(["history"]); + +var phases = { "phase1": "profile1" }; + + +// expected history state +var historyExpected = [ + { uri: "http://www.example.com/", + visits: [ + { type: 1 }, + { type: 2 } + ] + } +]; + +// sync and verify history +Phase("phase1", [ + [Sync], + [History.verify, historyExpected] +]); 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 294812d13..185ecfadf 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 @@ -10,12 +10,14 @@ def test_sync_history_from_desktop(tps, gradlewbuild): tps.run('test_history.js') gradlewbuild.test('checkHistoryFromDesktopTest') -def test_sync_bookmark_from_device(tps, gradlewbuild): - os.chdir('app/src/androidTest/java/org/mozilla/fenix/syncintegration/') +def test_sync_bookmark_from_desktop(tps, gradlewbuild): 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') + +def test_sync_bookmark_from_device(tps, gradlewbuild): + gradlewbuild.test('checkBookmarkFromDeviceTest') + tps.run('test_bookmark_desktop.js') 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 efc381261..581c6f3d7 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 @@ -146,6 +146,14 @@ class SettingsRobot { SettingsSubMenuLoginsAndPasswordRobot().interact() return SettingsSubMenuLoginsAndPasswordRobot.Transition() } + + fun openTurnOnSyncMenu(interact: SettingsTurnOnSyncRobot.() -> Unit): SettingsTurnOnSyncRobot.Transition { + fun turnOnSyncButton() = onView(ViewMatchers.withText("Turn on Sync")) + turnOnSyncButton().click() + + SettingsTurnOnSyncRobot().interact() + return SettingsTurnOnSyncRobot.Transition() + } } }