Fix start AUT

This commit is contained in:
Vladimir Druzhinin 2023-09-13 09:47:51 +02:00
parent 8c3a851399
commit 61b87e0d23
8 changed files with 39 additions and 18 deletions

View File

@ -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

View File

@ -3,5 +3,4 @@ import os
LOG_LEVEL = logging.DEBUG
DEV_BUILD = False
ATTACH_MODE = False
APP_DIR = os.getenv('APP_DIR')

View File

@ -2,5 +2,4 @@ import logging
LOG_LEVEL = logging.DEBUG
DEV_BUILD = False
ATTACH_MODE = False
APP_DIR = None

View File

@ -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)

View File

@ -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}',

View File

@ -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):

View File

@ -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')

View File

@ -18,3 +18,4 @@ def start_squish_server():
pytest.exit(err)
yield squish_server
squish_server.stop()
squish_server.config.unlink()