########################################################################### # # 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 os import names import squish import shutil import test import csv from dialin.ui import utils from builtins import str as pyStr from builtins import int as pyInt 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 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 keyboard_input(key_value): names.o_keyboard_object["text"] = key_value return names.o_keyboard_object def enter_keyboard_numeric_value(entry): """ Method to enter user desired value using keypad @param entry: (str) User expected value """ test.startSection("Entering {}".format(entry)) for value in entry: if value.isalpha(): value = pyStr(value) else: value = pyInt(value) key_val = squish.waitForObject(keyboard_input(value)) squish.mouseClick(key_val) utils.waitForGUI(0.1) test.endSection() def rename_file(path,filename): """ This method Rename the original folder name to dummy name. """ folder_path = os.listdir(path) for files in folder_path: if files == filename+"_1": if os.path.exists(path+filename+"_1"): shutil.rmtree(path+filename+"_1") test.log(str(filename+" name changed to "+files)) if files == filename: if os.path.exists(path+filename): utils.waitForGUI(1) os.rename(path+filename,path+filename+"_1") test.log(str(files+" name changed to "+filename+"_1")) def rename_old_name(path,filename): """ This method Rename the dummy name to original folder name . """ folder_path = os.listdir(path) for files in folder_path: if files == filename: if os.path.exists(path+filename): shutil.rmtree(path+filename) test.log(str(files+"_1 name changed to "+filename)) utils.waitForGUI(5) if files != filename: if (files == filename+"_1"): os.rename(path+files,path+filename) test.log(str(files+" name changed to "+filename)) def scroll_to_zone(zone=None, screen_object=None, direction = None): """ scroll to the to the value if object is hidden @param value - (obj) value object @param container - (obj) Container of the value @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.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, 200, squish.Qt.NoModifier) raise LookupError("zone object is not in view to the user after trying 100 times")