Beispiel #1
0
def _load_test_set(test_manifest, test_set_name):
    if test_manifest.contains_set(test_set_name):
        Printer.system_message(
            TAG, "Test set " + Color.GREEN + test_set_name + Color.BLUE +
            " was found in TestManifest.")

        test_set = test_manifest.get_set(test_set_name)
        Printer.system_message(TAG,
                               "Test set contains following package names: ")
        for package_name in test_set.set_package_names:
            Printer.system_message(
                TAG, "  * " + Color.GREEN + package_name + Color.BLUE)

        found_all_packages = True
        errors = ""
        for package_name in test_set.set_package_names:
            if not test_manifest.contains_package(package_name):
                found_all_packages = False
                errors += "\n              - Test package '" + package_name + "' was not found in TestManifest!"

        if found_all_packages:
            Printer.system_message(
                TAG, "All test packages from set " + Color.GREEN +
                test_set_name + Color.BLUE + " were found in TestManifest.")
        else:
            raise LauncherFlowInterruptedException(TAG, errors)
    else:
        message = "Test set '{}' not found in TestManifest. Launcher will quit."
        message = message.format(test_set_name)
        raise LauncherFlowInterruptedException(TAG, message)

    return test_set
Beispiel #2
0
    def set_instrumentation_runner_according_to(self, apk):
        Printer.system_message(
            self.TAG,
            "Scanning test .*apk file for Instrumentation Runner data.")

        resources = self.aapt_controller.list_resources(apk.test_apk_path)
        target_package = ""
        instrumentation_runner_name = ""

        inside_instrumentation_section = False
        inside_manifest_section = False
        for line in resources.splitlines():
            if "E: instrumentation" in line:
                inside_instrumentation_section = True
                continue

            if "E: manifest" in line:
                inside_manifest_section = True
                continue

            if inside_instrumentation_section and "E: " in line:
                inside_instrumentation_section = False

            if inside_manifest_section and "E: " in line:
                inside_manifest_section = False

            if inside_instrumentation_section:
                if "A: android:name" in line:
                    regex_result = re.findall("=\"(.+?)\"", line)
                    if regex_result:
                        instrumentation_runner_name = str(regex_result[0])

            if inside_manifest_section:
                if "A: package" in line:
                    regex_result = re.findall("=\"(.+?)\"", line)
                    if regex_result:
                        target_package = str(regex_result[0])

        if target_package == "":
            message = "Unable to find package of tested application in test .*apk file. Tests won't start without it."
            raise LauncherFlowInterruptedException(self.TAG, message)

        if instrumentation_runner_name == "":
            message = (
                "Unable to find Instrumentation Runner name of tested application in test .*apk file."
                " Tests won't start without it.")
            raise LauncherFlowInterruptedException(self.TAG, message)

        GlobalConfig.INSTRUMENTATION_RUNNER = target_package + "/" + instrumentation_runner_name
        Printer.system_message(
            self.TAG, "Instrumentation Runner found: " + Color.GREEN +
            GlobalConfig.INSTRUMENTATION_RUNNER + Color.BLUE + ".")
    def _check_if_build_is_possible(self, cmd):
        if cmd == "":
            message = "Gradle assemble task (for building .*apk) was not specified in TestManifest. Launcher will quit."
            raise LauncherFlowInterruptedException(self.TAG, message)

        if not self.project_root_found:
            message = "Unable to build new .*apk. Project root not found. Launcher will quit."
            raise LauncherFlowInterruptedException(self.TAG, message)

        if not self.gradlew_found:
            message = "Unable to build new .*apk. File 'gradlew' not found in dir '{}'. Launcher will quit."
            message = message.format(GlobalConfig.PROJECT_ROOT_DIR)
            raise LauncherFlowInterruptedException(self.TAG, message)
