2023-10-04 08:54:13 +00:00
|
|
|
import allure
|
2024-07-12 09:44:29 +00:00
|
|
|
import os
|
2024-07-24 10:13:05 +00:00
|
|
|
|
2023-08-04 18:27:03 +00:00
|
|
|
import pytest
|
2023-11-30 13:07:26 +00:00
|
|
|
import logging
|
2023-08-04 18:27:03 +00:00
|
|
|
import configs
|
2023-08-29 14:43:00 +00:00
|
|
|
import constants
|
2024-07-24 10:13:05 +00:00
|
|
|
from configs import get_platform
|
2023-08-29 14:43:00 +00:00
|
|
|
from constants import UserAccount
|
2023-08-04 18:27:03 +00:00
|
|
|
from driver.aut import AUT
|
|
|
|
from gui.main_window import MainWindow
|
|
|
|
from scripts.utils import system_path
|
2024-07-24 10:13:05 +00:00
|
|
|
from scripts.utils.local_system import get_pid_by_process_name, kill_process
|
2023-09-11 18:24:13 +00:00
|
|
|
from scripts.utils.system_path import SystemPath
|
2023-08-04 18:27:03 +00:00
|
|
|
|
2023-11-30 13:07:26 +00:00
|
|
|
LOG = logging.getLogger(__name__)
|
2023-10-09 17:04:29 +00:00
|
|
|
|
2023-11-30 10:51:00 +00:00
|
|
|
|
2023-11-06 11:31:34 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def options(request):
|
|
|
|
if hasattr(request, 'param'):
|
|
|
|
return request.param
|
|
|
|
return ''
|
|
|
|
|
2024-07-12 09:44:29 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def keycard_controller(request):
|
|
|
|
if 'settings_keycard' in str(getattr(request, 'fspath')):
|
|
|
|
os.environ['STATUS_RUNTIME_USE_MOCKED_KEYCARD'] = 'True'
|
2023-11-06 11:31:34 +00:00
|
|
|
|
2023-10-04 08:54:13 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def application_logs():
|
|
|
|
yield
|
2023-10-27 11:44:45 +00:00
|
|
|
if configs.testpath.STATUS_DATA.exists():
|
|
|
|
for app_data in configs.testpath.STATUS_DATA.iterdir():
|
2024-06-28 12:49:47 +00:00
|
|
|
for log_dir in ['logs', 'data']:
|
|
|
|
log_path = app_data / log_dir
|
|
|
|
for log in log_path.glob('*.log'):
|
|
|
|
allure.attach.file(log, name=str(log.name), attachment_type=allure.attachment_type.TEXT)
|
|
|
|
try:
|
|
|
|
log.unlink() # FIXME: it does not work on Windows, permission error
|
|
|
|
except PermissionError:
|
|
|
|
print(f"Permission error: {log} could not be deleted.")
|
2023-10-04 08:54:13 +00:00
|
|
|
|
2023-08-04 18:27:03 +00:00
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def user_data(request) -> system_path.SystemPath:
|
|
|
|
if hasattr(request, 'param'):
|
2023-08-10 11:43:17 +00:00
|
|
|
fp = request.param
|
|
|
|
assert fp.is_dir()
|
2023-09-11 18:24:13 +00:00
|
|
|
return fp
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def aut(user_data) -> AUT:
|
2023-11-30 11:05:59 +00:00
|
|
|
if not configs.AUT_PATH.exists():
|
|
|
|
pytest.exit(f"Application not found: {configs.AUT_PATH}")
|
2023-09-11 18:24:13 +00:00
|
|
|
_aut = AUT(user_data=user_data)
|
|
|
|
yield _aut
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
2024-03-27 09:38:50 +00:00
|
|
|
def multiple_instances(user_data):
|
2023-09-11 18:24:13 +00:00
|
|
|
def _aut(user_data: SystemPath = None) -> AUT:
|
2023-11-30 11:05:59 +00:00
|
|
|
if not configs.AUT_PATH.exists():
|
|
|
|
pytest.exit(f"Application not found: {configs.AUT_PATH}")
|
2023-09-11 18:24:13 +00:00
|
|
|
return AUT(user_data=user_data)
|
|
|
|
|
|
|
|
yield _aut
|
2023-08-04 18:27:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2023-11-30 13:07:26 +00:00
|
|
|
def main_window(aut: AUT, user_data):
|
|
|
|
aut.launch()
|
|
|
|
LOG.debug('Waiting for main window...')
|
2023-08-04 18:27:03 +00:00
|
|
|
yield MainWindow().wait_until_appears().prepare()
|
2023-10-27 11:44:45 +00:00
|
|
|
aut.stop()
|
2023-08-29 14:43:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def user_account(request) -> UserAccount:
|
|
|
|
if hasattr(request, 'param'):
|
|
|
|
user_account = request.param
|
|
|
|
assert isinstance(user_account, UserAccount)
|
|
|
|
else:
|
2023-09-11 18:24:13 +00:00
|
|
|
user_account = constants.user.user_account_one
|
2023-08-29 14:43:00 +00:00
|
|
|
yield user_account
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def main_screen(user_account: UserAccount, main_window: MainWindow) -> MainWindow:
|
2023-09-11 18:24:13 +00:00
|
|
|
main_window.authorize_user(user_account)
|
|
|
|
return main_window
|
2024-07-24 10:13:05 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def close_apps_before_start():
|
|
|
|
if get_platform() == "Windows":
|
|
|
|
name = 'Status.exe'
|
|
|
|
else:
|
|
|
|
name = 'nim_status_client'
|
|
|
|
running_pids = get_pid_by_process_name(name)
|
|
|
|
if running_pids is not None:
|
|
|
|
for pid in running_pids:
|
|
|
|
kill_process(pid)
|