2023-10-04 08:54:13 +00:00
|
|
|
import allure
|
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
|
|
|
|
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
|
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 ''
|
|
|
|
|
|
|
|
|
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():
|
|
|
|
for log in (app_data / 'logs').iterdir():
|
|
|
|
allure.attach.file(log, name=str(log.name), attachment_type=allure.attachment_type.TEXT)
|
|
|
|
log.unlink()
|
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()
|
|
|
|
def multiple_instance():
|
|
|
|
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
|