Beispiel #4
0
    def _check_avd_schema(self):
        if self.avd_schema.avd_name == "":
            message = "One AVD schema doesn't have name set."
            raise LauncherFlowInterruptedException(self.TAG, message)

        if self.avd_schema.create_avd_package == "":
            message = "Parameter 'create_avd_package' in AVD schema {} cannot be empty."
            message = message.format(self.avd_schema.avd_name)
            raise LauncherFlowInterruptedException(self.TAG, message)

        if self.avd_schema.launch_avd_launch_binary_name == "":
            message = "Parameter 'launch_avd_launch_binary_name' in AVD schema {} cannot be empty."
            message = message.format(self.avd_schema.avd_name)
            raise LauncherFlowInterruptedException(self.TAG, message)
    def _display_emulator_binaries(self):
        emulator_binaries = dict()

        emulator_dir = clean_path(
            add_ending_slash(str(GlobalConfig.SDK_DIR)) + "emulator/")
        try:
            for the_file in list_files_in_dir(emulator_dir):
                file_path = os.path.join(emulator_dir, the_file)
                if os.path.isfile(file_path) and "emulator" in file_path:
                    binary_name = re.findall("emulator\/(emulator*.+)",
                                             file_path)

                    if binary_name:
                        emulator_binaries[str(binary_name[0])] = file_path
        finally:
            if len(emulator_binaries) == 0:
                message = "Unable to find emulator binary files in direction '{}' of Android SDK."
                message = message.format(str(emulator_dir))
                raise LauncherFlowInterruptedException(self.TAG, message)

            else:
                Printer.system_message(
                    self.TAG,
                    "Emulator related binary files found in Android SDK:")
                for path in emulator_binaries.values():
                    Printer.system_message(
                        self.TAG, "  * " + Color.GREEN + path + Color.BLUE)

        return emulator_binaries
    def _find_latest_build_tools(self):
        build_tools = list_files_in_dir(
            clean_path(add_ending_slash(GlobalConfig.SDK_DIR) + "build-tools"))
        build_tools = [
            build_tool for build_tool in build_tools
            if build_tool[0].isdigit()
        ]
        build_tools_folder_with_highest_ver = None
        Printer.system_message(
            self.TAG,
            "Available Android SDK Build-Tools versions: " + str(build_tools))
        for build_tools_folder in build_tools:
            if build_tools_folder_with_highest_ver is None:
                build_tools_folder_with_highest_ver = build_tools_folder
                continue

            ver = int(re.sub("[^0-9]", "", build_tools_folder))
            highest_ver = int(
                re.sub("[^0-9]", "", build_tools_folder_with_highest_ver))

            if ver > highest_ver:
                build_tools_folder_with_highest_ver = build_tools_folder
        if build_tools_folder_with_highest_ver is None:
            message = "Android SDK Build-Tools not found. Launcher will quit."
            raise LauncherFlowInterruptedException(self.TAG, message)

        else:
            Printer.system_message(
                self.TAG,
                "Android SDK Build-Tools with latest version were selected: " +
                Color.GREEN + str(build_tools_folder_with_highest_ver) +
                Color.BLUE + ".")
        return build_tools_folder_with_highest_ver
Beispiel #7
0
    def _wait_for_adb_statuses_change_to(self, status, monitored_devices):
        Printer.system_message(
            self.TAG,
            "Waiting until (" + " ".join("'" + device.adb_name + "'"
                                         for device in monitored_devices) +
            ") devices status will change to '" + status + "'.")

        timeout = GlobalConfig.AVD_ADB_BOOT_TIMEOUT
        start_time = last_scan_ended = time.time() * 1000
        while True:
            current_time = time.time() * 1000

            if current_time - last_scan_ended >= GlobalConfig.ADB_SCAN_INTERVAL or start_time == last_scan_ended:
                Printer.system_message(self.TAG, "Scanning...")

                self.device_store.update_model_statuses()
                Printer.system_message(self.TAG, "  * Current wait status:")
                for device in monitored_devices:
                    Printer.system_message(
                        self.TAG, "    " + device.adb_name + " " +
                        Color.GREEN + "('" + device.status + "')")

                if all(device.status == status
                       for device in monitored_devices):
                    break

                last_scan_ended = time.time() * 1000

            if current_time - start_time >= timeout:
                message = "Devices took longer than {} seconds to launch (ADB launch). Timeout quit."
                message = message.format(str(timeout))
                raise LauncherFlowInterruptedException(self.TAG, message)

        Printer.system_message(self.TAG, "ADB wait finished with success!")
Beispiel #8
0
    def install_apk_on_devices(self, apk):
        if not self.device_store.get_devices():
            message = "No devices were found in test session. Launcher will quit."
            message = message.format(str(GlobalConfig.AVD_SYSTEM_BOOT_TIMEOUT))
            raise LauncherFlowInterruptedException(self.TAG, message)

        self._install_apk(apk)
Beispiel #9
0
    def prepare_device_directories(self):
        for device in self.device_store.get_devices():
            Printer.system_message(
                self.TAG,
                "Checking if folder for test recordings exists on device " +
                Color.GREEN + device.adb_name + Color.BLUE + ":")
            result = self.adb_shell_controller.check_for_directory(
                device.adb_name, GlobalConfig.DEVICE_VIDEO_STORAGE_DIR)
            if "No such file or directory" in result:
                Printer.system_message(
                    self.TAG, "Creating directory " + Color.GREEN +
                    GlobalConfig.DEVICE_VIDEO_STORAGE_DIR + Color.BLUE +
                    " directory on device " + Color.GREEN + device.adb_name +
                    Color.BLUE + ".")
                self.adb_shell_controller.create_dir(
                    device.adb_name, GlobalConfig.DEVICE_VIDEO_STORAGE_DIR)
            else:
                Printer.system_message(
                    self.TAG, "Directory " + Color.GREEN +
                    GlobalConfig.DEVICE_VIDEO_STORAGE_DIR + Color.BLUE +
                    " already exists." + " Re-creating.")
                self.adb_shell_controller.remove_files_in_dir(
                    device.adb_name, GlobalConfig.DEVICE_VIDEO_STORAGE_DIR)
                self.adb_shell_controller.create_dir(
                    device.adb_name, GlobalConfig.DEVICE_VIDEO_STORAGE_DIR)

            next_result = self.adb_shell_controller.check_for_directory(
                device.adb_name, GlobalConfig.DEVICE_VIDEO_STORAGE_DIR)
            if "No such file or directory" in next_result:
                message = (
                    "Directory '" + GlobalConfig.DEVICE_VIDEO_STORAGE_DIR +
                    "' was not created. This will " +
                    "lead to test session to malfunction and crash. Quitting..."
                )
                raise LauncherFlowInterruptedException(self.TAG, message)
 def _assert_bin_directory_exists(self):
     if os.path.isfile(self.adb_bin):
         Printer.system_message(
             self.TAG, "ADB binary file found at " + Color.GREEN +
             self.adb_bin + Color.BLUE + ".")
     else:
         message = "Unable to find ADB binary at '{}'."
         message = message.format(self.adb_bin)
         raise LauncherFlowInterruptedException(self.TAG, message)
