# -*- coding: utf-8 -*-" import names import os from dialin.ui import utils from dialin.ui.hd_simulator import HDSimulator from configuration import config from configuration import utility from dialin.common.hd_defs import HDOpModes, HDOpSubModes, PreTreatmentSubModes, PreTreatmentSampleWaterStates, PreTreatmentConsumableSelfTestStates, PreTreatmentNoCartSelfTestsStates, PreTreatmentCartridgeInstallStates, PreTreatmentDrySelfTestsStates, PreTreatmentPrimeStates, PreTreatmentRecircStates, PreTreatmentPatientConnectionStates from dialin.ui.utils import waitForGUI hd_simulator = HDSimulator() contents = [] instructions = [] image_names = [] title_list = [] count_of_instructions = [] title_count_dict = {} conf_dict = {} text_obj_names = [names.o_PreTreatmentBase_swipeview_SwipeView,names.o_PreTreatmentBase_swipeview_SwipeView_2,names.o_preTreatmentDisposablesCartridgeInstallation_swipeview_SwipeView,names.o_preTreatmentDisposablesCartridgeConnetion_swipeview_SwipeView,names.o_preTreatmentDisposablesSalineBag_swipeview_SwipeView,names.o_PreTreatmentBase_swipeview_SwipeView_3] rightarrow_obj_names = [names.o_preTreatmentConsumablesStack_PreTreatmentBase_TreatmentFlowBase,names.o_preTreatmentDisposablesStack_preTreatmentDisposablesCartridgeInstallation_TreatmentFlowBase,names.o_preTreatmentDisposablesStack_preTreatmentDisposablesCartridgeConnetion_TreatmentFlowBase,names.o_pretreatmentConnectionStack_PreTreatmentBase_TreatmentFlowBase] def get_text_obj(screen_obj,text): """ To obtain a text object based on text provided @param (str) screen_obj: provides the container name on which the text must be present @param (str) text: instruction text @returns a real name object """ names.o_instruction["container"] = screen_obj names.o_instruction["text"] = text return names.o_instruction def get_rightarrow_obj(screen_obj): """ To obtain object for right arrow based on container @param (str) screen_obj: provides the container @returns a real name object """ names.o_right_arrow["container"] = screen_obj return names.o_right_arrow def get_img_obj(screen_obj,source): """ To obtain image object based on container @param (str) screen_obj: provides the container @param (str) source: image source @returns a real name object """ names.o_image_path["container"] = screen_obj names.o_image_path["source"] = source return names.o_image_path def read_data_from_conf_file(): """ This method is used to read the data from Instructions.conf file. """ utils.waitForGUI(0.2) with open(utility.INSTRUCTION_CONF_LOCATION, 'r') as conf_file: contents = conf_file.readlines() count = 0 line_count = 0 for line in contents: length =len(line) line_count += 1 if line[0] =="[": title = line.split("^") title_strip = title[1][:-2] title_list.append(title_strip) continue else: conf_data = line.split("=") if length <= 2: if count > 0: count_of_instructions.append(count) count = 0 if length > 2: count += 1 conf_dict.update([(conf_data[1],conf_data[0])]) instructions.append(conf_dict.get(conf_data[1])) image_names.append(conf_data[1].strip()) if line_count == len(contents): count_of_instructions.append(count) title_count_dict.update(dict(zip(title_list,count_of_instructions))) def verify_instruction_and_image(title,index): """ This method is used to verify the instruction and image on present screen @param - (str) title: screen title @param - (int) index: index of data from Instructions.conf file """ test.startSection("Verifying instruction and image from " +title+ " screen") for i in range((title_count_dict.get(title))): instruction_text = instructions[index] image_text = image_names[index] # test.log(str(instruction_text)) instruction_text = instruction_text.replace('\\n','\n') # test.log(str(instruction_text)) index += 1 # test.log(str(index)) if instruction_text[-1] == " ": instruction_text = instruction_text.rstrip() # test.log(str(instruction_text)) image_source = waitForObjectExists(get_img_obj(text_obj_names[0],"{}{}".format(config.IMAGE_LOCATION, image_text))).source.path test.compare(str(waitForObject(get_text_obj(text_obj_names[0],instruction_text)).text),instruction_text, "Instruction from " +title+ " screen is visible and matched") test.compare(str(image_source),"{}{}".format(config.EXPECTED_IMAGE_LOCATION, image_text), "Image from " +title+ " screen is visible and matched") if object.exists(names.o_next_button): mouseClick(waitForObject(names.o_next_button)) if object.exists(names.o_fail_button): mouseClick(waitForObject(names.o_fail_button)) if object.exists(get_rightarrow_obj(rightarrow_obj_names[0])): mouseClick(waitForObject(get_rightarrow_obj(rightarrow_obj_names[0]))) test.endSection() return index def main(): utils.tstStart(__file__) startApplication(config.AUT_NAME) read_data_from_conf_file() hd_simulator.cmd_set_hd_operation_mode_data(HDOpModes.MODE_PRET.value,PreTreatmentSampleWaterStates.SAMPLE_WATER_SETUP_STATE.value) test.startSection("Navigating to Pre-Treatment Sample screen") hd_simulator.cmd_send_pre_treatment_state_data(sub_mode=HDOpSubModes.SUBMODE_WAIT_FOR_TREATMENT.value, water_sample_state=PreTreatmentSampleWaterStates.SAMPLE_WATER_STATE.value,consumables_self_test_state=PreTreatmentConsumableSelfTestStates.CONSUMABLE_SELF_TESTS_INSTALL_STATE.value, no_cartridge_self_test_state=PreTreatmentNoCartSelfTestsStates.NO_CART_SELF_TESTS_START_STATE.value,installation_state=PreTreatmentCartridgeInstallStates.CARTRIDGE_INSTALL_STATE.value, dry_self_test_state=PreTreatmentDrySelfTestsStates.DRY_SELF_TESTS_START_STATE.value, prime_state=PreTreatmentPrimeStates.HD_PRIME_START_STATE.value,recirculate_state=PreTreatmentRecircStates.PRE_TREATMENT_RECIRC_STATE.value, patient_connection_state=PreTreatmentPatientConnectionStates.PATIENT_CONNECTION_STATE.value) index = verify_instruction_and_image("Water Sample",index = 0) index = verify_instruction_and_image("Water Sample Result",index = index) index = verify_instruction_and_image("Water Sample Result Failed",index = index) test.endSection() test.startSection("Navigating to Pre-Treatment Consumables screen") hd_simulator.cmd_send_pre_treatment_state_data(sub_mode=HDOpSubModes.SUBMODE_WAIT_FOR_DISINFECT.value, water_sample_state=PreTreatmentSampleWaterStates.SAMPLE_WATER_SETUP_STATE.value,consumables_self_test_state=PreTreatmentConsumableSelfTestStates.CONSUMABLE_SELF_TESTS_INSTALL_STATE.value, no_cartridge_self_test_state=PreTreatmentNoCartSelfTestsStates.NO_CART_SELF_TESTS_START_STATE.value,installation_state=PreTreatmentCartridgeInstallStates.CARTRIDGE_INSTALL_STATE.value, dry_self_test_state=PreTreatmentDrySelfTestsStates.DRY_SELF_TESTS_START_STATE.value, prime_state=PreTreatmentPrimeStates.HD_PRIME_START_STATE.value,recirculate_state=PreTreatmentRecircStates.PRE_TREATMENT_RECIRC_STATE.value, patient_connection_state=PreTreatmentPatientConnectionStates.PATIENT_CONNECTION_STATE.value) text_obj_names.pop(0) index = verify_instruction_and_image("Consumables Installation",index = index) rightarrow_obj_names.pop(0) test.endSection() test.startSection("Navigating to Pre-Treatment Disposables screen") hd_simulator.cmd_send_pre_treatment_state_data(sub_mode=HDOpSubModes.SUBMODE_DG_HEAT_DISINFECT_IN_PROGRESS.value, water_sample_state=PreTreatmentSampleWaterStates.SAMPLE_WATER_SETUP_STATE.value, consumables_self_test_state=PreTreatmentConsumableSelfTestStates.CONSUMABLE_SELF_TESTS_INSTALL_STATE.value, no_cartridge_self_test_state=PreTreatmentNoCartSelfTestsStates.NO_CART_SELF_TESTS_START_STATE.value, installation_state=PreTreatmentCartridgeInstallStates.CARTRIDGE_INSTALL_STATE.value, dry_self_test_state=PreTreatmentDrySelfTestsStates.DRY_SELF_TESTS_START_STATE.value, prime_state=PreTreatmentPrimeStates.HD_PRIME_START_STATE.value, recirculate_state=PreTreatmentRecircStates.PRE_TREATMENT_RECIRC_STATE.value, patient_connection_state=PreTreatmentPatientConnectionStates.PATIENT_CONNECTION_STATE.value) text_obj_names.pop(0) index = verify_instruction_and_image("Cartridge Installation",index = index) text_obj_names.pop(0) rightarrow_obj_names.pop(0) test.log("Clicking on next button in Cartridge Installation instruction page") mouseClick(waitForObjectExists(names.o_next_button_cartridge_installation)) index = verify_instruction_and_image("Cartridge Connection",index = index) text_obj_names.pop(0) test.log("Clicking on next button in Cartridge Connection instruction page") mouseClick(waitForObjectExists(names.o_next_button_cartridge_connection)) index = verify_instruction_and_image("Saline Bag",index = 18) text_obj_names.pop(0) rightarrow_obj_names.pop(0) test.endSection() test.log("Navigating to Pre-Treatment Ultrafiltration screen") hd_simulator.cmd_send_pre_treatment_state_data(sub_mode=PreTreatmentSubModes.HD_PRE_TREATMENT_PATIENT_CONNECTION_STATE.value, water_sample_state=0, consumables_self_test_state=0,no_cartridge_self_test_state=0, installation_state=0, dry_self_test_state=0, prime_state=0, recirculate_state=0, patient_connection_state=0) hd_simulator.cmd_send_pre_treatment_continue_to_treament_response(accepted=True, reason=0) hd_simulator.cmd_send_uf_treatment_response(accepted = True, reason = 0, volume = 120) test.log("Clicking on skip button in BP/HR screen") mouseClick(waitForObject(names.o_skip_button)) test.startSection("Navigating to Pre-Treatment Patient Connection screen") index = verify_instruction_and_image("Patient Connection",index = index) test.endSection() test.startSection("Navigating to Pre-Treatment Start screen") hd_simulator.cmd_send_pre_treatment_patient_connection_confirm_response(accepted=True, reason=0) index = verify_instruction_and_image("Start Treatment",index = index) test.endSection() utils.tstDone()