# -*- 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, 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 = {} obj_names = [names.o_PreTreatmentBase_swipeview_SwipeView,names.o_PreTreatmentBase_swipeview_SwipeView_2] def get_text_obj(screen_obj,text): """ To obtain a text object based on text provided @param obj_name: provides the object name on which the text must be present @returns a real name object """ names.o_instruction["container"] = screen_obj names.o_instruction["text"] = text return names.o_instruction 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))) # return instructions def verify_instruction(title,index): """ This method is used to verify the instructions from water sample screen @param - (str) list of instructions from Instruction.conf file """ # test.startSection("Verify the instructions from water sample screen") # test.log(str(instructions)) for i in range((title_count_dict.get(title))): instruction_text = instructions[index] 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)) test.compare(str(waitForObject(get_text_obj(obj_names[0],instruction_text)).text),instruction_text, "Instruction from water sample screen should be 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)) return index # test.endSection() def verify_image_title_water_sample(image_names): """ This method is used to verify all the image titles from Instructions.conf file. """ test.startSection("Verify all the image titles from Instructions.conf file") image_titles = os.listdir(utility.IMAGE_FILE_LOCATION) image_names = list(set(image_names)) for image in image_names: if image in image_titles: test.passes("Image "+ str(image) +" is present at given file location") else: test.fail("Image "+ str(image) +" is not present at given file location") test.endSection() def main(): utils.tstStart(__file__) startApplication(config.AUT_NAME) hd_simulator.cmd_set_hd_operation_mode_data(HDOpModes.MODE_PRET.value,PreTreatmentSampleWaterStates.SAMPLE_WATER_SETUP_STATE.value) 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) read_data_from_conf_file() index = verify_instruction("Water Sample",index = 0) index = verify_instruction("Water Sample Result",index = index) index = verify_instruction("Water Sample Result Failed",index = index) hd_simulator.cmd_set_hd_operation_mode_data(HDOpModes.MODE_PRET.value,PreTreatmentConsumableSelfTestStates.CONSUMABLE_SELF_TESTS_INSTALL_STATE.value) 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) test.log(str(obj_names[0])) obj_names.pop(0) test.log(str(obj_names[0])) index = verify_instruction("Consumables Installation",index = index) # verify_image_title_water_sample(image_names) utils.tstDone()