def python_check():
    if sys.version_info >= MIN_PYTHON_VER:
        Printer.system_message(
            "", "Minimum Python version requirement met! Your version: " +
            Color.GREEN + str(sys.version_info) + Color.BLUE + ".")

    else:
        message = ("Invalid Python version. Please use at least Python " +
                   str(MIN_PYTHON_VER[0]) + "." + str(MIN_PYTHON_VER[1]) + ".")
        raise LauncherFlowInterruptedException("", message)
Beispiel #12
0
def _load_path_set(path_manifest, path_set_name):
    if path_manifest.contains_set(path_set_name):
        Printer.system_message(
            TAG, "Path set " + Color.GREEN + path_set_name + Color.BLUE +
            " was found in PathManifest.")
        return path_manifest.get_set(path_set_name)
    else:
        message = "Invalid path set with name '{}' does not exist in PathManifest!"
        message = message.format(path_set_name)
        raise LauncherFlowInterruptedException(TAG, message)
def _load_launch_plan(launch_manifest, launch_plan_name):
    if launch_manifest.contains_plan(launch_plan_name):
        Printer.system_message(
            TAG, "Launch plan " + Color.GREEN + launch_plan_name + Color.BLUE +
            " was found in LaunchManifest.")
        return launch_manifest.get_plan(launch_plan_name)
    else:
        message = "Invalid launch plan with name '{}' does not exist in LaunchManifest!"
        message = message.format(launch_plan_name)
        raise LauncherFlowInterruptedException(TAG, message)
Beispiel #14
0
def _load_path_set_name():
    path_set_name = ArgLoader.get_arg_loaded_by(ArgLoader.PATH_SET_PREFIX)
    if path_set_name is None:
        message = "No path set was selected. Launcher will quit."
        raise LauncherFlowInterruptedException(TAG, message)
    else:
        Printer.system_message(
            TAG, "Selected path set: " + Color.GREEN + path_set_name +
            Color.BLUE + ".")
    return path_set_name
Beispiel #15
0
def _load_test_set_name():
    test_set_name = ArgLoader.get_arg_loaded_by(ArgLoader.TEST_SET_PREFIX)
    if test_set_name is None:
        message = "No test set inserted. Launcher will quit."
        raise LauncherFlowInterruptedException(TAG, message)
    else:
        Printer.system_message(
            TAG, "Selected test set: " + Color.GREEN + test_set_name +
            Color.BLUE + ".")
    return test_set_name
def create_dir(directory):
    dir_path = clean_path(directory)

    try:
        os.makedirs(directory)
    except Exception as e:
        message = "Unable to create directory '{}'. Error message: {}"
        message = message.format(dir_path, str(e))
        raise LauncherFlowInterruptedException(TAG, message)

    return True
def _load_launch_plan_name():
    launch_plan_name = ArgLoader.get_arg_loaded_by(
        ArgLoader.LAUNCH_PLAN_PREFIX)

    if launch_plan_name is None:
        message = "No launch plan selected. Launcher will quit."
        raise LauncherFlowInterruptedException(TAG, message)
    else:
        Printer.system_message(
            TAG, "Selected launch plan: " + Color.GREEN + launch_plan_name +
            Color.BLUE + ".")
    return launch_plan_name
def create_file(directory, file_name, extension):
    file_path = clean_path(directory + str(file_name) + "." + extension)

    try:
        if not dir_exists(directory):
            os.makedirs(directory)
        open(file_path, "w", encoding="utf-8")
    except Exception as e:
        message = "Unable to create file '{}.{}'. Error message: {}"
        message = message.format(file_path, extension, str(e))
        raise LauncherFlowInterruptedException(TAG, message)

    return True
def load_json(json_dir):
    json_dir = clean_path(json_dir)
    with open(json_dir, "r", encoding="utf-8") as json_file:
        json_data = json_file.read()

    try:
        json_dict = json.loads(json_data)
    except Exception as e:
        message = "Unable to parse JSON file '{}/{}'. Error message: {}"
        message = message.format(os.getcwd(), json_dir, str(e))
        raise LauncherFlowInterruptedException(TAG, message)

    return json_dict
def _load_avd_schema(avd_manifest, avd_set, avd_set_name):
    avd_schema_dict = avd_manifest.avd_schema_dict

    for avd in avd_set.avd_list:
        if avd_manifest.contains_schema(avd.avd_name):
            Printer.system_message(
                TAG, "AVD schema " + Color.GREEN + avd.avd_name + Color.BLUE +
                " was found in AvdManifest.")
        else:
            message = "Set '{}' requests usage of AVD schema with name '{}' which doesn't exists in AVD schema list."
            message = message.format(avd_set_name, avd.avd_name)
            raise LauncherFlowInterruptedException(TAG, message)

    return avd_schema_dict
