########################################################################### # # 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 builtins import names import os import csv import glob import object import sys import test import time import squish from configuration import config from builtins import int as pyInt def verify_page_step_indicator(screen_obj, post_treatment_step): """ Method to verify the Page Step indicators [the object on top of the screen which indicates the steps passed, current, remained] @param post_treatment_step : (int) indicates the Current post-treatment step """ test.startSection("verification of page step indicators") for page in range(config.NUM_OF_POST_TREATMENT_BULLETS): bullet_children = object.children(squish.waitForObjectExists(get_bullet_object(screen_obj, page))) bullet_circle_color = bullet_children[0].color.name #test.log() bullet_border_color = bullet_children[0].border.color.name step_title = squish.waitForObjectExists(get_text_object(screen_obj, config.POST_TREATMENT_SCREENS[page])) #To verify the step indicators of the completed post treatment screens if page < post_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) #To verify the step indicators of the current post treatment screen elif page == post_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.COLOR) test.compare(step_title.color.name,config.ENABLED_COLOR_ONE) test.verify(step_title.font.bold) #To verify the step indicators of the remaining post 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.COLOR) test.compare(bullet_circle_color,config.CURRENT_COLOR) test.compare(bullet_border_color,config.COLOR) test.endSection() def get_text_object(screen_obj, txt): """ To obtain a text object based on text provided @param screen_obj: provides the container on which the txt must be present @returns a real name object """ 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): """ To obtain a bullet object based on occurrence provided. @param screen_obj: provides the container on which the bullet must be present @param num: provides the occurrence value @returns a real name object """ names.o_bullet_object["container"] = screen_obj names.o_bullet_object["occurrence"] = num + 1 return names.o_bullet_object def get_indicators(screen_obj, txt): """ Verifying the busy indicators for BiCarb Pump Check and Acid Pump Check. indicator object of expected text @param step - (str) expected text @return indicators - (obj) list of busy and check indicator """ parent_obj = object.parent(squish.waitForObjectExists(get_text_object(screen_obj,txt))) children_obj = object.children(parent_obj) indicator_parent = children_obj[2] indicators = object.children(indicator_parent) return indicators 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 and 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 zone if object is hidden @param zone - (obj) UI object @param screen_object - (obj) UI object @return boolean true and 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//2, screenHeight//2, 0, -50, squish.Qt.NoModifier) raise LookupError("zone object is not in view to the user after trying 100 times") def scroll_to_zone(zone=None, screen_object=None, direction = None): """ scroll to the UI, if object is hidden @param zone - object to be find out. @param screen_object - object of the screen. @return boolean """ counter = 0 while counter <= 100: try: counter += 1 squish.snooze(0.5) 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.findObject(screen_object) screenHeight = pyInt(ScreenObj.height) screenWidth = pyInt(ScreenObj.width) if direction is None: squish.mouseWheel(ScreenObj, (screenWidth-100), 107, 0, -(screenHeight-460), squish.Qt.NoModifier) else: squish.mouseWheel(ScreenObj, (screenWidth-100), -(screenHeight-700), 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, time_format="%M:%S"): seconds = builtins.int(seconds) min_and_sec = time.strftime(time_format, time.gmtime(seconds)) return min_and_sec def verify_parameter_from_post_treatment_log(msg_text): try: log_location = str(get_extracted_file()) with open(log_location, 'r') as csv_file: try: for row in csv_file: reader = csv.reader(csv_file) for row in reader: row_length = sum(1 for values in row) for row1 in row: if row[0]!= None and row[0] == msg_text and row_length == 3: return (row[1],row[2]) else: pass except: test.fail("Treatment log data is corrupted") except: test.fail("Log file is not created or log file is not created based on standard log naming format.") def get_extracted_file(): """ This function is the handler for getting file from log folder. This handler will go inside log folder and looks for newly added log based on current time. if it satisfied that condition, it will return the exact path of newly created log. @return latest_file - (string) returns latest file that append on log folder from sd-data """ try: list_of_files = glob.glob(config.TREATMENT_LOG_LOCATION) latest_file = max(list_of_files, key=os.path.getctime) return latest_file except: test.fail("log file is not created during application interaction") return False def get_text_object(screen_obj, txt): """ To obtain a text object based on text provided @param screen_obj: provides the container on which the txt must be present @returns a real name object """ 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): """ To obtain a bullet object based on occurrence provided. @param screen_obj: provides the container on which the bullet must be present @param num: provides the occurrence value @returns a real name object """ names.o_bullet_object["container"] = screen_obj names.o_bullet_object["occurrence"] = num + 1 return names.o_bullet_object def get_indicators(screen_obj, txt): """ Verifying the busy indicators for BiCarb Pump Check and Acid Pump Check. indicator object of expected text @param step - (str) expected text @return indicators - (obj) list of busy and check indicator """ parent_obj = object.parent(squish.waitForObjectExists(get_text_object(screen_obj,txt))) children_obj = object.children(parent_obj) indicator_parent = children_obj[2] indicators = object.children(indicator_parent) return indicators def verify_missing_object(object_to_check): """ Method to verify the given object is invisible or is not present on the screen @param object_to_check: the object whose invisibility must be verified """ try: squish.testSettings.objectNotFoundDebugging = False squish.waitForObject(object_to_check,3000) test.fail("Given object should not be present initially") except LookupError as _: test.passes("object is not present as expected") squish.testSettings.objectNotFoundDebugging = True def verify_page_step_indicator_post_treatment(screen_obj, post_treatment_step): """ Method to verify the Page Step indicators [the object on top of the screen which indicates the steps passed, current, remained] @param post_treatment_step : (int) indicates the Current post-treatment step """ test.startSection("verification of page step indicators") for page in range(len(config.POST_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.POST_TREATMENT_SCREENS[0])) #To verify the step indicators of the completed post-treatment screens if page < post_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 post-treatment screen elif page == post_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) #To verify the step indicators of the remaining post-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_POST_TREATMENT) test.compare(bullet_circle_color,config.CURRENT_COLOR) test.compare(bullet_border_color,config.INCOMPLETE_COLOR) test.endSection()