2023-09-13 07:47:51 +00:00
|
|
|
import logging
|
2023-08-29 14:43:00 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
import allure
|
|
|
|
|
|
|
|
import driver
|
|
|
|
from .object import QObject
|
|
|
|
|
2023-12-01 13:58:22 +00:00
|
|
|
LOG = logging.getLogger(__name__)
|
2023-09-13 07:47:51 +00:00
|
|
|
|
2023-08-29 14:43:00 +00:00
|
|
|
|
|
|
|
class Scroll(QObject):
|
|
|
|
|
2023-10-31 10:53:49 +00:00
|
|
|
@allure.step('Scroll vertical to object {1}')
|
2023-08-29 14:43:00 +00:00
|
|
|
def vertical_scroll_to(self, element: QObject, timeout_sec: int = 5):
|
|
|
|
started_at = time.monotonic()
|
|
|
|
step = 10
|
|
|
|
direction = 1
|
|
|
|
while not element.is_visible:
|
|
|
|
step *= 2
|
|
|
|
direction *= -1
|
|
|
|
driver.flick(self.object, 0, step * direction)
|
|
|
|
time.sleep(0.1)
|
|
|
|
if time.monotonic() - started_at > timeout_sec:
|
|
|
|
raise LookupError(f'Object not found: {element}')
|
2023-09-13 07:47:51 +00:00
|
|
|
try:
|
|
|
|
if hasattr(element.object, 'y'):
|
2023-10-02 09:21:12 +00:00
|
|
|
y = int(element.object.y)
|
|
|
|
if hasattr(element.object, 'height'):
|
|
|
|
y += int(element.object.height)
|
|
|
|
driver.flick(self.object, 0, y)
|
2023-12-04 18:16:52 +00:00
|
|
|
LOG.info('%s: scrolled to %s', self, element)
|
2023-09-13 07:47:51 +00:00
|
|
|
except LookupError as err:
|
2023-12-04 18:16:52 +00:00
|
|
|
LOG.error(err)
|
2023-09-07 04:13:38 +00:00
|
|
|
|
|
|
|
@allure.step('Scroll down to object')
|
|
|
|
def vertical_down_to(self, element: QObject, timeout_sec: int = 5):
|
|
|
|
started_at = time.monotonic()
|
|
|
|
step = 100
|
|
|
|
while not element.is_visible:
|
|
|
|
driver.flick(self.object, 0, step)
|
|
|
|
if time.monotonic() - started_at > timeout_sec:
|
|
|
|
raise LookupError(f'Object not found: {element}')
|
2023-12-04 18:16:52 +00:00
|
|
|
LOG.info('%s: scrolled down to %s', self, element)
|