Beispiel #21
0
def _load_manifest():
    test_manifest_dir = make_path_absolute(
        ArgLoader.get_manifest_dir(ArgLoader.TEST_MANIFEST_DIR_KEY))

    if test_manifest_dir is None:
        message = (
            "TestManifest file directory was not found. Check if config_files_dir.json exists in root "
            "of project. Otherwise check if it's linking to existing file.")
        raise LauncherFlowInterruptedException(TAG, message)
    else:
        test_manifest = TestManifest(test_manifest_dir)
        Printer.system_message(
            TAG, "Created TestManifest from file: " + Color.GREEN +
            test_manifest_dir + Color.BLUE + ".")
    return test_manifest
Beispiel #22
0
 def _get_apk_package(self):
     dump = ShellHelper.execute_shell(self.dump_badging_cmd, False, False)
     regex_result = re.findall("package: name='(.+?)'", dump)
     if regex_result:
         package = str(regex_result[0])
         if ".test" in package:
             GlobalConfig.APP_TEST_PACKAGE = package
         else:
             GlobalConfig.APP_PACKAGE = package
         Printer.system_message(self.TAG, "Package that is about to be installed: " + Color.GREEN + package
                                + Color.BLUE + ".")
     else:
         message = "Unable to find package of .*apk file: " + self.apk_name
         raise LauncherFlowInterruptedException(self.TAG, message)
     return package
def clear_dir(directory):
    if list_files_in_dir(directory):
        for the_file in list_files_in_dir(directory):
            file_path = os.path.join(directory, the_file)
            try:
                if file_exists(file_path):
                    os.unlink(file_path)
                elif file_exists(file_path):
                    shutil.rmtree(file_path)
            except Exception as e:
                message = "Unable to delete files in directory '{}'. Error message: {}"
                message = message.format(directory, str(e))
                raise LauncherFlowInterruptedException(TAG, message)

    return True
Beispiel #24
0
    def get_existing_apk(self, test_set):
        apk_candidate = self.apk_store.usable_apk_candidate
        if apk_candidate is None:
            apk_candidate = self.apk_store.provide_apk(test_set)
            if apk_candidate is None:
                message = "No .apk* candidates for test session were found. Check your config. Launcher will quit."
                raise LauncherFlowInterruptedException(self.TAG, message)

        session_logger.log_app_apk(apk_candidate.apk_name)
        session_logger.log_test_apk(apk_candidate.test_apk_name)
        session_logger.log_apk_version_code(apk_candidate.apk_version)

        if session_logger.session_log.apk_summary.apk_build_time is None:
            session_logger.session_log.apk_summary.apk_build_time = 0

        if session_logger.session_log.apk_summary.test_apk_build_time is None:
            session_logger.session_log.apk_summary.test_apk_build_time = 0

        return apk_candidate
def _load_avd_set(avd_manifest, avd_set_name):
    if avd_manifest.contains_set(avd_set_name):
        Printer.system_message(
            TAG, "AVD set " + Color.GREEN + avd_set_name + Color.BLUE +
            " was found in AvdManifest.")

        avd_set = avd_manifest.get_set(avd_set_name)
        Printer.system_message(TAG, "Requested AVD in set:")
        for requested_avd_schema in avd_set.avd_list:
            Printer.system_message(
                TAG, "  * " + Color.GREEN + requested_avd_schema.avd_name +
                Color.BLUE + " - instances num: " + Color.GREEN +
                str(requested_avd_schema.instances) + Color.BLUE + ".")
    else:
        message = "Invalid AVD set. Set '{}' does not exist in AvdManifest!"
        message = message.format(avd_set_name)
        raise LauncherFlowInterruptedException(TAG, message)

    return avd_manifest.get_set(avd_set_name)
