########################################################################### # # 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 pytz import squish import sys import test from configuration import config from dialin.ui import utils from builtins import int as pyInt from datetime import datetime def check_if_object_is_within_the_container(obj=None, container=None): """ check if an object is inside a container @param obj - (obj) child UI object @param container - (obj) container UI object @return boolean true/false """ container = squish.findObject(container) containerPos = container.mapToGlobal(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(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, Qt.NoModifier) raise LookupError("zone object is not in view to the user after " + \ "trying 100 times") def get_current_date_and_time(): date_format='%Y/%b/%d - %H:%M' date = datetime.now() device_timezone=pytz.timezone('US/Pacific') date = device_timezone.localize(date) date = date.astimezone(device_timezone) return str(date.strftime(date_format)) def enter_keypad_value(entry): """ Method to enter user desired value using keypad @param entry: (str) User expected value """ test.startSection("Enter {}".format(entry)) for value in entry: value = builtins.int(value) key_val = squish.waitForObject(names.keypad_input(key_value=value)) squish.mouseClick(key_val) utils.waitForGUI(1) 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 = input_field.text.toUtf8().constData() for value in entered_value: utils.waitForGUI(1) squish.mouseClick(squish.waitForObjectExists(names.o_back_space_key)) test.compare(input_field.text.toUtf8().constData(), "", "Input field should be empty") test.endSection()