Vladimir Druzhinin b09504be36
Test(pytest) start aut (#11482)
* test(pytest) The driver methods added. Wrappers for UI elements added.

#67

* test(pytest) Squishserver added

#68

* test(pytest) Attach/Detach AUT methods added

#69

* test(pytest) Main window handler added

#70

* test(pytest) Save screenshot on fail added

#71

* test(pytest) Wait for squishserver added

#71

* test(pytest) Setup Windows

#71

* Generate new keys (#11804)

* test(pytest) Image comparison methods added

#76

* test(pytest) Tesseract methods added

#77

* test(pytest) The Methods to search color on image added

#80

* test(onboarding) Test on generation new keys added

#75

* test(pytest) Handlers for OS Native File dialog added

#81

* test(Onboarding) Test on Profile image added

#83

* Allure and TestRail integration (#11806)

* test(Allure) Steps descriptions added

#72

* test(TestRail) Integration

#72
2023-08-04 20:27:03 +02:00

119 lines
2.9 KiB
Python

import logging
import time
import allure
import configs
import driver
from gui.elements.base_object import BaseObject
from scripts.tools.image import Image
_logger = logging.getLogger(__name__)
class QObject(BaseObject):
def __init__(self, name: str):
super().__init__(name)
self._image = Image(self.real_name)
def __str__(self):
return f'{type(self).__qualname__}({self.symbolic_name})'
@property
@allure.step('Get object {0}')
def object(self):
return driver.waitForObject(self.real_name, configs.timeouts.UI_LOAD_TIMEOUT_MSEC)
@property
@allure.step('Get object exists {0}')
def exists(self) -> bool:
return driver.object.exists(self.real_name)
@property
@allure.step('Get bounds {0}')
def bounds(self):
return driver.object.globalBounds(self.object)
@property
@allure.step('Get "x" coordinate {0}')
def x(self) -> int:
return self.bounds.x
@property
@allure.step('Get "y" coordinate {0}')
def y(self) -> int:
return self.bounds.y
@property
@allure.step('Get width {0}')
def width(self) -> int:
return int(self.bounds.width)
@property
@allure.step('Get height {0}')
def height(self) -> int:
return int(self.bounds.height)
@property
@allure.step('Get central coordinate {0}')
def center(self):
return self.bounds.center()
@property
@allure.step('Get enabled {0}')
def is_enabled(self) -> bool:
return self.object.enabled
@property
@allure.step('Get selected {0}')
def is_selected(self) -> bool:
return self.object.selected
@property
@allure.step('Get checked {0}')
def is_checked(self) -> bool:
return self.object.checked
@property
@allure.step('Get visible {0}')
def is_visible(self) -> bool:
try:
return driver.waitForObject(self.real_name, 0).visible
except (AttributeError, LookupError, RuntimeError):
return False
@property
@allure.step('Get image {0}')
def image(self):
if self._image.view is None:
self._image.update_view()
return self._image
@allure.step('Click {0}')
def click(
self,
x: int = None,
y: int = None,
button=None
):
driver.mouseClick(
self.object,
x or self.width // 2,
y or self.height // 2,
button or driver.Qt.LeftButton
)
@allure.step('Hover {0}')
def hover(self, timeout_msec: int = configs.timeouts.UI_LOAD_TIMEOUT_MSEC):
def _hover():
try:
driver.mouseMove(self.object)
return getattr(self.object, 'hovered', True)
except RuntimeError as err:
_logger.debug(err)
time.sleep(1)
return False
assert driver.waitFor(lambda: _hover(), timeout_msec)