def build_test_apk(self, test_set): assemble_task = test_set.test_apk_assemble_task self._check_if_build_is_possible(assemble_task) cmd = self.gradle_command_assembler.assemble_build_test_apk_cmd( self.gradle_bin, test_set.gradle_build_params, assemble_task, GlobalConfig.PROJECT_ROOT_DIR) ShellHelper.execute_shell(cmd, True, True)
def run(self): while True: if self.recordings and self._all_recordings_has_commands(): recording = self.recordings.pop() # TODO Implement proper synchronisation/wait for .mp4 to finish being written to time.sleep(10) ShellHelper.execute_shell(self.recording_pull_cmds.get(recording), False, False) ShellHelper.execute_shell(self.recording_clear_cmds.get(recording), False, False) if self.should_finish: break
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 launch_avd(self, avd_schema, port, log_file): emulator_binary = self.emulator_bin_dict[ avd_schema.launch_avd_launch_binary_name] cmd = self.emulator_command_assembler.assemble_launch_avd_cmd( emulator_binary, avd_schema, port, log_file) return ShellHelper.execute_shell(cmd, True, False)
def list_avd(self): cmd = self.avdmanager_command_assembler.assemble_list_avd_cmd( self.avdmanager_bin) return ShellHelper.execute_shell(cmd, False, False)
def create_avd(self, avd_schema): cmd = self.avdmanager_command_assembler.assemble_create_avd_cmd( self.avdmanager_bin, avd_schema) return ShellHelper.execute_shell(cmd, True, True)
def read_logcat(self, device_adb_name): cmd = self.adb_logcat_command_assembler.assemble_dump_logcat_cmd( self.adb_bin, device_adb_name) return ShellHelper.execute_shell(cmd, False, False)
def monitor_logcat(self, device_adb_name): cmd = self.adb_logcat_command_assembler.monitor_logcat_schema( self.adb_bin, device_adb_name) return ShellHelper.execute_shell(cmd, False, False)
def list_resources(self, apk_filepath): cmd = self.aapt_command_assembler.assemble_list_all_cmd( self.aapt_bin, apk_filepath) return ShellHelper.execute_shell(cmd, False, False)
def kill_device(self, device_adb_name): cmd = self.adb_command_assembler.assemble_kill_device_cmd( self.adb_bin, device_adb_name) return ShellHelper.execute_shell(cmd, True, False)
def check_for_directory(self, device_adb_name, directory): cmd = self.adb_shell_command_assembler.assemble_check_if_dir_exists_cmd( self.adb_bin, device_adb_name, directory) return ShellHelper.execute_shell(cmd, True, True)
def run(self): ShellHelper.execute_shell(self.flush_logcat_cmd, False, False) with subprocess.Popen(self.monitor_logcat_cmd, shell=True, stdout=subprocess.PIPE, bufsize=1, universal_newlines=True, encoding="utf-8", errors="ignore") as p: self.logcat_process = p current_log = None current_process_pid = None current_recording_name = None for line in p.stdout: line_cleaned = line.encode("utf-8", "ignore").decode("utf-8").strip() line_parts = line_cleaned.split() if len(line_parts) <= 5: continue if self.TEST_STARTED in line and current_log is None and current_process_pid is None: current_log = TestLogCat() current_process_pid = line_parts[self.PID_INDEX] test_name = re.findall("TestRunner: started:(.+)\(", line_cleaned) current_log.test_name = test_name[0].strip() full_test_package = re.findall("\((.+)\)", line_cleaned) package_parts = full_test_package[0].split(".") current_log.test_container = package_parts.pop().strip() current_log.test_full_package = full_test_package[0].strip() + "." + test_name[0].strip() if self.should_record_screen: self._restart_recording(current_log.test_name) if current_recording_name is not None: self.recordings.append(current_recording_name) current_recording_name = self.screen_recording_thread.recording_name if current_log is not None: if line_parts[self.PID_INDEX] == current_process_pid: logcat_line = TestLogCatLine() date = line_parts[self.DATE_INDEX] logcat_line.date = date time_hour = line_parts[self.TIME_INDEX] logcat_line.time = time_hour level = line_parts[self.LEVEL_INDEX] logcat_line.level = level tag = line_parts[self.TAG_INDEX] if len(tag) > 0 and tag[len(tag) - 1] == ":": tag = tag[:-1] logcat_line.tag = tag string_pos = line_cleaned.find(tag) length_tag = len(tag) text = line_cleaned[(string_pos + length_tag):].strip() if text.startswith(":"): text = text[1:] text = text.strip() logcat_line.text = text current_log.lines.append(logcat_line) if self.TEST_FINISHED in line: self.logs.append(current_log) if self.should_record_screen: self._stop_recording() self.recordings.append(current_recording_name) current_log = None current_process_pid = None current_recording_name = None
def record_screen(self, device_adb_name, file_dir): cmd = self.adb_shell_command_assembler.assemble_record_screen_cmd( self.adb_bin, device_adb_name, file_dir) return ShellHelper.execute_shell(cmd, False, False)
def create_dir(self, device_adb_name, file_dir): cmd = self.adb_shell_command_assembler.assemble_create_dir_cmd( self.adb_bin, device_adb_name, file_dir) return ShellHelper.execute_shell(cmd, True, True)
def get_property(self, device_adb_name, device_property): cmd = self.adb_shell_command_assembler.assemble_get_property_cmd( self.adb_bin, device_adb_name, device_property) return ShellHelper.execute_shell(cmd, False, False)
def pull(self, device_adb_name, file_dir, file_destination): cmd = self.adb_command_assembler.assemble_pull_file_cmd( self.adb_bin, device_adb_name, file_dir, file_destination) return ShellHelper.execute_shell(cmd, False, False)
def install_apk(self, device_adb_name, apk_name): cmd = self.adb_command_assembler.assemble_install_apk_cmd( self.adb_bin, device_adb_name, apk_name) return ShellHelper.execute_shell(cmd, True, False)
def devices(self): cmd = self.adb_command_assembler.assemble_devices_cmd(self.adb_bin) return ShellHelper.execute_shell(cmd, False, False)
def kill_server(self): cmd = self.adb_command_assembler.assemble_kill_server_cmd(self.adb_bin) return ShellHelper.execute_shell(cmd, True, True)
def dump_badging(self, apk_filepath): cmd = self.aapt_command_assembler.assemble_dump_badging_cmd( self.aapt_bin, apk_filepath) return ShellHelper.execute_shell(cmd, False, False)
def get_device_android_id(self, device_adb_name): cmd = self.adb_settings_command_assembler.assemble_get_device_android_id_cmd( self.adb_bin, device_adb_name) return ShellHelper.execute_shell(cmd, False, False)
def get_installed_packages(self, device_adb_name): cmd = self.adb_package_manager_command_assembler.assemble_list_installed_packages_cmd( self.adb_bin, device_adb_name) return ShellHelper.execute_shell(cmd, False, False)
def wait_for_device(self): cmd = self.adb_command_assembler.assemble_wait_for_device_cmd( self.adb_bin) return ShellHelper.execute_shell(cmd, False, False)
def clear_package_cache(self, device_adb_name, package_name): cmd = self.adb_package_manager_command_assembler.assemble_clear_package_cache_cmd( self.adb_bin, device_adb_name, package_name) return ShellHelper.execute_shell(cmd, True, True)
def get_open_ports(avd_set): _check_port_rules(avd_set) ports_to_use = avd_set.avd_port_rules.ports_to_use if len(ports_to_use) > 0: message = "Requested ports:" for port in ports_to_use: message += (" '" + str(port) + "'") message += "." message(TAG, message) ports_to_ignore = avd_set.avd_port_rules.ports_to_ignore if len(ports_to_ignore) > 0: message = "Ignoring ports:" for port in ports_to_ignore: message += (" '" + str(port) + "'") message += "." Printer.system_message(TAG, message) should_assign_missing_ports = avd_set.avd_port_rules.assign_missing_ports if should_assign_missing_ports: Printer.system_message( TAG, "Not requested ports will be automatically assigned.") else: Printer.system_message( TAG, "Port auto assignment is turned off. Only specified ports will be used." ) avd_instances = 0 for avd in avd_set.avd_list: avd_instances += avd.instances range_min = avd_set.avd_port_rules.search_range_min range_max = avd_set.avd_port_rules.search_range_max Printer.system_message( TAG, "Checking for " + str(avd_instances) + " open ports in range <" + str(range_min) + ", " + str(range_max) + ">.") available_ports = list() for port in ports_to_use: try: ShellHelper.execute_shell(GeneralCommand.CHECK_PORT.format(port), False, False) port_open = False except: port_open = True if port_open: available_ports.append(port) else: message = "Port {} was requested but is currently used." message = message.format(str(port)) raise LauncherFlowInterruptedException(TAG, message) if should_assign_missing_ports: temp_port = range_min for i in range(avd_instances - len(available_ports)): while temp_port < range_max and len( available_ports) != avd_instances: try: ShellHelper.execute_shell( GeneralCommand.CHECK_PORT.format(temp_port), False, False) port_open = False except: port_open = True if port_open: if temp_port not in available_ports and temp_port not in ports_to_ignore: available_ports.append(temp_port) else: Printer.error( TAG, "Port " + str(temp_port) + " is currently used and will be omitted.") temp_port += 2 if len(available_ports) != avd_instances: message = "There are only {} open ports available in range <{}, {}>. Requested amount: {}." message = message.format(str(len(available_ports)), str(range_min), str(range_max), str(avd_instances)) raise LauncherFlowInterruptedException(TAG, message) return available_ports