########################################################################### # # Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. # # 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 utils.py # # @author (last) Joseph varghese # @date (last) 15-Jan-2022 # ############################################################################ import names import sys import test import object import squish from configuration import config from builtins import int as pyInt from builtins import str as pyStr from dialin.ui import utils def check_if_object_is_within_the_container(obj=None, container=None): """ check if an object is inside a container @param obj - child UI object @param container - container UI object @return boolean true/false """ container = squish.findObject(container) containerPos = container.mapToGlobal(squish.QPoint(0, 0)) container_x, container_y = pyInt(containerPos.x), pyInt(containerPos.y) container_width, container_height = pyInt(container.width), pyInt(container.height) obj = squish.findObject(obj) objPos = obj.mapToGlobal(squish.QPoint(0, 0)) obj_x, obj_y = pyInt(objPos.x), pyInt(objPos.y) obj_width, obj_height = pyInt(obj.width), pyInt(obj.height) if obj_x >= container_x and obj_y >= container_y: if (obj_x + obj_width) <= (container_x + container_width) and (obj_y + obj_height) <= (container_y + container_height): return True return False def scroll_to_zone(zone=None, screen_object=None): """ scroll to the numeric if object is hidden @param zone - UI object @param screen_object - UI object (UI Home screen = waveforms + numerics) @return boolean true/false """ counter = 0 while counter <= 100: try: counter += 1 squish.findObject(zone) squish.snooze(0.5) if check_if_object_is_within_the_container(obj=zone, container=screen_object): return True else: raise RuntimeError except RuntimeError: ScreenObj = squish.waitForObject(screen_object) screenHeight = pyInt(ScreenObj.height) screenWidth = pyInt(ScreenObj.width) squish.mouseWheel(ScreenObj, screenWidth-1000, screenHeight-10, 0, -50, squish.Qt.NoModifier) raise LookupError("zone object is not in view to the user after " + \ "trying 100 times") def page_step_indicator_verification(pre_treatment_step, pre_treatment_items_object): """ Method to verify the Page Step indicators on top of the screen which indicates the steps passed, current, remained] @param pre_treatment_step :(int) indicates the Current pre-treatment step @param pre_treatment_items_object :(dictionary) pre_treatment bullet object @return N/A """ test.startSection("Method to verify the Page Step indicators from patient connection section") for page in range(1, len(config.PRE_TREATMENT_SCREENS)): pre_treatment_items_object["occurrence"] = page bullet_children = object.children(squish.waitForObject(pre_treatment_items_object)) bullet_circle_color = bullet_children[0].color.name bullet_border_color = bullet_children[0].border.color.name step_title = bullet_children[2] #To verify the step indicators of the completed pre treatment screens if page < pre_treatment_step: test.verify(squish.waitForObjectExists(pre_treatment_items_object).complete, str(config.PRE_TREATMENT_SCREENS[page]+" complete attribute should be True")) test.verify(not squish.waitForObjectExists(pre_treatment_items_object).current, str(config.PRE_TREATMENT_SCREENS[page]+" current attribute should be false")) test.compare(bullet_circle_color, config.COMPLETE_COLOR, str(config.PRE_TREATMENT_SCREENS[page]+" bullet color hex should be "+str(config.COMPLETE_COLOR))) test.compare(bullet_border_color, config.COMPLETE_COLOR, str(config.PRE_TREATMENT_SCREENS[page]+" bullet border color hex should be "+str(config.COMPLETE_COLOR))) test.compare(step_title.color.name, config.ENABLED_COLOR, str(config.PRE_TREATMENT_SCREENS[page]+" title color hex should be "+str(config.ENABLED_COLOR))) #To verify the step indicators of the current pre treatment screen elif page == pre_treatment_step: test.verify(squish.waitForObjectExists(pre_treatment_items_object).current, str(config.PRE_TREATMENT_SCREENS[page]+" complete attribute should be True")) test.verify(not squish.waitForObjectExists(pre_treatment_items_object).complete, str(config.PRE_TREATMENT_SCREENS[page]+" current attribute should be false")) test.compare(bullet_circle_color,config.CURRENT_COLOR, str(config.PRE_TREATMENT_SCREENS[page]+" bullet color hex should be "+str(config.CURRENT_COLOR))) test.compare(bullet_border_color,config.COMPLETE_COLOR, str(config.PRE_TREATMENT_SCREENS[page]+" bullet border color hex should be "+str(config.COMPLETE_COLOR))) test.compare(step_title.color.name,config.ENABLED_COLOR, str(config.PRE_TREATMENT_SCREENS[page]+" title color hex should be "+str(config.ENABLED_COLOR))) test.verify(step_title.font.bold, str(config.PRE_TREATMENT_SCREENS[page]+" title font bold should be "+str(config.ENABLED_COLOR))) #To verify the step indicators of the remaining pre-treatment screens else: test.verify(not squish.waitForObjectExists(pre_treatment_items_object).current, str(config.PRE_TREATMENT_SCREENS[page]+" complete attribute should be false")) test.verify(not squish.waitForObjectExists(pre_treatment_items_object).complete, str(config.PRE_TREATMENT_SCREENS[page]+" current attribute should be false")) test.compare(step_title.color.name,config.INCOMPLETE_COLOR, str(config.PRE_TREATMENT_SCREENS[page]+" title color hex should be "+str(config.INCOMPLETE_COLOR))) test.compare(bullet_circle_color,config.CURRENT_COLOR, str(config.PRE_TREATMENT_SCREENS[page]+" bullet circle color hex should be "+str(config.CURRENT_COLOR))) test.compare(bullet_border_color,config.INCOMPLETE_COLOR, str(config.PRE_TREATMENT_SCREENS[page]+" bullet border color hex should be "+str(config.INCOMPLETE_COLOR))) test.endSection() def instruction_screen_indicator_verification(current_indicator, training_items_object): """ Method to verify the pre treatment tutorial indicators on top of the screen which indicates the steps passed, current, remained] @param current_indicator :(int) Current pre-treatment tutorial indicator @param training_items_object :(dictionary) pre_treatment bullet object @return N/A """ test.startSection("Method to verify the Page Step indicators from training screen") for page in range(config.TRAINING_INDICATOR_SCREEN): occurrence_index = 10 + page #1-9 occurrence of object belongs to page indicators, 10 - 13 occurrence of object belongs to training indicators training_items_object["occurrence"] = occurrence_index bullet_children = object.children(squish.waitForObject(training_items_object)) bullet_circle_color = bullet_children[0].color.name bullet_border_color = bullet_children[0].border.color.name #To verify the step indicators of pre treatment tutorial screens if page < current_indicator: test.verify(squish.waitForObjectExists(training_items_object).complete, "bullet indicator {index} should be in complete state".format(index=current_indicator)) test.verify(not squish.waitForObjectExists(training_items_object).current, "bullet indicator {index} current attribute should be unchecked".format(index=current_indicator)) test.compare(bullet_circle_color, config.COMPLETE_COLOR, " bullet color hex should be "+str(config.COMPLETE_COLOR)) test.compare(bullet_border_color, config.COMPLETE_COLOR, " bullet border color hex should be "+str(config.COMPLETE_COLOR)) #To verify the step indicators of pre treatment tutorial screen elif page == current_indicator: test.verify(squish.waitForObjectExists(training_items_object).current, "bullet indicator {index} should be in complete state".format(index=current_indicator)) test.verify(not squish.waitForObjectExists(training_items_object).complete, "bullet indicator {index} current attribute should be unchecked".format(index=current_indicator)) test.compare(bullet_circle_color,config.COMPLETE_COLOR, "bullet color hex should be "+str(config.CURRENT_COLOR)) test.compare(bullet_border_color,config.COMPLETE_COLOR, "bullet border color hex should be "+str(config.COMPLETE_COLOR)) #To verify the step indicators of pre-treatment tutorial screens else: test.verify(not squish.waitForObjectExists(training_items_object).current, "bullet indicator {index} should not be complete state".format(index=current_indicator)) test.verify(not squish.waitForObjectExists(training_items_object).complete, "bullet indicator {index} current attribute should be unchecked".format(index=current_indicator)) test.compare(bullet_circle_color,config.CURRENT_COLOR, "bullet circle color hex should be "+str(config.CURRENT_COLOR)) test.compare(bullet_border_color,config.INCOMPLETE_COLOR, "bullet border color hex should be "+str(config.INCOMPLETE_COLOR)) test.endSection() def verify_color_of_entry(entry = 0, vital_parameter = None, input_field = None): """ Method to verify the color of entry of systolic, diastolic and heart rate @param entry: (int) user entered value @param vital_parameter - (str) parameter name under which user is entering value (sys/dia/heart rate) @param input_field - (obj) object of input field """ test.startSection("Verify the color of {} value {}".format(vital_parameter, entry)) input_field_color = input_field.color.name entry = pyInt(entry) if vital_parameter is config.SYSTOLIC_TEXT: if (entry < config.SYSTOLIC_LOWER_LIMIT) or (entry > config.SYSTOLIC_UPPER_LIMIT): test.compare(input_field_color, config.OUT_OF_RANGE_COLOR, "systolic value {} is out of range, systolic value should be in range of {} and {}".format(entry, config.SYSTOLIC_LOWER_LIMIT, config.SYSTOLIC_UPPER_LIMIT)) elif (entry >= config.SYSTOLIC_LOWER_LIMIT) and (entry <= config.SYSTOLIC_UPPER_LIMIT): test.compare(input_field_color, config.ENABLED_COLOR, "systolic value {} is in range of {} and {}".format(entry, config.SYSTOLIC_LOWER_LIMIT, config.SYSTOLIC_UPPER_LIMIT)) elif vital_parameter is config.DIASTOLIC_TEXT: if (entry < config.DIASTOLIC_LOWER_LIMIT) or (entry > config.DIASTOLIC_UPPER_LIMIT): test.compare(input_field_color, config.OUT_OF_RANGE_COLOR, "diastolic value {} is out of range, diastolic value should be in range of {} and {}".format(entry, config.DIASTOLIC_LOWER_LIMIT, config.DIASTOLIC_UPPER_LIMIT)) elif (entry >= config.DIASTOLIC_LOWER_LIMIT) and (entry <= config.DIASTOLIC_UPPER_LIMIT): test.compare(input_field_color, config.ENABLED_COLOR, "diastolic value {} is in range of {} and {}".format(entry, config.DIASTOLIC_LOWER_LIMIT, config.DIASTOLIC_UPPER_LIMIT)) elif vital_parameter is config.HEART_RATE_TITLE: if (entry < config.HEART_RATE_LOWER_LIMIT) or (entry > config.HEART_RATE_UPPER_LIMIT): test.compare(input_field_color, config.OUT_OF_RANGE_COLOR, "Heart Rate value {} is out of range, Heart Rate value should be in range of {} and {}".format(entry, config.HEART_RATE_LOWER_LIMIT, config.HEART_RATE_UPPER_LIMIT)) elif (entry >= config.HEART_RATE_LOWER_LIMIT) and (entry <= config.HEART_RATE_UPPER_LIMIT): test.compare(input_field_color,config.ENABLED_COLOR, "Heart Rate value {} is in range of {} and {}".format(entry, config.HEART_RATE_LOWER_LIMIT, config.HEART_RATE_UPPER_LIMIT)) test.endSection() def keypad_input(key_value): """ Method to enter values using application UI keyboard @param key_value: (str) User expected value """ if key_value is not None: names.o_keypad_input["text"] = key_value return names.o_keypad_input else: test.log("Invalid text for object.") names.o_keypad_input["text"] = None def enter_keypad_value(entry): """ Method to enter user desired value using keypad @param entry: (str) User expected value """ test.startSection("Entering {}".format(entry)) entry = pyStr(entry) #type casted into string format for value in entry: squish.mouseClick(squish.waitForObject(keypad_input(value))) test.endSection() def erase_entered_value(input_field): """ Method to erase the entered value @param input_field - (obj) object of input field """ test.startSection("Erasing value") input_field= squish.waitForObject(input_field) entered_value = str(input_field.text) for value in range(len(entered_value)+1): utils.waitForGUI(1) squish.mouseClick(squish.waitForObjectExists(names.o_back_space_key)) test.compare(str(input_field.text), "", "Input field should be empty") test.endSection()