# Subject/Title: Pre-Treatment - SW - 02 - Foundation - Q&R # # Functionalities: Testing of Pre-Treatment Foundation # # Steps: # 1 Handle startTreatment sent messages from UI # 2 Update Advanced Mode back to deLDfault, Start Leahi Application and simulate TD standby mode # and Navigate to through Pre-Treatment Pages Comparing Page Title and Page Contents # Click on Start in UI and Verify FW receives the request # simulate TD Treatment mode and simulate TD Post Treatment mode # Navigate to Device settings using service password and Toggle Advanced Mode Switch # Navigate to Through Pre-Treatment Pages Comparing Page Title and Page Contents import names import re from configuration import config, utility, navigation, application_init from leahi_dialin.ui import utils from leahi_dialin.ui.td_messaging import TD_Messaging from leahi_dialin.common.td_defs import TDOpModes, TDTreatmentStates from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions from leahi_dialin.protocols import CAN from leahi_dialin.utils import conversions td_simulator = TD_Messaging() can_interface = td_simulator.can_interface startTreatment = "-1" # handler for messages from UI to FW def handle_start_treatment_request(message, timestamp=0.0): """ Called when the user requests to firmware from UI @return: None """ message = message["message"] index = MsgFieldPositions.START_POS_FIELD_1 state, index = conversions.bytearray_to_integer(message, index) global startTreatment startTreatment = str(state) def send_start_treatment_response(vRejectionReason: int): """ the start treatment response message method(Msg ID: 0xXX, XXX) Args: None @return: None """ payload = conversions.integer_to_bytearray(1 if vRejectionReason == 0 else 0) payload += conversions.integer_to_bytearray(vRejectionReason) message = CAN.DenaliMessage.build_message( channel_id=CAN.DenaliChannels.td_to_ui_ch_id, message_id=MsgIds.MSG_ID_TD_ADJUST_START_TREATMENT_RESPONSE.value, payload=payload, ) can_interface.send(message, 0) def click_text(container, text, timeout=3000): mouseClick( utility.findChildByText(container, text) if container else utility.setObjectText(names.o_preTreatmentStack_Text, text) ) def click_next(): next_button = waitForObject( utility.setObjectText(names.o_preTreatmentStack_Text, config.NEXT), 3000 ) mouseClick(next_button) def click_auto_load(): auto_load_button = waitForObject( utility.setObjectText(names.o_preTreatmentStack_Text, config.AUTO_LOAD), 3000 ) mouseClick(auto_load_button) def wait_compare_text(obj_name, expected, msg_suffix): obj = waitForObject( utility.setObjectText(names.o_preTreatmentStack_Text, expected), 3000 ) test.compare( obj.text if hasattr(obj, "text") else obj, expected, f"Comparison of {msg_suffix}", ) def set_treatment_params(blood, dial, dur, hep_vol, hep_rate, hep_stop, acid_idx, temp, dialyzer_idx, saline, bp, bicarb_idx): utility.set_value_based_on_target( names.o_PreTreatmentCreate_bloodFlowRateControl_ValueAdjuster, blood ) utility.set_value_based_on_target( names.o_PreTreatmentCreate_dialysateFlowRateControl_ValueAdjuster, dial ) utility.set_value_based_on_target( names.o_PreTreatmentCreate_durationControl_ValueAdjuster, dur ) utility.set_value_based_on_target( names.o_PreTreatmentCreate_heparinBolusVolumeControl_ValueAdjuster, hep_vol ) utility.set_value_based_on_target( names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, hep_rate ) utility.set_value_based_on_target( names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster, hep_stop ) utility.select_different_dropdown( names.o_PreTreatmentCreate_acidConcentrateComboBox_BaseComboBox, config.ACID_CONCENTRATE, acid_idx, ) utility.set_value_based_on_target( names.o_PreTreatmentCreate_dialysateTemperatureControl_ValueAdjuster, temp ) utility.select_different_dropdown( names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox, config.DIALYZER_TYPE, dialyzer_idx, ) utility.set_value_based_on_target( names.o_PreTreatmentCreate_salineBolusVolumeControl_ValueAdjuster, saline ) utility.set_value_based_on_target( names.o_PreTreatmentCreate_bpMeasurementIntervalControl_ValueAdjusterCustom, bp ) utility.select_different_dropdown( names.o_PreTreatmentCreate_bicarbonateConcentrateComboBox_BaseComboBox, config.BICARBONATE, bicarb_idx, ) def verify_start_treatment_request(): click_text(None, config.START) test.verify( waitFor("'startTreatment == 1'", 3000), "Testing UI -> TD message Auto Load" ) def main(): utils.tstStart(__file__) test.startSection("Pre-Treatment Foundation") global startTreatment if can_interface: can_interface.register_receiving_publication_function( CAN.DenaliChannels.ui_to_td_ch_id, MsgIds.MSG_ID_UI_ADJUST_START_TREATMENT_REQUEST.value, handle_start_treatment_request, ) application_init.reset_system_setting("AdvancedMode") startApplication(utility.aut("-q")) # --- Flow 1: Full Pre-Treatment --- td_simulator.td_operation_mode(TDOpModes.MODE_STAN.value) mouseClick(waitForObject(names.o_createTreatmentRect_TouchRect, 3000)) td_simulator.td_operation_mode(TDOpModes.MODE_PRET.value) # Concentrates waitForObjectExists(names.o_preTreatmentStack_PreTreatmentStack, 3000) test.compare( waitForObjectExists( names.o_PreTreatmentBase_instructionView_InstructionView, 3000 ).title, config.CONCENTRATES_PAGE_TITLE, "Comparison of Concentrates Page Title Text", ) click_text( waitForObjectExists( names.o_PreTreatmentBase_instructionView_InstructionView, 3000 ), config.CONCENTRATES_PAGE_CONTENTS[1], ) click_next() # Installation Stepper wait_compare_text( names.o_preTreatmentStack_Text, config.INSTALLATION_STEPPER_1_PAGE_TITLE, "Installation Page Stepper 1", ) for content in config.INSTALL_BLOOD_TUBING_SET_CONTENTS[1:4]: click_text(None, content) click_auto_load() td_simulator.td_blood_set_auto_load_response(0) wait_compare_text( names.o_preTreatmentStack_Text, config.INSTALLATION_STEPPER_2_PAGE_TITLE, "Installation Page Stepper 2", ) for content in config.INSTALL_BLOODLINES_CONTENTS[1:5]: click_text(None, content) click_next() wait_compare_text( names.o_preTreatmentStack_Text, config.INSTALLATION_STEPPER_3_PAGE_TITLE, "Installation Page Stepper 3", ) for content in config.INSTALL_PRESSURE_LINES_CONTENTS[1:7]: click_text(None, content) click_next() # Self Tests for content in config.SELF_TESTS_PAGE_CONTENTS: obj = waitForObjectExists( utility.setObjectText(names.o_preTreatmentStack_Text, content) ) test.compare( obj.text, content, f"Comparison of Self Tests Page Contents: {content}" ) click_next() # Saline wait_compare_text( names.o_preTreatmentStack_Text, config.SALINE_PAGE_TITLE, "Saline Page Title Text", ) for content in config.SALINE_PAGE_CONTENTS[1:5]: mouseClick(utility.setObjectText(names.o_preTreatmentStack_Text, content)) click_next() # Prime for content in config.PRIME_PAGE_CONTENTS: obj = waitForObjectExists( utility.setObjectText(names.o_preTreatmentStack_Text, content) ) test.compare(obj.text, content, f"Comparison of Prime Page Contents: {content}") click_next() # Create Rx Flow 1 set_treatment_params(50, 50, 60, "0.2", "0.2", 60, 2, 37.0, 2, 100, 6.0, 0) mouseClick( waitForObjectExists(names.o_preTreatmentStack_confirmButton_ConfirmButton, 3000) ) td_simulator.td_Treatment_Parameters_Validation(vAccepted=1) mouseClick( waitForObjectExists(names.o_preTreatmentStack_confirmButton_ConfirmButton, 3000) ) # Connect wait_compare_text( names.o_preTreatmentStack_Text, config.CONNECT_PAGE_TITLE, "Connect Page Title Text", ) for content in config.CONNECT_PAGE_CONTENTS[1:5]: click_text(None, content) verify_start_treatment_request() td_simulator.td_operation_mode(TDOpModes.MODE_INIT.value, 0) # --- Toggle Advanced Mode --- navigation.navigate_to_device_settings_using_service_password() mouseClick( utility.findChildByText( waitForObject(names.o_DeviceSettingsGrid, 2000), config.ADVANCED_MODE ) ) mouseClick(waitForObject(names.o_settingsAdvancedMode_BaseSwitch, 1000)) mouseClick(waitForObjectExists(names.o_SettingsBase_backButton_AdvancedMode, 3000)) # --- Flow 2: Simplified Pre-Treatment --- main_menu_container = waitForObject(names.o_mainMenu_MainMenu, 2000) prescription_menu = waitForObject( utility.findChildByText(main_menu_container, config.PRESCRIPTIONS), 3000 ) mouseClick(prescription_menu) treatment_menu = waitForObject( utility.findChildByText(main_menu_container, config.TREATMENT), 3000 ) mouseClick(treatment_menu) mouseClick(waitForObject(names.o_createTreatmentRect_TouchRect, 3000)) td_simulator.td_operation_mode(TDOpModes.MODE_PRET.value) wait_compare_text( names.o_preTreatmentStack_Text, config.INSTALLATION_PAGE_TITLE, "Installation Page Title Text", ) click_text(None, config.INSTALLATION_PAGE_CONTENTS[1]) click_text(None, config.AUTO_LOAD) td_simulator.td_blood_set_auto_load_response(0) # Self Tests for content in config.SELF_TESTS_PAGE_CONTENTS: obj = waitForObjectExists( utility.setObjectText(names.o_preTreatmentStack_Text, content) ) test.compare( obj.text, content, f"Comparison of Self Tests Page Contents: {content}" ) click_next() # Saline wait_compare_text( names.o_preTreatmentStack_Text, config.SALINE_PAGE_TITLE, "Saline Page Title Text", ) click_next() # Prime for content in config.PRIME_PAGE_CONTENTS: obj = waitForObjectExists( utility.setObjectText(names.o_preTreatmentStack_Text, content) ) test.compare(obj.text, content, f"Comparison of Prime Page Contents: {content}") click_next() # Create Rx Flow 2 set_treatment_params(60, 75, 75, "0.3", "0.3", 60, 2, 38.0, 2, 200, 3.0, 0) mouseClick( waitForObjectExists(names.o_preTreatmentStack_confirmButton_ConfirmButton, 3000) ) td_simulator.td_Treatment_Parameters_Validation(vAccepted=1) mouseClick( waitForObjectExists(names.o_preTreatmentStack_confirmButton_ConfirmButton, 3000) ) wait_compare_text( names.o_preTreatmentStack_Text, config.CONNECT_PAGE_TITLE, "Connect Page Title Text", ) verify_start_treatment_request() test.endSection()