########################################################################### # # 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) LTTS # @date (last) 15-Jan-2022 # ############################################################################ import object import names import sys import test import squish from builtins import int as pyInt import time from configuration import config from configuration.config import * from dialin.ui.hd_simulator import HDSimulator from dialin.ui.dg_simulator import DGSimulator hd_simulator = HDSimulator() dg_simulator = DGSimulator() def start_application(app_name): """ Function to start application and verify application status [running] If application does not start or running status is false, test stops Argument: @param app_name : (str) - Name of the application @param app_executable : (str) - Actual application @return: handle for the application if the application is in running state, or error (exist the application) """ counter = 0 while True: try: counter += 1 test.log("Starting {}".format(app_name)) squish.startApplication(app_name) if counter == 1: test.log("Application launched at the "+str(counter)+" st try.") elif counter == 2: test.log("Application launched at the "+str(counter)+" nd try.") elif counter == 3: test.log("Application launched at the "+str(counter)+" rd try.") else: test.log("Application launched at the "+str(counter)+" th try.") break except RuntimeError: if counter == 1: test.log("Application failed to launch after "+str(counter)+" try - Please refer logs") elif counter == 20: test.log("Exiting after "+str(counter)+ " tries..") sys.exit(1) else: test.log("Application failed to launch after "+str(counter)+ " tries - Please refer logs") except: logErrorDetails("Failed to start the application") sys.exit(1) 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 convert_seconds_into_min_and_sec(seconds): min_and_sec = time.strftime("%M:%S", time.gmtime(seconds)) return min_and_sec def get_time(screen_title): """ Method to return the current count down in the application @param screen_title - (str) current title of the screen @return time_text - (str) count down in the application """ if screen_title == BEGIN_PRIME_TITLE or screen_title == PRIMING_TITLE: parent_object = object.parent(squish.waitForObjectExists(self_test_dry_check_list_text(screen_title))) elif screen_title == SYSTEM_SELF_TEST_TITLE: parent_object = object.parent(squish.waitForObjectExists(names.o_system_self_test)) else: parent_object = object.parent(squish.waitForObjectExists(names.o_PreTreatmentBase_Filter_Flush_Text)) time_parent_children = object.children(parent_object) progress_circle_parent = time_parent_children[4] progress_circle_parent = object.children(progress_circle_parent) progress_circle_parent = progress_circle_parent[0] progress_circle_parent = object.children(progress_circle_parent) progress_circle_children = object.children(progress_circle_parent[0]) time_text = progress_circle_children[1] return time_text.time def verify_the_countdown(screen_title): """ Method to verify the count down time in application @param screen_title - (str) current title of the screen """ test.startSection("Verify the count down time in application") for count_down in range(MAXIMUM_COUNTDOWN_TIME, MINIMUM_COUNTDOWN_TIME-1, -1): if screen_title == BEGIN_PRIME_TITLE: hd_simulator.cmd_send_pre_treatment_self_test_dry_progress_data(total=300, countdown=count_down) elif screen_title == PRIMING_TITLE: hd_simulator.cmd_send_pre_treatment_disposables_prime_progress_data(timeout=300, countdown=count_down) elif screen_title == SYSTEM_SELF_TEST_TITLE: hd_simulator.cmd_send_pre_treatment_self_test_no_cartridge_progress_data(total=300, countdown=count_down) else: dg_simulator.cmd_send_dg_pre_treatment_filter_flush_progress_data(total=300, countdown=count_down) actual_time = get_time(screen_title) expected_time = convert_seconds_into_min_and_sec(count_down) test.compare(actual_time, expected_time, "Actual count down time: {} should be equal to expected count down time {}".format(actual_time, expected_time)) verify_the_progress(count_down, screen_title) test.endSection() def verify_the_progress(count_down, screen_title): """ Method to verify the current progress @param count_down - (int) current count down time """ test.startSection("Verifying the current progress") if screen_title == BEGIN_PRIME_TITLE or screen_title == PRIMING_TITLE: current_progress = (squish.waitForObjectExists(names.o_self_test_dry_progress)).progressValue elif screen_title == SYSTEM_SELF_TEST_TITLE: current_progress = (squish.waitForObjectExists(names.o_system_self_test_progress)).progressValue else: current_progress = (squish.waitForObjectExists(names.o_filter_flush_progress)).progressValue #Since progress value is equal maximum count down value - current count down value expected_progress = MAXIMUM_COUNTDOWN_TIME - count_down test.compare(current_progress, expected_progress, "{} should be the current progress".format(expected_progress)) test.endSection() def page_step_indicator_verification(screen_obj, pre_treatment_step): """ Method to verify the Page Step indicators [the object on top of the screen which indicates the steps passed, current, remained] @param pre_treatment_step : indicates the Current pre-treatment step """ test.startSection("verification of page step indicators") for page in range(len(config.PRE_TREATMENT_SCREENS)): bullet_children = object.children(squish.waitForObjectExists(get_bullet_object(screen_obj, page))) bullet_circle_color = bullet_children[0].color.name bullet_border_color = bullet_children[0].border.color.name step_title = squish.waitForObjectExists(get_text_object(screen_obj, config.PRE_TREATMENT_SCREENS[page])) #To verify the step indicators of the completed pre treatment screens if page < pre_treatment_step: test.verify(squish.waitForObjectExists(get_bullet_object(screen_obj, page)).complete) test.verify(not squish.waitForObjectExists(get_bullet_object(screen_obj, page)).current) test.compare(bullet_circle_color, config.COMPLETE_COLOR) test.compare(bullet_border_color,config.COMPLETE_COLOR) test.compare(step_title.color.name,config.ENABLED_COLOR) #To verify the step indicators of the current pre treatment screen elif page == pre_treatment_step: test.verify(squish.waitForObjectExists(get_bullet_object(screen_obj, page)).current,) test.verify(not squish.waitForObjectExists(get_bullet_object(screen_obj, page)).complete) test.compare(bullet_circle_color,config.CURRENT_COLOR) test.compare(bullet_border_color,config.COMPLETE_COLOR) test.compare(step_title.color.name,config.ENABLED_COLOR) test.verify(step_title.font.bold) #To verify the step indicators of the remaining pre-treatment screens else: test.verify(not squish.waitForObjectExists(get_bullet_object(screen_obj, page)).current,) test.verify(not squish.waitForObjectExists(get_bullet_object(screen_obj, page)).complete,) test.compare(step_title.color.name,config.INCOMPLETE_COLOR) test.compare(bullet_circle_color,config.CURRENT_COLOR) test.compare(bullet_border_color,config.INCOMPLETE_COLOR) test.endSection() def get_text_object(screen_obj, txt): names.o_text_object["container"] = screen_obj names.o_text_object["text"] = txt return names.o_text_object def get_bullet_object(screen_obj, num): names.o_bullet_object["container"] = screen_obj names.o_bullet_object["occurrence"] = num + 1 return names.o_bullet_object def navigate_to_pretreatment_screen(mode): """ Method to navigate to sub mode under pre-treatment screen @param mode - (int) pre treatment state """ hd_simulator.cmd_set_hd_operation_mode_data(5,0) hd_simulator.cmd_send_pre_treatment_state_data(sub_mode=mode, 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)