Пример #1
0
def real_adb_device():
    """Fixture for testing a real Android phone.

    Expects our CI phone (an old Samsung Galaxy Ace 2) connected via USB. You
    can specify your own phone via $ANDROID_SERIAL (it must match the output of
    ``adb devices -l``) but you might have to update the tests that use this
    fixture (for example you might need to provide reference screenshots that
    match your phone).
    """
    _adb = AdbDevice(
        adb_server=os.environ.get("ADB_SERVER", "localhost"),
        adb_device=os.environ.get("ANDROID_SERIAL", None),
        adb_binary=os.environ.get("ADB_BINARY", "adb"),
        tcpip=os.environ.get("ADB_TCPIP", False),
        coordinate_system=CoordinateSystem.ADB_NATIVE)
    if not any(
            serial in _adb.devices() for serial in [
                "7278681B045C937CEB770FD31542B16",  # Our CI Samsung Galaxy Ace2
                "model:XT1092",  # Moto X (2nd gen)
                os.environ.get("ANDROID_SERIAL", None),
            ] if serial is not None):
        raise SkipTest(
            "CI Android device not connected. You can set ADB_SERVER, "
            "ANDROID_SERIAL, and ADB_BINARY environment variables.")
    return _adb
Пример #2
0
def adb():
    _adb = AdbDevice(adb_server=os.environ.get("ADB_SERVER", "localhost"),
                     adb_device=os.environ.get("ANDROID_SERIAL", None),
                     adb_binary=os.environ.get("ADB_BINARY", "adb"),
                     tcpip=os.environ.get("ADB_TCPIP", False),
                     coordinate_system=CoordinateSystem.ADB_NATIVE)
    if not any(serial in _adb.devices() for serial in [
            "7278681B045C937CEB770FD31542B16",  # Our CI Samsung Galaxy Ace2
            "model:XT1092",  # Moto X (2nd gen)
            os.environ.get("ANDROID_SERIAL", None),
    ] if serial is not None):
        raise SkipTest(
            "CI Android device not connected. You can set ADB_SERVER, "
            "ANDROID_SERIAL, and ADB_BINARY environment variables.")
    return _adb
Пример #3
0
def adb():
    _adb = AdbDevice(
        adb_server=os.environ.get("ADB_SERVER", "localhost"),
        adb_device=os.environ.get("ANDROID_SERIAL", None),
        adb_binary=os.environ.get("ADB_BINARY", "adb"),
        tcpip=os.environ.get("ADB_TCPIP", False),
        coordinate_system=CoordinateSystem.ADB_NATIVE)
    if not any(
            serial in _adb.devices() for serial in [
                "7278681B045C937CEB770FD31542B16",  # Our CI Samsung Galaxy Ace2
                "model:XT1092",  # Moto X (2nd gen)
                os.environ.get("ANDROID_SERIAL", None),
            ] if serial is not None):
        raise SkipTest(
            "CI Android device not connected. You can set ADB_SERVER, "
            "ANDROID_SERIAL, and ADB_BINARY environment variables.")
    return _adb
Пример #4
0
def test_adb_tcpip(real_adb_device):  # pylint:disable=redefined-outer-name

    # Expects a phone connected via USB. Set it to TCP/IP mode, test it over
    # TCP/IP, then use the TCP/IP connection to set it back to USB mode.

    adb = real_adb_device

    if "7278681B045C937CEB770FD31542B16" in adb.devices():
        raise SkipTest("adb tcpip doesn't work with our old Galaxy Ace 2.")

    ip = _parse_ip_address(
        adb.adb(["shell", "ip", "addr"], capture_output=True))
    adb.adb(["tcpip", "5555"])
    time.sleep(5)
    try:
        adb2 = AdbDevice(
            adb_server="localhost",
            adb_device=ip,
            adb_binary=os.environ.get("ADB_BINARY", "adb"),
            tcpip=True,
            coordinate_system=CoordinateSystem.ADB_NATIVE)
        assert ip == _parse_ip_address(
            adb2.adb(["shell", "ip", "addr"], capture_output=True))
        assert "%s:5555" % ip in adb2.devices()
    finally:
        try:
            adb2.adb(["usb"])
            time.sleep(5)
        except AdbError:
            pass
Пример #5
0
def test_adbdevice_default_constructor():
    adb = AdbDevice()
    assert adb.coordinate_system == CoordinateSystem.ADB_NATIVE
Пример #6
0
def new_adb_device(address):
    from stbt.android import AdbDevice
    tcpip = bool(re.match(r"\d+\.\d+\.\d+\.\d+", address))
    return AdbDevice(adb_device=address, tcpip=tcpip)