diff --git a/app/build.gradle b/app/build.gradle index 00cec3506..9bc32abf1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,7 +27,8 @@ android { targetSdkVersion Config.targetSdkVersion versionCode Config.versionCode versionName Config.versionName + Config.generateVersionSuffix() - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + testInstrumentationRunnerArguments clearPackageData: 'true' manifestPlaceholders.isRaptorEnabled = "false" } @@ -50,6 +51,10 @@ android { } } + testOptions { + execution 'ANDROIDX_TEST_ORCHESTRATOR' + } + flavorDimensions "abi", "channel" productFlavors { @@ -333,8 +338,32 @@ dependencies { implementation Deps.adjust implementation Deps.installreferrer // Required by Adjust +// androidTestImplementation Deps.tools_test_runner +// androidTestImplementation Deps.tools_espresso_core + + androidTestImplementation Deps.uiautomator + + androidTestImplementation Deps.espresso_core, { + exclude group: 'com.android.support', module: 'support-annotations' + } + + androidTestImplementation(Deps.espresso_contrib) { + exclude module: 'appcompat-v7' + exclude module: 'support-v4' + exclude module: 'support-annotations' + exclude module: 'recyclerview-v7' + exclude module: 'design' + exclude module: 'espresso-core' + } + + androidTestImplementation Deps.espresso_idling_resources + androidTestImplementation Deps.tools_test_runner - androidTestImplementation Deps.tools_espresso_core + androidTestImplementation Deps.tools_test_rules + androidTestUtil Deps.orchestrator + androidTestImplementation Deps.espresso_core, { + exclude group: 'com.android.support', module: 'support-annotations' + } testImplementation Deps.junit_jupiter_api testImplementation Deps.junit_jupiter_params diff --git a/app/src/androidTest/java/org/mozilla/fenix/ExampleInstrumentedTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ExampleInstrumentedTest.kt deleted file mode 100644 index f3ee17ba6..000000000 --- a/app/src/androidTest/java/org/mozilla/fenix/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,24 +0,0 @@ -package org.mozilla.fenix - -import androidx.test.InstrumentationRegistry -import androidx.test.runner.AndroidJUnit4 - -import org.junit.Test -import org.junit.runner.RunWith -/* ktlint-disable no-wildcard-imports */ -import org.junit.Assert.* - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getTargetContext() - assertEquals("org.mozilla.fenix", appContext.packageName) - } -} diff --git a/app/src/androidTest/java/org/mozilla/fenix/FirefoxTestApplication.kt b/app/src/androidTest/java/org/mozilla/fenix/FirefoxTestApplication.kt new file mode 100644 index 000000000..f5cbdf46b --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/FirefoxTestApplication.kt @@ -0,0 +1,7 @@ +/* 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 + +class FirefoxTestApplication : HomeActivity() diff --git a/app/src/androidTest/java/org/mozilla/fenix/FirefoxTestRunner.kt b/app/src/androidTest/java/org/mozilla/fenix/FirefoxTestRunner.kt new file mode 100644 index 000000000..7d1717720 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/FirefoxTestRunner.kt @@ -0,0 +1,16 @@ +/* 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 + +import android.app.Application +import android.content.Context +import androidx.test.runner.AndroidJUnitRunner + +class FirefoxTestRunner : AndroidJUnitRunner() { + + override fun newApplication(cl: ClassLoader?, className: String?, context: Context?): Application { + return super.newApplication(cl, FirefoxTestApplication::class.java.name, context) + } +} diff --git a/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt b/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt new file mode 100644 index 000000000..bc11ca5dc --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt @@ -0,0 +1,18 @@ +/* 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.helpers + +import androidx.test.rule.ActivityTestRule +import org.mozilla.fenix.HomeActivity + +/** + * A [org.junit.Rule] to handle shared test set up for tests on [HomeActivity]. + * + * @param initialTouchMode See [ActivityTestRule] + * @param launchActivity See [ActivityTestRule] + */ + +class HomeActivityTestRule(initialTouchMode: Boolean = false, launchActivity: Boolean = true) : + ActivityTestRule(HomeActivity::class.java, initialTouchMode, launchActivity) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/HomeScreenTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/HomeScreenTest.kt new file mode 100644 index 000000000..c5f4054be --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/HomeScreenTest.kt @@ -0,0 +1,32 @@ +/* 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 + +import org.junit.Rule +import org.junit.Test +import org.mozilla.fenix.helpers.HomeActivityTestRule +import org.mozilla.fenix.ui.robots.homeScreen + +/** + * Tests for verifying the presence of home screen elements + * + */ + +class HomeScreenTest { + /* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping. + @get:Rule + val activityTestRule = HomeActivityTestRule() + @Test + fun homeScreenItemsTest() { + homeScreen { + verifyHomeScreen() + verifyHomePrivateBrowsingButton() + verifyHomeMenu() + verifyHomeWordmark() + verifyHomeToolbar() + verifyHomeComponent() + } + } +} diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt new file mode 100644 index 000000000..6256104d7 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt @@ -0,0 +1,39 @@ +/* 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.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility +import androidx.test.espresso.matcher.ViewMatchers.Visibility + +class HomeScreenRobot { + fun verifyHomeScreen() = homeScreen() + fun verifyHomePrivateBrowsingButton() = homePrivateBrowsingButton() + fun verifyHomeMenu() = homeMenu() + fun verifyHomeWordmark() = homeWordmark() + fun verifyHomeToolbar() = homeToolbar() + fun verifyHomeComponent() = homeComponent() +} + +fun homeScreen(interact: HomeScreenRobot.() -> Unit) { + HomeScreenRobot().interact() +} + +private fun homeScreen() = onView(ViewMatchers.withResourceName("homeLayout")) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun homePrivateBrowsingButton() = onView(ViewMatchers.withResourceName("privateBrowsingButton")) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun homeMenu() = onView(ViewMatchers.withResourceName("menuButton")) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun homeWordmark() = onView(ViewMatchers.withResourceName("wordmark")) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun homeToolbar() = onView(ViewMatchers.withResourceName("toolbar")) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun homeComponent() = onView(ViewMatchers.withResourceName("home_component")) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index e5c22401b..785683510 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -27,10 +27,7 @@ private object Versions { const val appservices_gradle_plugin = "0.4.2" const val mozilla_android_components = "0.50.0-SNAPSHOT" const val mozilla_appservices = "0.23.0" - - const val test_tools = "1.0.2" - const val espresso_core = "2.2.2" - + const val autodispose = "1.1.0" const val adjust = "4.11.4" const val installreferrer = "1.0" @@ -41,6 +38,13 @@ private object Versions { const val glide = "4.9.0" const val flipper = "0.18.0" const val soLoader = "0.5.1" + + const val espresso_core = "2.2.2" + const val espresso_version = "3.0.2" + const val orchestrator = "1.1.1" + const val tools_test_rules = "1.1.1" + const val tools_test_runner = "1.1.1" + const val uiautomator = "2.1.3" } @Suppress("unused") @@ -119,9 +123,6 @@ object Deps { const val leanplum = "com.leanplum:leanplum-core:${Versions.leanplum}" - const val tools_test_runner = "com.android.support.test:runner:${Versions.test_tools}" - const val tools_espresso_core = "com.android.support.test.espresso:espresso-core:${Versions.espresso_core}" - const val androidx_annotation = "androidx.annotation:annotation:${Versions.androidx_annotation}" const val androidx_fragment = "androidx.fragment:fragment:${Versions.androidx_fragment}" const val androidx_appcompat = "androidx.appcompat:appcompat:${Versions.androidx_appcompat}" @@ -156,4 +157,12 @@ object Deps { const val flipper = "com.facebook.flipper:flipper:${Versions.flipper}" const val soLoader = "com.facebook.soloader:soloader:${Versions.soLoader}" + + const val espresso_contrib = "com.android.support.test.espresso:espresso-contrib:${Versions.espresso_version}" + const val espresso_core = "com.android.support.test.espresso:espresso-core:${Versions.espresso_core}" + const val espresso_idling_resources = "com.android.support.test.espresso:espresso-idling-resource:${Versions.espresso_version}" + const val orchestrator = "androidx.test:orchestrator:${Versions.orchestrator}" + const val tools_test_rules = "com.android.support.test:rules:${Versions.tools_test_rules}" + const val tools_test_runner = "com.android.support.test:runner:${Versions.tools_test_runner}" + const val uiautomator = "com.android.support.test.uiautomator:uiautomator-v18:${Versions.uiautomator}" }