Index: suite_leahi/tst_service_export_logs/test.py =================================================================== diff -u --- suite_leahi/tst_service_export_logs/test.py (revision 0) +++ suite_leahi/tst_service_export_logs/test.py (revision 14e13c671eb6df2f9f100143a68c0fa86c3d2241) @@ -0,0 +1,172 @@ +# -*- coding: utf-8 -*- + +# Python + +import builtins +import names +import os +import glob +from pathlib import Path + +from configuration import application_init as application_init +from configuration import config, utility +from leahi_dialin.ui.td_messaging import TD_Messaging +from leahi_dialin.common.td_defs import TDOpModes, TDStandbyStates +from leahi_dialin.ui import utils +from calendar import isleap + + +td =TD_Messaging() + +def custom_object_for_export_log(text): + """ + Method to set custom object property for export option + @param text : (string) parameter text + """ + names.o_option_combo_box["text"] = text + return names.o_option_combo_box + +def service_text_obj(text): + names.o_SettingsHome_Service_Text["text"] = text + return names.o_SettingsHome_Service_Text + +def navigate_to_service_menu(): + """ + Method to navigate to "Service" screen + """ + test.startSection("Navigating to 'Service' menu") + td.td_operation_mode(op_mode=TDOpModes.MODE_SERV.value, sub_mode=TDStandbyStates.STANDBY_START_STATE.value) + utils.waitForGUI(0.5) + service_screen_text = utility.get_object_from_names(service_text_obj(config.SERVICE_SCREEN_TITLE_TEXT), error_message="Service Screen title object missing") + if service_screen_text is not None: + test.compare(service_screen_text.text, config.SERVICE_SCREEN_TITLE_TEXT, "{} screen is displayed".format(config.SERVICE_SCREEN_TITLE_TEXT)) + test.endSection() + +def navigate_to_export_logs(): + test.startSection("Verifying the the export logs screen") + export_log_subscreen_menu_element = utility.get_object_from_names(names.o_SettingsHome_touchItem_ExportsLogs, error_message = "export log menu element object missing") + if export_log_subscreen_menu_element is not None: + mouseClick(export_log_subscreen_menu_element) + + utils.waitForGUI(1) + + export_log_text = utility.get_object_from_names(names.o_export_logs_text, error_message = "export log text object missing") + if export_log_text is not None: + test.compare(export_log_text.text,config.EXPORT_LOG_TEXT,"{} should be under export logs screen ".format(config.EXPORT_LOG_TEXT)) + test.endSection() + +def select_different_log_type(whichTypeIndex): + log_type_combo_box = utility.get_object_from_names(names.o_combo_box, error_message="Combo box object is missing") + if log_type_combo_box is not None: + mouseClick(waitForObjectExists(names.o_combo_box)) + log_type_option = utility.get_object_from_names(custom_object_for_export_log(config.EXPORT_LOGS_OPTIONS[whichTypeIndex]), + error_message=f"Option {config.EXPORT_LOGS_OPTIONS[whichTypeIndex]} object is missing", timeout_ms = 500) + if log_type_option is not None: + mouseClick(log_type_option) + utils.waitForGUI(2) + test.compare(config.EXPORT_LOGS_OPTIONS[whichTypeIndex], waitForObjectExists(names.o_combo_box ).displayText, "User should able to select {}".format(config.EXPORT_LOGS_OPTIONS[whichTypeIndex])) + utils.waitForGUI(1) + mouseClick(waitForObjectExists(names.o_SettingsBase_logTypeExportButton_ExportButton)) + mouseClick(waitForObjectExists(names.o_SettingsBase_usbEjectButton_USBButton)) + return True + return False # default return if not successful + +def check_eject_usb_button(is_enabled, is_clicking_button = False): + """ + For checking enabled/disabled state of the usb eject button + """ + eject_usb_button = utility.get_object_from_names(names.o_SettingsBase_usbEjectButton_USBButton, error_message="eject usb button object not found") + if eject_usb_button is not None: + test.compare(eject_usb_button.enabled, is_enabled, f"Check if the USB eject button enabled = {is_enabled}") + if is_clicking_button: + utils.waitForGUI(0.5) + mouseClick(eject_usb_button) + utils.waitForGUI(0.5) + +app_context = None; +def init_application_service_export_logs(): + """ + starts the application and traverse to the export log screen + """ + app_context = startApplication(config.AUT_NAME+ " -l") + + navigate_to_service_menu() + navigate_to_export_logs() + +def stop_application(): + if app_context is not None: + app_context.detach() + +def test_export_logs_eject_usb_case(): + """ + tests the case that the usb is ejected, requires restarting the application to get original state + """ + init_application_service_export_logs() + + mouseClick(waitForObjectExists(names.o_SettingsBase_logTypeExportButton_ExportButton)) + utils.waitForGUI(1) + check_eject_usb_button(config.ENABLED, is_clicking_button=True) + utils.waitForGUI(1) + # check_eject_usb_button(config.DISABLED) + stop_application() + +def select_a_log_file_and_export(): + test.startSection("Selecting a log file and exporting it") + mouseClick(waitForObjectExists(names.o_SettingsBase_progressRect_ProgressRect)) + utils.waitForGUI(1) + + mouseClick(waitForObjectExists(names.o_SettingsBase_logTypeExportButton_ExportButton)) + mouseClick(waitForObjectExists(names.o_SettingsBase_usbEjectButton_USBButton)) + +def delete_existing_files_usb_folders(): + + base_path = Path.home() / "Desktop/usb-disk" + + cleanup_targets = { + base_path / "log": ["*.log"], + base_path / "service": ["*.err"] + } + + for folder, extensions in cleanup_targets.items(): + if not folder.is_dir(): + test.log(f"Warning: Directory '{folder}' not found. Skipping.") + continue + + found = False + for ext in extensions: + for file_path in folder.glob(ext): + try: + os.remove(file_path) + found = True + except OSError as e: + test.log(f" Error deleting file {file_path}: {e}") + + if not found: + test.log("No matching files found.") + + test.log("Cleanup complete.") + +def main(): + utils.tstStart(__file__) + + application_init.setup_post_log_successful_start() + + test.startSection("Export Application files") + + delete_existing_files_usb_folders() + test_export_logs_eject_usb_case() + closeWindow(names.o_Gui_MainView) + + test.startSection("Export Service files") + + init_application_service_export_logs() + select_different_log_type(1) + closeWindow(names.o_Gui_MainView) + + test.startSection("Export single log file") + delete_existing_files_usb_folders() + init_application_service_export_logs() + select_a_log_file_and_export() + + utils.tstDone() + \ No newline at end of file