def _check_port_rules(avd_set):
    avd_instances = 0
    avd_rules = avd_set.avd_port_rules

    for avd in avd_set.avd_list:
        avd_instances += avd.instances

    if len(avd_rules.ports_to_use) != len(set(avd_rules.ports_to_use)):
        message = "'Ports to use' list contains duplicates."
        raise LauncherFlowInterruptedException(TAG, message)

    if len(avd_rules.ports_to_ignore) != len(set(avd_rules.ports_to_ignore)):
        message = "'Ports to ignore' list contains duplicates."
        raise LauncherFlowInterruptedException(TAG, message)

    for port_to_be_used in avd_rules.ports_to_use:
        if port_to_be_used % 2 == 1:
            message = "Port numbers has to be even."
            raise LauncherFlowInterruptedException(TAG, message)

    for port_to_be_used in avd_rules.ports_to_use:
        if port_to_be_used < avd_rules.search_range_min or port_to_be_used > avd_rules.search_range_max:
            message = "Requested to use port {} is out of range <{}, {}>."
            message = message.format(str(port_to_be_used),
                                     str(avd_rules.search_range_min),
                                     str(avd_rules.search_range_max))
            raise LauncherFlowInterruptedException(TAG, message)

    for port_to_be_ignored in avd_rules.ports_to_ignore:
        for port_to_be_used in avd_rules.ports_to_use:
            if port_to_be_used == port_to_be_ignored:
                message = "Port {} is set to be used and ignored at the same time."
                message = message.format(str(port_to_be_used))
                raise LauncherFlowInterruptedException(TAG, message)

    if not avd_rules.assign_missing_ports:
        requested_ports_to_use_num = len(avd_rules.ports_to_use)
        if requested_ports_to_use_num != avd_instances:
            message = (
                "There are {} AVD instances about to be created according to set, but there were only {} ports "
                "requested to use. Set 'assign_missing_ports' to True or add more ports to list."
            )
            message = message.format(str(avd_instances),
                                     str(requested_ports_to_use_num))
            raise LauncherFlowInterruptedException(TAG, message)
    def apply_config_to_avd(self, avd_schema):
        config_ini_to_apply_filepath = clean_path(
            avd_schema.create_avd_hardware_config_filepath)

        real_config_ini_file_path = clean_path(
            add_ending_slash(GlobalConfig.AVD_DIR) + add_ending_slash("avd") +
            add_ending_slash(avd_schema.avd_name + ".avd") + "config.ini")

        real_config_ini_file = None
        config_ini_to_apply_file = None
        try:
            if os.path.isfile(config_ini_to_apply_filepath):
                config_ini_to_apply_file = open(config_ini_to_apply_filepath,
                                                "r")
                real_config_ini_file = open(real_config_ini_file_path, "w")
                real_config_ini_file.seek(0)
                real_config_ini_file.truncate()

                for config_line in config_ini_to_apply_file.readlines():
                    temp_lane = config_line
                    if "AvdId=" in config_line:
                        temp_lane = ("AvdId=" + str(avd_schema.avd_name) +
                                     "\n")
                    if "avd.ini.displayname=" in config_line:
                        temp_lane = ("avd.ini.displayname=" +
                                     str(avd_schema.avd_name) + "\n")
                    real_config_ini_file.write(temp_lane)
            else:
                message = "Filepath '" + config_ini_to_apply_filepath + "' not found!"
                raise LauncherFlowInterruptedException(self.TAG, message)
        finally:
            if real_config_ini_file is not None:
                real_config_ini_file.close()
            if config_ini_to_apply_file is not None:
                config_ini_to_apply_file.close()

        return "Config.ini successfully applied"
Beispiel #28
0
def _load_test_list(test_manifest):
    if test_manifest.test_package_list:
        return test_manifest.test_package_list
    else:
        message = "There are no tests specified in TestManifest! Launcher will quit."
        raise LauncherFlowInterruptedException(TAG, message)
