-
-
Notifications
You must be signed in to change notification settings - Fork 875
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a8d0fc
commit 3d2a2c3
Showing
8 changed files
with
232 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
android-app/app/src/androidTest/kotlin/app/tivi/SmokeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2023, Google LLC, Christopher Banes and the Tivi project contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package app.tivi | ||
|
||
import android.content.Intent | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.uiautomator.By | ||
import androidx.test.uiautomator.UiDevice | ||
import androidx.test.uiautomator.Until | ||
import app.tivi.app.test.AppScenarios | ||
import org.junit.Assert.assertNotNull | ||
import org.junit.Test | ||
|
||
class SmokeTest { | ||
|
||
@Test | ||
fun openApp() { | ||
val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) | ||
|
||
startAppAndWait(device) | ||
|
||
// Run through the main navigation items | ||
AppScenarios.mainNavigationItems(device) | ||
} | ||
} | ||
|
||
private fun startAppAndWait(device: UiDevice) { | ||
device.pressHome() | ||
|
||
// Wait for launcher | ||
val launcherPackage = device.launcherPackageName | ||
assertNotNull(launcherPackage) | ||
device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), 5_000) | ||
|
||
// Launch the app | ||
val context = ApplicationProvider.getApplicationContext<TiviApplication>() | ||
val packageName = context.packageName | ||
val intent = context.packageManager.getLaunchIntentForPackage(packageName)!!.apply { | ||
// Clear out any previous instances | ||
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) | ||
} | ||
context.startActivity(intent) | ||
|
||
// Wait for the app to appear | ||
device.wait(Until.hasObject(By.pkg(packageName).depth(0)), 5_000) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2023, Christopher Banes and the Tivi project contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
plugins { | ||
id("app.tivi.android.library") | ||
id("app.tivi.kotlin.android") | ||
} | ||
|
||
android { | ||
namespace = "app.tivi.app.test" | ||
} | ||
|
||
dependencies { | ||
implementation(projects.core.base) | ||
api(libs.androidx.uiautomator) | ||
} |
120 changes: 120 additions & 0 deletions
120
android-app/common-test/src/main/java/app/tivi/app/test/AppScenarios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// Copyright 2023, Google LLC, Christopher Banes and the Tivi project contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package app.tivi.app.test | ||
|
||
import android.os.SystemClock | ||
import androidx.test.uiautomator.By | ||
import androidx.test.uiautomator.BySelector | ||
import androidx.test.uiautomator.Direction | ||
import androidx.test.uiautomator.SearchCondition | ||
import androidx.test.uiautomator.UiDevice | ||
import androidx.test.uiautomator.UiObject2 | ||
import androidx.test.uiautomator.Until | ||
import kotlin.time.Duration | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
object AppScenarios { | ||
fun mainNavigationItems(device: UiDevice) { | ||
device.waitForIdle() | ||
|
||
// ------------- | ||
// Discover | ||
// ------------- | ||
device.testDiscover() || return | ||
device.navigateFromDiscoverToShowDetails() | ||
|
||
// ------------- | ||
// Show Details | ||
// ------------- | ||
device.testShowDetails() || return | ||
device.navigateFromShowDetailsToSeasons() | ||
|
||
// ------------- | ||
// Seasons | ||
// ------------- | ||
device.testSeasons() || return | ||
device.navigateFromSeasonsToEpisodeDetails() | ||
|
||
// ------------- | ||
// Episode details | ||
// ------------- | ||
device.testEpisodeDetails() || return | ||
} | ||
} | ||
|
||
private fun UiDevice.testDiscover(): Boolean { | ||
// Might need to wait a while for the app to load | ||
waitForObject(By.res("discover_carousel"), 30.seconds).run { | ||
// Scroll one of the Discover Carousels | ||
scroll(Direction.RIGHT, 1f) | ||
scroll(Direction.LEFT, 1f) | ||
} | ||
|
||
return wait(Until.hasObject(By.res("discover_carousel_item")), 5.seconds) | ||
} | ||
|
||
private fun UiDevice.navigateFromDiscoverToShowDetails() { | ||
// Open a show from one of the carousels | ||
waitForObject(By.res("discover_carousel_item")).click() | ||
waitForIdle() | ||
} | ||
|
||
private fun UiDevice.testShowDetails(): Boolean { | ||
// Follow the show | ||
waitForObject(By.res("show_details_follow_button")).click() | ||
|
||
// Keep scrolling to the end of the LazyColumn, waiting for a season item | ||
repeat(20) { | ||
if (hasObject(By.res("show_details_season_item"))) { | ||
return true | ||
} | ||
|
||
SystemClock.sleep(1.seconds.inWholeMilliseconds) | ||
|
||
// Scroll to the end to show the seasons | ||
waitForObject(By.res("show_details_lazycolumn")) | ||
.scroll(Direction.DOWN, 1f) | ||
} | ||
|
||
return false | ||
} | ||
|
||
private fun UiDevice.navigateFromShowDetailsToSeasons() { | ||
waitForObject(By.res("show_details_season_item")).click() | ||
waitForIdle() | ||
} | ||
|
||
private fun UiDevice.testSeasons(): Boolean { | ||
// Not much to test here at the moment | ||
return wait(Until.hasObject(By.res("show_seasons_episode_item")), 5.seconds) | ||
} | ||
|
||
private fun UiDevice.navigateFromSeasonsToEpisodeDetails() { | ||
waitForObject(By.res("show_seasons_episode_item")).click() | ||
waitForIdle() | ||
} | ||
|
||
private fun UiDevice.testEpisodeDetails(): Boolean { | ||
waitForObject(By.res("episode_details")).run { | ||
// Need to 'inset' the gesture so that we don't swipe | ||
// the notification tray down | ||
setGestureMargin(displayWidth / 10) | ||
|
||
// Swipe the bottom sheet 'up', then 'down' | ||
scroll(Direction.DOWN, 0.8f) | ||
scroll(Direction.UP, 0.8f) | ||
} | ||
return true | ||
} | ||
|
||
fun UiDevice.waitForObject(selector: BySelector, timeout: Duration = 5.seconds): UiObject2 { | ||
if (wait(Until.hasObject(selector), timeout)) { | ||
return findObject(selector) | ||
} | ||
error("Object with selector [$selector] not found") | ||
} | ||
|
||
fun <R> UiDevice.wait(condition: SearchCondition<R>, timeout: Duration): R { | ||
return wait(condition, timeout.inWholeMilliseconds) | ||
} |
Oops, something went wrong.