From 61b87e0d23639c413ad4082c1d168c2da9b03790 Mon Sep 17 00:00:00 2001 From: Vladimir Druzhinin Date: Wed, 13 Sep 2023 09:47:51 +0200 Subject: [PATCH] Fix start AUT --- test/e2e/configs/__init__.py | 5 +++++ test/e2e/configs/_local.py.ci | 1 - test/e2e/configs/_local.py.default | 1 - test/e2e/driver/atomacos.py | 8 +++----- test/e2e/driver/aut.py | 8 +++++--- test/e2e/gui/elements/qt/scroll.py | 10 ++++++++-- test/e2e/scripts/utils/local_system.py | 23 +++++++++++++++++------ test/e2e/tests/fixtures/squish.py | 1 + 8 files changed, 39 insertions(+), 18 deletions(-) diff --git a/test/e2e/configs/__init__.py b/test/e2e/configs/__init__.py index fc27f746fa..687bbcf4d5 100644 --- a/test/e2e/configs/__init__.py +++ b/test/e2e/configs/__init__.py @@ -19,3 +19,8 @@ if APP_DIR is None: if system.IS_WIN and 'bin' not in APP_DIR: exit('Please use launcher from "bin" folder in "APP_DIR"') APP_DIR = SystemPath(APP_DIR) + + +# Application will be stuck in test execution if set to False (Mac only) +# We need to investigate more time on it. +ATTACH_MODE = True diff --git a/test/e2e/configs/_local.py.ci b/test/e2e/configs/_local.py.ci index c68ab16cb4..0fca80c0be 100644 --- a/test/e2e/configs/_local.py.ci +++ b/test/e2e/configs/_local.py.ci @@ -3,5 +3,4 @@ import os LOG_LEVEL = logging.DEBUG DEV_BUILD = False -ATTACH_MODE = False APP_DIR = os.getenv('APP_DIR') diff --git a/test/e2e/configs/_local.py.default b/test/e2e/configs/_local.py.default index ed169a9fba..2fc1b4a6a7 100644 --- a/test/e2e/configs/_local.py.default +++ b/test/e2e/configs/_local.py.default @@ -2,5 +2,4 @@ import logging LOG_LEVEL = logging.DEBUG DEV_BUILD = False -ATTACH_MODE = False APP_DIR = None diff --git a/test/e2e/driver/atomacos.py b/test/e2e/driver/atomacos.py index c80657e782..9ecd1375f5 100644 --- a/test/e2e/driver/atomacos.py +++ b/test/e2e/driver/atomacos.py @@ -2,6 +2,7 @@ import time from copy import deepcopy import configs.timeouts +import driver from scripts.utils import local_system if configs.system.IS_MAC: @@ -27,11 +28,8 @@ def attach_atomac(timeout_sec: int = configs.timeouts.UI_LOAD_TIMEOUT_SEC): ) return atomacos.NativeUIElement.from_pid(apps[-1].processIdentifier()) - if configs.DEV_BUILD: - pid = local_system.find_process_by_port(configs.squish.AUT_PORT) - atomator = atomacos.getAppRefByPid(pid) - else: - atomator = from_bundle_id(BUNDLE_ID) + pid = driver.currentApplicationContext().pid + atomator = atomacos.getAppRefByPid(pid) started_at = time.monotonic() while not hasattr(atomator, 'AXMainWindow'): time.sleep(1) diff --git a/test/e2e/driver/aut.py b/test/e2e/driver/aut.py index cb002f6b2b..7f21d04cd5 100644 --- a/test/e2e/driver/aut.py +++ b/test/e2e/driver/aut.py @@ -26,7 +26,7 @@ class AUT: self.port = int(port) self.ctx = None self.pid = None - self.aut_id = self.path.name if IS_LIN else self.path.stem + self.aut_id = f'AUT_{datetime.now():%H%M%S}' self.app_data = configs.testpath.STATUS_DATA / f'app_{datetime.now():%H%M%S_%f}' self.user_data = user_data driver.testSettings.setWrappersForApplication(self.aut_id, ['Qt']) @@ -43,7 +43,7 @@ class AUT: @allure.step('Attach Squish to Test Application') def attach(self, timeout_sec: int = configs.timeouts.PROCESS_TIMEOUT_SEC, attempt: int = 2): if self.ctx is None: - self.ctx = context.attach('AUT', timeout_sec) + self.ctx = context.attach(self.aut_id, timeout_sec) try: squish.setApplicationContext(self.ctx) except TypeError as err: @@ -71,7 +71,9 @@ class AUT: SquishServer().set_aut_timeout() if configs.ATTACH_MODE: - SquishServer().add_attachable_aut('AUT', self.port) + if local_system.find_process_by_port(self.port): + self.port += 100 + SquishServer().add_attachable_aut(self.aut_id, self.port) command = [ configs.testpath.SQUISH_DIR / 'bin' / 'startaut', f'--port={self.port}', diff --git a/test/e2e/gui/elements/qt/scroll.py b/test/e2e/gui/elements/qt/scroll.py index ea92ec639f..66c1d94bbf 100644 --- a/test/e2e/gui/elements/qt/scroll.py +++ b/test/e2e/gui/elements/qt/scroll.py @@ -1,3 +1,4 @@ +import logging import time import allure @@ -5,6 +6,8 @@ import allure import driver from .object import QObject +_logger = logging.getLogger(__name__) + class Scroll(QObject): @@ -20,8 +23,11 @@ class Scroll(QObject): time.sleep(0.1) if time.monotonic() - started_at > timeout_sec: raise LookupError(f'Object not found: {element}') - if hasattr(element.object, 'y'): - driver.flick(self.object, 0, int(element.object.y)) + try: + if hasattr(element.object, 'y'): + driver.flick(self.object, 0, int(element.object.y)) + except LookupError as err: + _logger.debug(err) @allure.step('Scroll down to object') def vertical_down_to(self, element: QObject, timeout_sec: int = 5): diff --git a/test/e2e/scripts/utils/local_system.py b/test/e2e/scripts/utils/local_system.py index 1aa4d85e8b..7de7c784e1 100644 --- a/test/e2e/scripts/utils/local_system.py +++ b/test/e2e/scripts/utils/local_system.py @@ -26,22 +26,33 @@ def find_process_by_port(port: int) -> int: def wait_for_close(pid: int, timeout_sec: int = configs.timeouts.PROCESS_TIMEOUT_SEC): started_at = time.monotonic() while True: - if pid in [proc.pid for proc in psutil.process_iter()]: - time.sleep(1) - if time.monotonic() - started_at > timeout_sec: - raise RuntimeError(f'Process with PID: {pid} not closed') + for proc in psutil.process_iter(): + try: + if proc.pid == pid: + return True + except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): + pass + time.sleep(1) + if time.monotonic() - started_at > timeout_sec: + raise RuntimeError(f'Process with PID: {pid} not closed') else: break @allure.step('Kill process') -def kill_process(pid, verify: bool = False): +def kill_process(pid, verify: bool = False, timeout_sec: int = configs.timeouts.PROCESS_TIMEOUT_SEC, attempt: int = 2): try: os.kill(pid, signal.SIGILL if IS_WIN else signal.SIGKILL) except ProcessLookupError as err: _logger.debug(err) if verify: - wait_for_close(pid) + try: + wait_for_close(pid, timeout_sec) + except RuntimeError as err: + if attempt: + kill_process(pid, verify, timeout_sec, attempt-1) + else: + raise err @allure.step('System execute command') diff --git a/test/e2e/tests/fixtures/squish.py b/test/e2e/tests/fixtures/squish.py index 7b767c9151..e2eb9da663 100644 --- a/test/e2e/tests/fixtures/squish.py +++ b/test/e2e/tests/fixtures/squish.py @@ -18,3 +18,4 @@ def start_squish_server(): pytest.exit(err) yield squish_server squish_server.stop() + squish_server.config.unlink()