def _load_launch_plan_to_global_settings(launch_plan):
    avd_set = ArgLoader.get_arg_loaded_by(ArgLoader.AVD_SET_PREFIX)
    is_avd_session_requested = avd_set is not None and avd_set != ArgLoader.AVD_SET_DEFAULT

    Printer.system_message(TAG, "General:")
    general_settings = launch_plan.general

    if is_avd_session_requested:
        GlobalConfig.SHOULD_USE_ONLY_DEVICES_SPAWNED_IN_SESSION = True
    else:
        GlobalConfig.SHOULD_USE_ONLY_DEVICES_SPAWNED_IN_SESSION = False

    GlobalConfig.ADB_CALL_BUFFER_SIZE = general_settings.adb_call_buffer_size
    if GlobalConfig.ADB_CALL_BUFFER_SIZE > 0:
        Printer.system_message(
            TAG, "  * ADB call buffer size set to: " + Color.GREEN +
            str(GlobalConfig.ADB_CALL_BUFFER_SIZE) + " slot(s)" + Color.BLUE +
            ".")
    else:
        message = "ADB_CALL_BUFFER_SIZE cannot be smaller than 1. Launcher will quit."
        raise LauncherFlowInterruptedException(TAG, message)

    GlobalConfig.ADB_CALL_BUFFER_DELAY_BETWEEN_CMD = general_settings.adb_call_buffer_delay_between_cmd
    if GlobalConfig.ADB_CALL_BUFFER_DELAY_BETWEEN_CMD >= 0:
        if GlobalConfig.ADB_CALL_BUFFER_DELAY_BETWEEN_CMD == 0:
            Printer.system_message(
                TAG,
                "  * ADB call buffer is disabled. ADB_CALL_BUFFER_DELAY_BETWEEN_CMD"
                " param set to: " + +Color.GREEN + "0 second(s)" +
                +Color.BLUE + ".")
        else:
            Printer.system_message(
                TAG,
                "  * ADB call buffer will clear slots after " + Color.GREEN +
                str(GlobalConfig.ADB_CALL_BUFFER_DELAY_BETWEEN_CMD / 1000) +
                " second(s)" + Color.BLUE + " from ADB call.")
    else:
        message = "ADB_CALL_BUFFER_DELAY_BETWEEN_CMD cannot be negative! Launcher will quit."
        raise LauncherFlowInterruptedException(TAG, message)

    if is_avd_session_requested:
        Printer.system_message(TAG, "Device preparation phase settings:")
        device_prep_settings = launch_plan.device_preparation_phase

        GlobalConfig.SHOULD_RECREATE_EXISTING_AVD = device_prep_settings.avd_should_recreate_existing
        if GlobalConfig.SHOULD_RECREATE_EXISTING_AVD:
            Printer.system_message(
                TAG, "  * If requested AVD already exists - it will be" +
                Color.GREEN + " recreated from scratch" + Color.BLUE + ".")
        else:
            Printer.system_message(
                TAG, "  * If requested AVD already exists - it will be" +
                Color.GREEN + " reused" + Color.BLUE + ".")

    Printer.system_message(TAG, "Device launching phase settings:")
    device_launch_settings = launch_plan.device_launching_phase

    GlobalConfig.IGNORED_DEVICE_LIST = device_launch_settings.device_android_id_to_ignore
    Printer.system_message(
        TAG, "  * Devices with following Android-IDs will be ignored: " +
        Color.GREEN + str(GlobalConfig.IGNORED_DEVICE_LIST) + Color.BLUE + ".")

    if is_avd_session_requested:
        GlobalConfig.SHOULD_LAUNCH_AVD_SEQUENTIALLY = device_launch_settings.avd_launch_sequentially
        if GlobalConfig.SHOULD_LAUNCH_AVD_SEQUENTIALLY:
            Printer.system_message(
                TAG, "  * AVD will be launched " + Color.GREEN + "one by one" +
                Color.BLUE +
                ". Wait for start will be performed for each AVD separately and it will take more"
                " time.")
        else:
            Printer.system_message(
                TAG, "  * AVD will be launched " + Color.GREEN +
                "all at once" + Color.BLUE + ".")
            Printer.error(
                TAG,
                "Warning: when launching AVD simultaneously ADB is unaware of the amount of memory"
                " that specific AVD will use. If there is not enough memory in the system and you launch"
                " too many AVD at the same time your PC might turn off due to lack of RAM memory."
            )

        GlobalConfig.ADB_SCAN_INTERVAL = device_launch_settings.avd_status_scan_interval_millis
        if GlobalConfig.ADB_SCAN_INTERVAL is "":
            message = "  * ADB_SCAN_INTERVAL not specified in LaunchManifest. Launcher will quit."
            raise LauncherFlowInterruptedException(TAG, message)
        else:
            Printer.system_message(
                TAG, "  * ADB will be scanned with interval of " +
                Color.GREEN + str(GlobalConfig.ADB_SCAN_INTERVAL / 1000) +
                " second(s)" + Color.BLUE + ".")

        GlobalConfig.AVD_ADB_BOOT_TIMEOUT = device_launch_settings.avd_wait_for_adb_boot_timeout_millis
        if GlobalConfig.AVD_ADB_BOOT_TIMEOUT is "":
            message = "  * AVD_ADB_BOOT_TIMEOUT not specified in LaunchManifest. Launcher will quit."
            raise LauncherFlowInterruptedException(TAG, message)
        else:
            Printer.system_message(
                TAG, "  * AVD - ADB boot timeout set to " + Color.GREEN +
                str(GlobalConfig.AVD_ADB_BOOT_TIMEOUT / 1000) + " second(s)" +
                Color.BLUE + ".")

        GlobalConfig.AVD_SYSTEM_BOOT_TIMEOUT = device_launch_settings.avd_wait_for_system_boot_timeout_millis
        if GlobalConfig.AVD_SYSTEM_BOOT_TIMEOUT is "":
            message = "  * AVD_SYSTEM_BOOT_TIMEOUT not specified in LaunchManifest. Launcher will quit."
            raise LauncherFlowInterruptedException(TAG, message)
        else:
            Printer.system_message(
                TAG,
                "  * AVD - ADB system boot timeout set to " + Color.GREEN +
                str(GlobalConfig.AVD_SYSTEM_BOOT_TIMEOUT / 1000) +
                " second(s)" + Color.BLUE + ".")

    GlobalConfig.SHOULD_RESTART_ADB = device_launch_settings.device_before_launching_restart_adb
    if GlobalConfig.SHOULD_RESTART_ADB:
        Printer.system_message(
            TAG, "  * " + Color.GREEN + "ADB will be restarted" + Color.BLUE +
            " before launching tests.")

    Printer.system_message(TAG, "Apk preparation phase settings:")
    apk_preparation_settings = launch_plan.apk_preparation_phase

    GlobalConfig.SHOULD_BUILD_NEW_APK = apk_preparation_settings.build_new_apk
    if GlobalConfig.SHOULD_BUILD_NEW_APK:
        Printer.system_message(
            TAG, "  * Launcher will " + Color.GREEN + "build .*apk" +
            Color.BLUE + " for tests with commands specified in test set.")
    else:
        Printer.system_message(
            TAG, "  * Launcher will " + Color.GREEN +
            "look for existing .*apk" + Color.BLUE +
            " look for existing .*apk for tests and try to build only if nothing was found."
        )

    Printer.system_message(TAG, "Test run  phase settings:")
    testing_phase = launch_plan.testing_phase

    GlobalConfig.SHOULD_RECORD_TESTS = testing_phase.record_tests
    if GlobalConfig.SHOULD_RECORD_TESTS:
        Printer.system_message(
            TAG, "  * Launcher will " + Color.GREEN + "record device screens" +
            Color.BLUE + " during test session.")
    else:
        Printer.system_message(
            TAG, "  * Launcher test " + Color.GREEN +
            "recording is turned off" + Color.BLUE + ".")
