1
0
Fork 0

UI tests for the home screen

master
Kevin Brosnan 2019-04-10 09:59:38 -07:00 committed by Jeff Boek
parent 42056fed7c
commit 493bab42a4
8 changed files with 159 additions and 33 deletions

View File

@ -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

View File

@ -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)
}
}

View File

@ -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()

View File

@ -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)
}
}

View File

@ -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>(HomeActivity::class.java, initialTouchMode, launchActivity)

View File

@ -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()
}
}
}

View File

@ -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)))

View File

@ -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}"
}