Recipes: Android#

To configure ADB see Device Configuration: Android TV.

Launch an app#

Use ADB Activity Manager to launch an app by specifying its package name. Do this in a helper function so that you can call it from any test-case:

def launch_youtube(force=True):
    """Launch the app using ADB Activity Manager.

    :param bool force: If True, force-stop the app before launching it.
    """
    if force:
        flags = ["-S"]
    else:
        flags = []
    stbt.android.adb(["shell", "am", "start"] + flags + ["com.google.android.youtube.tv"])

(To find the package name of your app, use adb shell pm list packages.)

Enter text to an on-screen keyboard#

We need to use shell-style quoting to handle text with spaces.

import shlex
from stbt.android import adb

def enter_text(text):
    """Enter text using ADB."""
    adb(["shell", "input", "text", shlex.quote(text)])

Logcat#

See Capturing logs from the device-under-test.