Beispiel #30
0
def _load_paths_to_global_settings(path_set):
    GlobalConfig.SDK_DIR = clean_folder_only_dir(
        (path_set.paths["sdk_dir"]).path_value)
    if GlobalConfig.SDK_DIR == "":
        Printer.system_message(
            TAG,
            "SDK path not set in PathManifest. Will use path set in env variable "
            + Color.GREEN + "ANDROID_HOME" + Color.BLUE + ".")
        if ANDROID_HOME_ENV is None:
            message = "Env variable 'ANDROID_HOME' is not set. Launcher will quit."
            raise LauncherFlowInterruptedException(TAG, message)
        else:
            GlobalConfig.SDK_DIR = clean_folder_only_dir(
                make_path_absolute(ANDROID_HOME_ENV))
    Printer.system_message(
        TAG, "Launcher will look for SDK in dir: " + Color.GREEN +
        GlobalConfig.SDK_DIR + Color.BLUE + ".")

    GlobalConfig.AVD_DIR = clean_folder_only_dir(
        (path_set.paths["avd_dir"]).path_value)
    if GlobalConfig.AVD_DIR == "":
        Printer.system_message(
            TAG, "AVD path not set in PathManifest. "
            "Will use path set in env variable 'ANDROID_SDK_HOME'.")
        if ANDROID_SDK_HOME_ENV is None:
            Printer.system_message(
                TAG, "Env variable 'ANDROID_SDK_HOME' is not set. "
                "Trying to recreate default path from user root.")
            GlobalConfig.AVD_DIR = clean_folder_only_dir(
                make_path_absolute(HOME)) + ".android"
    Printer.system_message(
        TAG, "Launcher will look for AVD images in dir: " + Color.GREEN +
        GlobalConfig.AVD_DIR + Color.BLUE + ".")

    GlobalConfig.PROJECT_ROOT_DIR = clean_folder_only_dir(
        make_path_absolute((path_set.paths["project_root_dir"]).path_value))
    if GlobalConfig.PROJECT_ROOT_DIR == "":
        Printer.system_message(
            TAG,
            "Project root was not specified. This field is not obligatory.")
        Printer.error(
            TAG,
            "Warning: Without project root directory launcher will quit if no "
            ".*apk files will be found in directory loaded from 'apk_dir' field of PathManifest."
        )
    else:
        Printer.system_message(
            TAG, "Android project root dir set to: " + Color.GREEN +
            GlobalConfig.PROJECT_ROOT_DIR + Color.BLUE + ".")

    GlobalConfig.APK_DIR = clean_folder_only_dir(
        make_path_absolute((path_set.paths["apk_dir"]).path_value))
    if GlobalConfig.APK_DIR == "":
        message = "Directory with .*apk files was not specified. Launcher will quit."
        raise LauncherFlowInterruptedException(TAG, message)
    Printer.system_message(
        TAG, "Launcher will look for .*apk files in dir: " + Color.GREEN +
        GlobalConfig.APK_DIR + Color.BLUE + ".")

    GlobalConfig.OUTPUT_DIR = clean_folder_only_dir(
        (path_set.paths["output_dir"]).path_value)
    if GlobalConfig.OUTPUT_DIR == "":
        Printer.system_message(
            TAG,
            "Output path not set in PathManifest. Default value will be used.")
        GlobalConfig.OUTPUT_DIR = OUTPUT_DIR_DEFAULT
    if not os.path.isabs(GlobalConfig.OUTPUT_DIR):
        message = "Path " + GlobalConfig.OUTPUT_DIR + " needs to be absolute!"
        raise LauncherFlowInterruptedException(TAG, message)
    Printer.system_message(
        TAG, "Launcher will generate log from tests in dir: " + Color.GREEN +
        GlobalConfig.OUTPUT_DIR + Color.BLUE + ".")

    GlobalConfig.OUTPUT_SUMMARY_LOG_DIR = clean_folder_only_dir(
        GlobalConfig.OUTPUT_DIR + OUTPUT_SUMMARY_LOG_FOLDER_DEFAULT)
    if not os.path.isabs(GlobalConfig.OUTPUT_SUMMARY_LOG_DIR):
        message = "Path " + GlobalConfig.OUTPUT_SUMMARY_LOG_DIR + " needs to be absolute!"
        raise LauncherFlowInterruptedException(TAG, message)
    Printer.system_message(
        TAG, "Summary log will be stored in dir: " + Color.GREEN +
        GlobalConfig.OUTPUT_SUMMARY_LOG_DIR + Color.BLUE + ".")

    GlobalConfig.OUTPUT_AVD_LOG_DIR = clean_folder_only_dir(
        GlobalConfig.OUTPUT_DIR + OUTPUT_AVD_LOG_FOLDER_DEFAULT)
    if not os.path.isabs(GlobalConfig.OUTPUT_AVD_LOG_DIR):
        message = "Path " + GlobalConfig.OUTPUT_AVD_LOG_DIR + " needs to be absolute!"
        raise LauncherFlowInterruptedException(TAG, message)
    Printer.system_message(
        TAG, "Logs from AVD will be stored in dir: " + Color.GREEN +
        GlobalConfig.OUTPUT_AVD_LOG_DIR + Color.BLUE + ".")

    GlobalConfig.OUTPUT_TEST_LOG_DIR = clean_folder_only_dir(
        GlobalConfig.OUTPUT_DIR + OUTPUT_TEST_LOG_FOLDER_DEFAULT)
    if not os.path.isabs(GlobalConfig.OUTPUT_TEST_LOG_DIR):
        message = "Path " + GlobalConfig.OUTPUT_TEST_LOG_DIR + " needs to be absolute!"
        raise LauncherFlowInterruptedException(TAG, message)
    Printer.system_message(
        TAG, "Logs from tests will be stored in dir: " + Color.GREEN +
        GlobalConfig.OUTPUT_TEST_LOG_DIR + Color.BLUE + ".")

    GlobalConfig.OUTPUT_TEST_LOGCAT_DIR = clean_folder_only_dir(
        GlobalConfig.OUTPUT_DIR + OUTPUT_TEST_LOGCAT_FOLDER_DEFAULT)
    if not os.path.isabs(GlobalConfig.OUTPUT_TEST_LOGCAT_DIR):
        message = "Path " + GlobalConfig.OUTPUT_TEST_LOGCAT_DIR + " needs to be absolute!"
        raise LauncherFlowInterruptedException(TAG, message)
    Printer.system_message(
        TAG, "Logcat logs from tests will be stored in dir: " + Color.GREEN +
        GlobalConfig.OUTPUT_TEST_LOGCAT_DIR + Color.BLUE + ".")

    GlobalConfig.DEVICE_VIDEO_STORAGE_DIR = clean_folder_only_dir(
        DEVICE_VIDEO_STORAGE_FOLDER_DEFAULT)
    Printer.system_message(
        TAG,
        "Firstly recordings will be saved in root directory of test device storage in "
        + Color.GREEN + GlobalConfig.DEVICE_VIDEO_STORAGE_DIR + Color.BLUE +
        " folder.")

    GlobalConfig.OUTPUT_TEST_RECORDINGS_DIR = clean_folder_only_dir(
        GlobalConfig.OUTPUT_DIR + OUTPUT_TEST_VIDEO_FOLDER_DEFAULT)
    if not os.path.isabs(GlobalConfig.OUTPUT_TEST_RECORDINGS_DIR):
        message = "Path " + GlobalConfig.OUTPUT_TEST_RECORDINGS_DIR + " needs to be absolute!"
        raise LauncherFlowInterruptedException(TAG, message)
    Printer.system_message(
        TAG,
        "Secondly recordings from tests will be pulled from each device to dir: "
        + Color.GREEN + GlobalConfig.OUTPUT_TEST_RECORDINGS_DIR + Color.BLUE +
        ".")

    GlobalConfig.OUTPUT_STYLES_FOLDER_DIR = clean_folder_only_dir(
        GlobalConfig.OUTPUT_DIR + OUTPUT_HTML_STYLES_FOLDER_DEFAULT)
    if not os.path.isabs(GlobalConfig.OUTPUT_STYLES_FOLDER_DIR):
        message = "Path " + GlobalConfig.OUTPUT_STYLES_FOLDER_DIR + " needs to be absolute!"
        raise LauncherFlowInterruptedException(TAG, message)
    Printer.system_message(
        TAG, "Styles for all html logs will be stored in dir: " + Color.GREEN +
        GlobalConfig.OUTPUT_STYLES_FOLDER_DIR + Color.BLUE + ".")

    GlobalConfig.OUTPUT_LOGCAT_HTML_DIR = clean_folder_only_dir(
        GlobalConfig.OUTPUT_DIR + OUTPUT_TEST_LOGCAT_HTML_FOLDER_DEFAULT)
    if not os.path.isabs(GlobalConfig.OUTPUT_LOGCAT_HTML_DIR):
        message = "Path " + GlobalConfig.OUTPUT_TEST_RECORDINGS_DIR + " needs to be absolute!"
        raise LauncherFlowInterruptedException(TAG, message)
    Printer.system_message(
        TAG,
        "Html logs presenting logcats from devices will be stored in dir: " +
        Color.GREEN + GlobalConfig.OUTPUT_LOGCAT_HTML_DIR + Color.BLUE + ".")

    GlobalConfig.OUTPUT_INDEX_HTML_DIR = clean_folder_only_dir(
        GlobalConfig.OUTPUT_DIR) + OUTPUT_HTML_INDEX_FILE_NAME
    if not os.path.isabs(GlobalConfig.OUTPUT_INDEX_HTML_DIR):
        message = "Path " + GlobalConfig.OUTPUT_TEST_RECORDINGS_DIR + " needs to be absolute!"
        raise LauncherFlowInterruptedException(TAG, message)
    Printer.system_message(
        TAG,
        "All html logs containing results from tests, logcats and videos can be accessed from "
        + Color.GREEN + GlobalConfig.OUTPUT_INDEX_HTML_DIR + Color.BLUE +
        " file generated after " + "session ends.")

    GlobalConfig.LOG_GENERATOR_DIR = clean_folder_only_dir(
        LOG_GENERATOR_DIR_DEFAULT)
    if not os.path.isabs(GlobalConfig.LOG_GENERATOR_DIR):
        message = "Path " + GlobalConfig.LOG_GENERATOR_DIR + " needs to be absolute!"
        raise LauncherFlowInterruptedException(TAG, message)
    Printer.system_message(
        TAG, "Logs will be generated with usage of " + Color.GREEN +
        "LogGenerator.py" + Color.BLUE + " file stored in dir: " +
        Color.GREEN + GlobalConfig.LOG_GENERATOR_DIR + Color.BLUE + ".")