示例#1
0
def _prepare_environment_for_android(disable_android_setup):
    """Additional environment overrides needed to run on an Android device."""
    environment.set_value('OS_OVERRIDE', 'ANDROID')

    # Bail out if we don't have an Android device connected.
    serial = environment.get_value('ANDROID_SERIAL')
    if not serial:
        # TODO(mbarbella): Handle the one-device case gracefully.
        raise errors.ReproduceToolUnrecoverableError(
            'This test case requires an Android device. Please set the '
            'ANDROID_SERIAL environment variable and try again.')

    print('Warning: this tool will make changes to settings on the connected '
          'Android device with serial {serial} that could result in data '
          'loss.'.format(serial=serial))
    willing_to_continue = prompts.get_boolean(
        'Are you sure you want to continue?')
    if not willing_to_continue:
        raise errors.ReproduceToolUnrecoverableError(
            'Bailing out to avoid changing settings on the connected device.')

    # Push the test case and build APK to the device.
    apk_path = environment.get_value('APP_PATH')
    device.update_build(apk_path,
                        should_initialize_device=not disable_android_setup)

    device.push_testcases_to_device()
示例#2
0
def prepare_environment(disable_android_setup):
    """Additional environment overrides needed to run on an Android device."""
    environment.set_value('OS_OVERRIDE', 'ANDROID')

    # Bail out if we can't determine which Android device to use.
    serial = environment.get_value('ANDROID_SERIAL')
    if not serial:
        devices = get_devices()
        if len(devices) == 1:
            serial = devices[0]
            environment.set_value('ANDROID_SERIAL', serial)
        elif not devices:
            raise errors.ReproduceToolUnrecoverableError(
                'No connected Android devices were detected. Run with the -e '
                'argument to use an emulator.')
        else:
            raise errors.ReproduceToolUnrecoverableError(
                'You have multiple Android devices or emulators connected. Please '
                'set the ANDROID_SERIAL environment variable and try again.\n\n'
                'Attached devices: ' + ', '.join(devices))

    print('Warning: this tool will make changes to settings on the connected '
          'Android device with serial {serial} that could result in data '
          'loss.'.format(serial=serial))
    willing_to_continue = prompts.get_boolean(
        'Are you sure you want to continue?')
    if not willing_to_continue:
        raise errors.ReproduceToolUnrecoverableError(
            'Bailing out to avoid changing settings on the connected device.')

    # Push the test case and build APK to the device.
    apk_path = environment.get_value('APP_PATH')
    device.update_build(apk_path,
                        should_initialize_device=not disable_android_setup)

    device.push_testcases_to_device()