# -*- coding: utf-8 -*-" ## # Copyright (c) 2019-2023 Diality Inc. - All Rights Reserved. # copyright # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, # IN PART OR IN WHOLE, # WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # # file tst_settings_information # date 10/07/2023 # author Vy Duong ### ## Tests for the service menu section that is password protected ### import builtins import names from configuration import application_init as application_init from configuration import config, utility from dialin.ui.hd_simulator import HDSimulator from dialin.common.hd_defs import HDOpModes, HDStandbyStates from dialin.ui import utils from calendar import isleap hd_simulator = HDSimulator() def service_text_obj(text): names.o_service_home_text_obj["text"] = text return names.o_service_home_text_obj def navigate_to_service_menu(): """ Method to navigate to "Service" screen """ test.startSection("Navigating to 'Service' menu") hd_simulator.cmd_send_hd_operation_mode(op_mode=HDOpModes.MODE_SERV.value, sub_mode=HDStandbyStates.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)) service_text = utility.get_object_from_names(names.o_service_text, error_message = "Service text object is missing") if service_text is not None: test.compare(service_text.text,config.SERVICE_TEXT, "{} screen is displayed".format(config.SERVICE_TEXT)) mouseClick(waitForObjectExists(names.o_service_text)) #enter the password to access screen test.log("Clicking on password entry field") utils.waitForGUI(0.5) mouseClick(waitForObjectExists(names.o_password_text_field)) mouseClick(waitForObjectExists(names.o_switch_keyboard_to_keypad)) password = config.DEFAULT_SERVICE_PASSWORD_RAW type(waitForObject(names.o_password_text_field), str(password)) confirm_button = (waitForObjectExists(names.o_service_confirm_btn).text) test.compare(confirm_button, config.CONFIRM_TEXT, "Button text should be {}".format(config.CONFIRM_TEXT)) mouseClick(waitForObjectExists(names.o_service_confirm_btn)) utils.waitForGUI(0.5) # HD response to advance to the service menu hd_simulator.cmd_send_hd_operation_mode(op_mode=HDOpModes.MODE_SERV.value, sub_mode=HDStandbyStates.STANDBY_START_STATE.value) test.endSection() def navigate_to_subscreen(whichScreenKey, expectedScreenTitle, titleObject): """ Method to navigate to the water input mode screen @param whichScreenEnum : SERVICE_SCREEN_SUBSCREEN_INDEX """ test.startSection(f"Navigating '{expectedScreenTitle}' screen") utils.waitForGUI(0.5) names.o_serviceScreen_subscreen_menu["occurrence"] = whichScreenKey service_subScreen_menu_element = utility.get_object_from_names(names.o_serviceScreen_subscreen_menu, error_message="subscreen menu element not found") if service_subScreen_menu_element is not None: mouseClick(service_subScreen_menu_element) utils.waitForGUI(0.5) subscreenTitle = utility.get_object_from_names(titleObject, error_message=f"{expectedScreenTitle} object is missing") if subscreenTitle is not None: test.compare(subscreenTitle.text, expectedScreenTitle, "{} should be displayed when user is navigated to this screen".format(expectedScreenTitle)) test.endSection() def test_enable_root_ssh_screen(): test.startSection(f"Navigating {config.SERVICES_ENABLE_ROOT_SSH_TITLE} screen") navigate_to_subscreen(config.SERVICE_SCREEN_SUBSCREEN_INDEX["ENABLE_ROOT_SUBSCREEN"], config.SERVICES_ENABLE_ROOT_SSH_TITLE, names.o_SettingsBase_Enable_Root_SSH_Text) enable_root_ssh_options=[{"option_label": "Enable SSH Login", "option_switch": names.o_SettingsBase_settingsRootSSHAccess_SSHDSwitch_Switch}, {"option_label": "Enable Root Login", "option_switch": names.o_SettingsBase_settingsRootSSHAccess_RootSwitch_Switch}] #traverse the options available to enable/disable on the "enable root ssh" screen for index in range(0,len(enable_root_ssh_options), 1): option_text = enable_root_ssh_options[index]["option_label"] names.o_SettingsBase_Enable_Root_SSH_Screen_Text["text"] = option_text try: # option label text object option_label_text_object = waitForObject(names.o_SettingsBase_Enable_Root_SSH_Screen_Text) test.compare(option_label_text_object.text, option_text, f"{option_text} text") utils.waitForGUI(0.5) try: option_switch_object = waitForObject(enable_root_ssh_options[index]["option_switch"]) test.compare(option_switch_object.checked, False, f"{option_text} switch value should be False") utils.waitForGUI(0.5) mouseClick(option_switch_object) utils.waitForGUI(0.5) test.compare(option_switch_object.checked, True, f"{option_text} switch value should be True") except LookupError: test.fail(f"FAIL : Switch object for \"{option_text}\" not found") except LookupError: test.fail(f"FAIL : Object for \"{option_text}\" not found") # done, go back to main screen back_button_obj = utility.get_object_from_names(names.o_service_back_btn, error_message = "enable root ssh screen back button object missing") if back_button_obj is not None: mouseClick(back_button_obj) utils.waitForGUI(0.5) test.endSection() ## ================================================================================= ## Helper functions for the Factory reset and decommissioning sub screens: ## ================================================================================= def check_factory_reset_confirm_button_state(expected_enable_state): try: test.compare(waitForObjectExists(names.o_services_factory_reset_confirm_button).enabled, expected_enable_state, f"Check that the confirm button state is {expected_enable_state}") utils.waitForGUI(0.5) except LookupError: test.fail("ERROR : Confirm button object missing") def check_factory_reset_back_button_state(expected_enable_state): try: test.compare(waitForObjectExists(names.o_services_factory_reset_back_button).enabled, expected_enable_state, f"Check that the enable button state is {expected_enable_state}") utils.waitForGUI(0.5) except LookupError: test.fail("ERROR : back button object missing") def check_decommission_confirm_button_state(expected_enable_state): try: test.compare(waitForObjectExists(names.o_service_decommission_confirm_button).enabled, expected_enable_state, f"Check that the confirm button state is {expected_enable_state}") utils.waitForGUI(0.5) except LookupError: test.fail("ERROR : Confirm button object missing") def check_decommission_back_button_state(expected_enable_state): try: test.compare(waitForObjectExists(names.o_service_decommission_back_button).enabled, expected_enable_state, f"Check that the enable button state is {expected_enable_state}") utils.waitForGUI(0.5) except LookupError: test.fail("ERROR : back button object missing") def check_decommission_back_button_state(expected_enable_state): try: test.compare(waitForObjectExists(names.o_service_decommission_back_button).enabled, expected_enable_state, f"Check that the enable button state is {expected_enable_state}") utils.waitForGUI(0.5) except LookupError: test.fail("ERROR : back button object missing") def click_on_factory_reset_confirm_button(): try: mouseClick(waitForObject(names.o_services_factory_reset_confirm_button)) utils.waitForGUI(0.5) except LookupError: test.fail("ERROR : Confirm button object missing") def click_on_decommission_confirm_button(): try: mouseClick(waitForObject(names.o_service_decommission_confirm_button)) utils.waitForGUI(0.5) except LookupError: test.fail("ERROR : Confirm button object missing") def test_user_confirmation_screen(expected_title, expected_message, is_test_click_confirm = False, is_test_click_cancel = False): # expecting a pop-up user confirmation dialog confirmation_dialog = utility.get_object_from_names(names.o_modalDialog, error_message = "Confirmation dialog object not found") if confirmation_dialog is not None: test.compare(confirmation_dialog.visible, True, "Check if user confirmation dialog is visible") # check dialog title names.o_service_subscreen_titleText["text"] = expected_title confirmation_title = utility.get_object_from_names(names.o_service_subscreen_titleText, error_message = "Confirmation dialog title object not found") if confirmation_title is not None: test.compare(confirmation_title.text, expected_title, "Checking the confirm dialog message string") # check dialog message confirmation_message = utility.get_object_from_names(names.o_service_confirmation_are_you_sure_TitleText, error_message = "Confirmation dialog message object not found") if confirmation_message is not None: test.compare(confirmation_message.text, expected_message, "Checking the confirm dialog message string") ## Do check on the confirmation dialog action buttons # Cancel Button confirmation_cancel_button = utility.get_object_from_names(names.o_cancelTouch_TouchRect, error_message = "Cancel button object not found") if confirmation_cancel_button is not None: test.compare(confirmation_cancel_button.enabled, config.ENABLED, "Checking that the cancel button is enabled") if is_test_click_cancel and confirmation_cancel_button.enabled: mouseClick(confirmation_cancel_button) utils.waitForGUI(0.5) #Confirm Button : if is_test_click_cancel is not True: confirmation_confirm_button = utility.get_object_from_names(names.o_confirmTouch_TouchRect, error_message = "Confirm button object not found") if confirmation_confirm_button is not None: test.compare(confirmation_confirm_button.enabled, config.ENABLED, "Checking that the confirm button is enabled") if is_test_click_confirm and confirmation_confirm_button.enabled: mouseClick(confirmation_confirm_button) utils.waitForGUI(0.5) # clicking any button will trigger the dialog to be invisible, check if is_test_click_cancel or is_test_click_confirm: test.compare(confirmation_dialog.visible, False, "Checking dialog is not visible since testing button clicked") else: test.compare(confirmation_dialog.visible, True, "Checking dialog is visible since not testing for button clicked") utils.waitForGUI(1) else: test.log("NOTE: Confirmation Dialog body tests not run since dialog object not found") ## ================================================================================= def test_factory_reset_screen(): test.startSection("Navigating to 'Factory Reset' screen") navigate_to_subscreen(config.SERVICE_SCREEN_SUBSCREEN_INDEX["FACTORY_RESET_SUBSCREEN"], config.SERVICES_FACTORY_RESET_TITLE, names.o_userConfirmation_Factory_Reset_Text) # test buttons enable-state check_factory_reset_confirm_button_state(config.ENABLED) check_factory_reset_back_button_state(config.ENABLED) # Checking the user confirmation dialog behavior for when clicking cancel button click_on_factory_reset_confirm_button() utils.waitForGUI(0.5) test_user_confirmation_screen(expected_title=config.SERVICES_FACTORY_RESET_TITLE, expected_message=config.SERVICES_FACTORY_RESET_CONFIRM_MSG, is_test_click_cancel = True) # Checking the user confirmation dialog behavior for when clicking cancel button # TODO need to uncomment when scripting handling is added # click_on_factory_reset_confirm_button() # test_user_confirmation_screen(expected_title = config.SERVICES_FACTORY_RESET_TITLE, # expected_message = config.SERVICES_FACTORY_RESET_CONFIRM_MSG, # is_test_click_confirm = True) # when reset is happening, the buttons should be both disabled # check_factory_reset_confirm_button_state(config.DISABLED) # check_factory_reset_back_button_state(config.DISABLED) # TODO check for completion or failure state # Done, navigate back to main screen back_button_obj = utility.get_object_from_names(names.o_services_factory_reset_back_button, error_message = "Factory reset screen back button object missing") if back_button_obj is not None: mouseClick(back_button_obj) utils.waitForGUI(0.5) test.endSection() def test_decommissioning_screen(): test.startSection("Navigating to 'decommissioning' screen") navigate_to_subscreen(config.SERVICE_SCREEN_SUBSCREEN_INDEX["DECOMMISSION_SUBSCREEN"], config.SERVICES_DECOMMISSION_TITLE, names.userConfirmation_Decommissioning_Text) # test buttons enable-state check_decommission_confirm_button_state(config.ENABLED) check_decommission_back_button_state(config.ENABLED) # Checking the user confirmation dialog behavior for when clicking cancel button click_on_decommission_confirm_button() utils.waitForGUI(0.5) test_user_confirmation_screen(expected_title=config.SERVICES_DECOMMISSION_TITLE, expected_message=config.SERVICES_DECOMMISSION_CONFIRM_MSG, is_test_click_cancel = True) # Checking the user confirmation dialog behavior for when clicking cancel button # TODO need to uncomment when scripting handling is added # click_on_confirm_button() # test_user_confirmation_screen(expected_title = config.SERVICES_FACTORY_RESET_TITLE, # expected_message = config.SERVICES_FACTORY_RESET_CONFIRM_MSG, # is_test_click_confirm = True) # when reset is happening, the buttons should be both disabled # check_factory_reset_confirm_button_state(config.DISABLED) # check_factory_reset_back_button_state(config.DISABLED) # TODO check for completion or failure state # Done, navigate back to main screen back_button_obj = utility.get_object_from_names(names.o_service_decommission_back_button, error_message = "Decommission screen back button object missing") if back_button_obj is not None: mouseClick(back_button_obj) utils.waitForGUI(0.5) test.endSection() def main(): utils.tstStart(__file__) test.log("TODO test case incomplete, need script call handling in the APP to complete", "Need to add an option to the application to allow mocked-script calls") application_init.setup_post_log_successful_start() startApplication(config.AUT_NAME+ " -l") navigate_to_service_menu() # test the subscreens test_enable_root_ssh_screen() test_factory_reset_screen() test_decommissioning_screen() utils.tstDone()