# -*- coding: utf-8 -*- ## # Copyright (c) 2019-2020 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_create_patient_ID # date 2022/01/18 # author Joseph varghese # # NOTE: # This test is intended to be used to verify patient id in application. . import names from dialin.ui import utils from dialin.ui.hd_simulator import HDSimulator from configuration import utility, config def keyboard_object_map_helper(text): """ Method for setting custom object property's for keyboard keys @return: required object property's for keys """ if text is not None: names.o_keboard_input["text"] = text return names.o_keboard_input else: test.log("Invalid ",text," for object.") names.o_keyboard_input["text"] = "Q" def keyboard_switching_section(text): """ Tests to automate keyboard based on user input @return: key text (text displayed on keyboard) """ keyboard_value = keyboard_object_map_helper(text) object_status = object.exists(keyboard_value) if object_status is True: return text else: #Tests to get status of keys in keyboard layout object_status = object.exists(keyboard_object_map_helper(config.KEYBOARD_SWITCH[1])) if object_status is True: keyboard_value = keyboard_object_map_helper(config.KEYBOARD_SWITCH[1]) utils.waitForGUI(.3) mouseClick(waitForObject(keyboard_value)) keyboard_value = keyboard_object_map_helper(text) object_status = object.exists(keyboard_value) if object_status is True: return text object_status = object.exists(keyboard_object_map_helper(config.KEYBOARD_SWITCH[0])) if object_status is True: keyboard_value = keyboard_object_map_helper(config.KEYBOARD_SWITCH[0]) mouseClick(waitForObject(keyboard_value)) keyboard_value = keyboard_object_map_helper(text) object_status = object.exists(keyboard_value) if object_status is True: return text object_status = object.exists(names.o_keyboard_switch2) if object_status is True: keyboard_value = waitForObject(names.o_keyboard_switch2) mouseClick(keyboard_value) text = text.lower() keyboard_value = keyboard_object_map_helper(text) object_status = object.exists(keyboard_value) if object_status is True: return text object_status = object.exists(names.o_keyboard_switch) if object_status is True: keyboard_value = waitForObject(names.o_keyboard_switch) mouseClick(keyboard_value) text = text.lower() keyboard_value = keyboard_object_map_helper(text) object_status = object.exists(keyboard_value) if object_status is True: return text def user_input_clear_option(): """ Tests to clear retained patient id @return: N/A """ patient_id_input = waitForObject(names.o_input_patient_id) patient_id = str(patient_id_input.text) patient_id_length = len(patient_id) while (patient_id_length != 0): type(waitForObject(names.o_input_patient_id), "") type(waitForObject(names.o_input_patient_id), "") patient_id_length = patient_id_length - 1 def verify_valid_patient_id_through_keypad(expected_value, actual_value): """ Tests verifies valid patient id set through application keyboard setup . @return: N/A """ patient_id_input = waitForObject(names.o_input_patient_id) mouseClick(patient_id_input) for text in expected_value: keyword_state = keyboard_switching_section(text) if keyword_state is not None: keyboard_value = keyboard_object_map_helper(keyword_state) mouseClick(waitForObject(keyboard_value)) utils.waitForGUI(.2) test.compare(actual_value, (patient_id_input.text), "Patient id should be -> "+ str(actual_value)) verify_continue_button_based_on_patient_id(expected_value) mouseClick(waitForObject(names.o_continue_text_button)) custom_treatment = waitForObject(names.o_custom_treatment) test.compare("Create a Custom Treatment", custom_treatment.text) test.log("User successfully authenticated through patient id -> " + expected_value + "using keypad.") mouseClick(waitForObject(names.o_create_back_button)) def verify_valid_patient_id_through_user_input(expected_value, actual_value): """ Tests verifies valid patient id set through user's input. @return: N/A """ patient_id_input = waitForObject(names.o_input_patient_id) mouseClick(waitForObject(patient_id_input)) type(waitForObject(names.o_input_patient_id), expected_value) test.compare(actual_value, (patient_id_input.text)) test.log("Patient id should be ->" + expected_value) verify_continue_button_based_on_patient_id(expected_value) mouseClick(waitForObject(names.o_PreTreatmentBase_confirmButton_TouchRect_2)) custom_treatment = waitForObject(names.o_custom_treatment) test.compare("Create a Custom Treatment", custom_treatment.text) test.log("User successfully authenticated through patient id ->"+ actual_value) mouseClick(waitForObject(names.o_create_back_button)) def verify_continue_button_based_on_patient_id(patient_id): """ Tests verifies skip and continue button based on patient id. @input : patient id to be set @return: N/A """ utils.waitForGUI(1) if patient_id is None: mouseClick( waitForObject(names.o_input_patient_id)) type( waitForObject(names.o_input_patient_id), " ") skip_button_status = findObject(names.o_skip_text_button) if skip_button_status.enabled == True: test.passes("Skip button enabled without patient id") else: continue_button_status = waitForObject(names.o_PreTreatmentBase_confirmButton_TouchRect_2) if continue_button_status.enabled == True: test.passes("Continue button enabled with patient id -> " + str(patient_id)) else: test.fail("Continue button disabled with patient id -> " + str(patient_id)) def verify_invalid_patient_id_through_user_input(expected_value): """ Tests verifies invalid patient id set through user's input. @return: N/A """ patient_id_input = waitForObject(names.o_input_patient_id) mouseClick(patient_id_input) type(waitForObject(names.o_input_patient_id), expected_value) if expected_value is not patient_id_input.text or patient_id_input.text is None: test.passes("Patient ID -> ", expected_value, " should be invalid") else: #None patient id is accepting in application "space is accepting" - development stage test.xfail("Patient ID" ,expected_value," is valid") user_input_clear_option() def main(): utils.tstStart(__file__) startApplication(config.AUT_NAME) hd = HDSimulator() hd.cmd_send_hd_operation_mode(4, 0) utils.waitForGUI(1) mouseClick(waitForObject(names.o_PreTreatmentBase_confirmButton_TouchRect_2)) utils.waitForGUI(0.2) mouseClick(waitForObject(names.o_PreTreatmentCreate_backButton_BackButton)) utils.waitForGUI(0.2) mouseClick(waitForObject(names.o_PreTreatmentPatientid_back_button)) hd.cmd_send_hd_operation_mode(4, 0) utils.waitForGUI(1) mouseClick(waitForObject(names.o_input_patient_id)) for expected_patient_id, actual_patient_id in config.PATIENT_ID_COMBINATION.items(): verify_valid_patient_id_through_keypad(expected_patient_id, actual_patient_id) mouseClick(waitForObject(names.o_PreTreatmentPatientid_back_button)) verify_valid_patient_id_through_user_input(expected_patient_id, actual_patient_id) #verification of continue button without giving patient id verify_continue_button_based_on_patient_id(patient_id = None) utils.tstDone()