From 1c5aad7733b5a226f383b09bcc31208943188dea Mon Sep 17 00:00:00 2001 From: Anastasiya Semenkevich Date: Tue, 18 Jun 2024 09:53:37 +0300 Subject: [PATCH] chore: replace conditions with function call in system.py --- test/e2e/configs/__init__.py | 3 ++- test/e2e/configs/system.py | 7 +++---- test/e2e/conftest.py | 4 ++-- test/e2e/constants/commands.py | 4 ++-- test/e2e/driver/aut.py | 4 ++-- test/e2e/gui/main_window.py | 4 ++-- test/e2e/gui/screens/onboarding.py | 2 +- test/e2e/scripts/tools/image.py | 6 +++--- test/e2e/scripts/utils/local_system.py | 9 ++++----- .../communities/test_communities_mint_owner_token.py | 4 ++-- .../onboarding/test_onboarding_generate_new_keys.py | 4 ++-- test/e2e/tests/onboarding/test_onboarding_import_seed.py | 4 ++-- .../onboarding/test_onboarding_negative_scenarios.py | 4 ++-- test/e2e/tests/onboarding/test_onboarding_syncing.py | 2 +- test/e2e/tests/settings/test_ens_name_purchase.py | 4 ++-- .../wallet - footer actions/test_footer_actions_send.py | 4 ++-- .../test_footer_actions_send_nft.py | 4 ++-- 17 files changed, 36 insertions(+), 37 deletions(-) diff --git a/test/e2e/configs/__init__.py b/test/e2e/configs/__init__.py index f60383c8a5..795e02f84c 100644 --- a/test/e2e/configs/__init__.py +++ b/test/e2e/configs/__init__.py @@ -3,6 +3,7 @@ import logging from os import path from scripts.utils.system_path import SystemPath from . import testpath, timeouts, testrail, squish, system +from .system import get_platform LOG = logging.getLogger(__name__) @@ -17,7 +18,7 @@ except ImportError: if AUT_PATH is None: exit('Please add "AUT_PATH" in ./configs/_local.py') -if system.IS_WIN and 'bin' not in AUT_PATH: +if get_platform() == "Windows" and 'bin' not in AUT_PATH: exit('Please use launcher from "bin" folder in "AUT_PATH"') AUT_PATH = SystemPath(AUT_PATH) diff --git a/test/e2e/configs/system.py b/test/e2e/configs/system.py index ebed60e33c..69fd13ee27 100644 --- a/test/e2e/configs/system.py +++ b/test/e2e/configs/system.py @@ -1,11 +1,10 @@ import os import platform -IS_LIN = True if platform.system() == 'Linux' else False -IS_MAC = True if platform.system() == 'Darwin' else False -IS_WIN = True if platform.system() == 'Windows' else False -OS_ID = 'lin' if IS_LIN else 'mac' if IS_MAC else 'win' +def get_platform(): + return platform.system() + DISPLAY = os.getenv('DISPLAY', ':0') diff --git a/test/e2e/conftest.py b/test/e2e/conftest.py index 8ddb36bafa..323be2de3a 100644 --- a/test/e2e/conftest.py +++ b/test/e2e/conftest.py @@ -7,7 +7,7 @@ import pytest from PIL import ImageGrab import configs -from configs.system import IS_LIN +from configs.system import get_platform from fixtures.path import generate_test_info from scripts.utils.system_path import SystemPath @@ -62,7 +62,7 @@ def pytest_exception_interact(node): node_dir: SystemPath = configs.testpath.RUN / test_path / test_name / test_params node_dir.mkdir(parents=True, exist_ok=True) screenshot = node_dir / f'screenshot_{datetime.today().strftime("%Y-%m-%d %H-%M-%S")}.png' - ImageGrab.grab(xdisplay=configs.system.DISPLAY if IS_LIN else None).save(screenshot) + ImageGrab.grab(xdisplay=configs.system.DISPLAY if get_platform() == "Linux" else None).save(screenshot) allure.attach( name='Screenshot on fail', body=screenshot.read_bytes(), diff --git a/test/e2e/constants/commands.py b/test/e2e/constants/commands.py index 736d30064c..71e246fd57 100644 --- a/test/e2e/constants/commands.py +++ b/test/e2e/constants/commands.py @@ -1,4 +1,4 @@ -import configs.system +from configs import system # Buttons BACKSPACE = 'Backspace' @@ -9,5 +9,5 @@ RETURN = 'Return' SHIFT = 'Shift' # Combinations -SELECT_ALL = f'{CTRL if configs.system.IS_WIN else COMMAND}+A' +SELECT_ALL = f'{CTRL if system.get_platform() == "Windows" else COMMAND}+A' OPEN_GOTO = f'{COMMAND}+{SHIFT}+G' diff --git a/test/e2e/driver/aut.py b/test/e2e/driver/aut.py index f2948f7dfa..e6d9d3552a 100644 --- a/test/e2e/driver/aut.py +++ b/test/e2e/driver/aut.py @@ -9,7 +9,7 @@ import configs import driver import shortuuid from datetime import datetime -from configs.system import IS_LIN +from configs.system import get_platform from driver import context from driver.server import SquishServer from gui.objects_map.names import statusDesktop_mainWindow @@ -54,7 +54,7 @@ class AUT: rect = driver.object.globalBounds(driver.waitForObject(statusDesktop_mainWindow)) img = ImageGrab.grab( bbox=(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height), - xdisplay=configs.system.DISPLAY if IS_LIN else None) + xdisplay=configs.system.DISPLAY if get_platform() == "Linux" else None) view = cv2.cvtColor(np.array(img), cv2.COLOR_BGR2RGB) cv2.imwrite(str(screenshot), view) diff --git a/test/e2e/gui/main_window.py b/test/e2e/gui/main_window.py index 41985985af..111588b828 100644 --- a/test/e2e/gui/main_window.py +++ b/test/e2e/gui/main_window.py @@ -183,11 +183,11 @@ class MainWindow(Window): create_password_view = profile_view.next() confirm_password_view = create_password_view.create_password(user_account.password) confirm_password_view.confirm_password(user_account.password) - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": BiometricsView().wait_until_appears().prefer_password() SplashScreen().wait_until_appears().wait_until_hidden() YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": AllowNotificationsView().start_using_status() SplashScreen().wait_until_appears().wait_until_hidden() if not configs.system.TEST_MODE: diff --git a/test/e2e/gui/screens/onboarding.py b/test/e2e/gui/screens/onboarding.py index 9c20c8ae6b..53576eafff 100755 --- a/test/e2e/gui/screens/onboarding.py +++ b/test/e2e/gui/screens/onboarding.py @@ -419,7 +419,7 @@ class YourEmojihashAndIdenticonRingView(OnboardingView): def next(self): self._next_button.click() time.sleep(1) - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": return AllowNotificationsView().wait_until_appears() @allure.step('Go back') diff --git a/test/e2e/scripts/tools/image.py b/test/e2e/scripts/tools/image.py index 03339dabf6..979679d72b 100755 --- a/test/e2e/scripts/tools/image.py +++ b/test/e2e/scripts/tools/image.py @@ -12,7 +12,7 @@ from PIL import ImageGrab import configs import constants import driver -from configs.system import IS_LIN +from configs.system import get_platform from scripts.tools.ocv import Ocv from scripts.utils.system_path import SystemPath @@ -57,7 +57,7 @@ class Image: rect = driver.object.globalBounds(driver.waitForObject(self.object_name)) img = ImageGrab.grab( bbox=(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height), - xdisplay=configs.system.DISPLAY if IS_LIN else None + xdisplay=configs.system.DISPLAY if get_platform() == "Linux" else None ) self._view = cv2.cvtColor(np.array(img), cv2.COLOR_BGR2RGB) @@ -212,7 +212,7 @@ def compare(actual: Image, ): expected_fp = None if isinstance(expected, str): - expected_fp = configs.testpath.TEST_VP / configs.system.OS_ID / expected + expected_fp = configs.testpath.TEST_VP / configs.system.get_platform() / expected if not expected_fp.exists(): expected_fp = configs.testpath.TEST_VP / expected expected = expected_fp diff --git a/test/e2e/scripts/utils/local_system.py b/test/e2e/scripts/utils/local_system.py index 81573c3861..1e97c66b0d 100644 --- a/test/e2e/scripts/utils/local_system.py +++ b/test/e2e/scripts/utils/local_system.py @@ -9,6 +9,7 @@ import allure import psutil import configs +from configs.system import get_platform LOG = logging.getLogger(__name__) @@ -35,15 +36,13 @@ def find_free_port(start: int, step: int): def kill_process(pid): LOG.debug(f'Terminating process {pid}') - current_platform = platform.system() - try: - if current_platform == "Windows": + if get_platform() == "Windows": subprocess.call(f"taskkill /F /T /PID {str(pid)}") - elif current_platform in ["Linux", "Darwin"]: + elif get_platform() in ["Linux", "Darwin"]: os.kill(pid, signal.SIGKILL) else: - raise NotImplementedError(f"Unsupported platform: {current_platform}") + raise NotImplementedError(f"Unsupported platform: {get_platform()}") except Exception as e: print(f"Failed to terminate process {pid}: {e}") diff --git a/test/e2e/tests/communities/test_communities_mint_owner_token.py b/test/e2e/tests/communities/test_communities_mint_owner_token.py index 0928b03700..685f13c4a9 100644 --- a/test/e2e/tests/communities/test_communities_mint_owner_token.py +++ b/test/e2e/tests/communities/test_communities_mint_owner_token.py @@ -41,11 +41,11 @@ def test_mint_owner_token(keys_screen, main_window, user_account): create_password_view = profile_view.next() confirm_password_view = create_password_view.create_password(user_account.password) confirm_password_view.confirm_password(user_account.password) - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": BiometricsView().wait_until_appears().prefer_password() SplashScreen().wait_until_appears().wait_until_hidden() next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": next_view.start_using_status() SplashScreen().wait_until_appears().wait_until_hidden() if not configs.system.TEST_MODE: diff --git a/test/e2e/tests/onboarding/test_onboarding_generate_new_keys.py b/test/e2e/tests/onboarding/test_onboarding_generate_new_keys.py index 1de4834347..f166406980 100755 --- a/test/e2e/tests/onboarding/test_onboarding_generate_new_keys.py +++ b/test/e2e/tests/onboarding/test_onboarding_generate_new_keys.py @@ -86,7 +86,7 @@ def test_generate_new_keys_sign_out_from_settings(aut, main_window, keys_screen, with step('Confirm password and login'): confirm_password_view.confirm_password(password) - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": assert BiometricsView().is_touch_id_button_visible(), f"TouchID button is not found" BiometricsView().wait_until_appears().prefer_password() SplashScreen().wait_until_appears().wait_until_hidden() @@ -99,7 +99,7 @@ def test_generate_new_keys_sign_out_from_settings(aut, main_window, keys_screen, with step('Click Start using Status'): next_view = emoji_hash_identicon_view.next() - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": next_view.start_using_status() SplashScreen().wait_until_appears().wait_until_hidden() if not configs.system.TEST_MODE: diff --git a/test/e2e/tests/onboarding/test_onboarding_import_seed.py b/test/e2e/tests/onboarding/test_onboarding_import_seed.py index 5e429cdb51..58214c9757 100644 --- a/test/e2e/tests/onboarding/test_onboarding_import_seed.py +++ b/test/e2e/tests/onboarding/test_onboarding_import_seed.py @@ -45,11 +45,11 @@ def test_import_seed_phrase(keys_screen, main_window, aut: AUT, user_account, de create_password_view = profile_view.next() confirm_password_view = create_password_view.create_password(user_account.password) confirm_password_view.confirm_password(user_account.password) - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": BiometricsView().wait_until_appears().prefer_password() SplashScreen().wait_until_appears().wait_until_hidden() next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": next_view.start_using_status() SplashScreen().wait_until_appears().wait_until_hidden() if not configs.system.TEST_MODE: diff --git a/test/e2e/tests/onboarding/test_onboarding_negative_scenarios.py b/test/e2e/tests/onboarding/test_onboarding_negative_scenarios.py index e5298eccb8..5abfe5f185 100644 --- a/test/e2e/tests/onboarding/test_onboarding_negative_scenarios.py +++ b/test/e2e/tests/onboarding/test_onboarding_negative_scenarios.py @@ -45,11 +45,11 @@ def test_login_with_wrong_password(aut: AUT, keys_screen, main_window, error: st create_password_view = profile_view.next() confirm_password_view = create_password_view.create_password(user_one.password) confirm_password_view.confirm_password(user_one.password) - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": BiometricsView().wait_until_appears().prefer_password() SplashScreen().wait_until_appears().wait_until_hidden() next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": next_view.start_using_status() SplashScreen().wait_until_appears().wait_until_hidden() if not configs.system.TEST_MODE: diff --git a/test/e2e/tests/onboarding/test_onboarding_syncing.py b/test/e2e/tests/onboarding/test_onboarding_syncing.py index 43ea551308..7b8cdddc1b 100644 --- a/test/e2e/tests/onboarding/test_onboarding_syncing.py +++ b/test/e2e/tests/onboarding/test_onboarding_syncing.py @@ -86,7 +86,7 @@ def test_sync_device_during_onboarding(multiple_instances): sync_result.sign_in() SplashScreen().wait_until_hidden() YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": AllowNotificationsView().start_using_status() SplashScreen().wait_until_appears().wait_until_hidden() if not configs.system.TEST_MODE: diff --git a/test/e2e/tests/settings/test_ens_name_purchase.py b/test/e2e/tests/settings/test_ens_name_purchase.py index a5a35a3201..74e25e1539 100644 --- a/test/e2e/tests/settings/test_ens_name_purchase.py +++ b/test/e2e/tests/settings/test_ens_name_purchase.py @@ -46,11 +46,11 @@ def test_ens_name_purchase(keys_screen, main_window, user_account, ens_name): create_password_view = profile_view.next() confirm_password_view = create_password_view.create_password(user_account.password) confirm_password_view.confirm_password(user_account.password) - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": BiometricsView().wait_until_appears().prefer_password() SplashScreen().wait_until_appears().wait_until_hidden() next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": next_view.start_using_status() SplashScreen().wait_until_appears().wait_until_hidden() if not configs.system.TEST_MODE: diff --git a/test/e2e/tests/wallet_main_screen/wallet - footer actions/test_footer_actions_send.py b/test/e2e/tests/wallet_main_screen/wallet - footer actions/test_footer_actions_send.py index 35bc875daf..089a7b0c2d 100644 --- a/test/e2e/tests/wallet_main_screen/wallet - footer actions/test_footer_actions_send.py +++ b/test/e2e/tests/wallet_main_screen/wallet - footer actions/test_footer_actions_send.py @@ -44,11 +44,11 @@ def test_wallet_send_0_eth(keys_screen, main_window, user_account, receiver_acco create_password_view = profile_view.next() confirm_password_view = create_password_view.create_password(user_account.password) confirm_password_view.confirm_password(user_account.password) - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": BiometricsView().wait_until_appears().prefer_password() SplashScreen().wait_until_appears().wait_until_hidden() next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": next_view.start_using_status() SplashScreen().wait_until_appears().wait_until_hidden() if not configs.system.TEST_MODE: diff --git a/test/e2e/tests/wallet_main_screen/wallet - footer actions/test_footer_actions_send_nft.py b/test/e2e/tests/wallet_main_screen/wallet - footer actions/test_footer_actions_send_nft.py index 5ac5dbb432..1ac0ef27ab 100644 --- a/test/e2e/tests/wallet_main_screen/wallet - footer actions/test_footer_actions_send_nft.py +++ b/test/e2e/tests/wallet_main_screen/wallet - footer actions/test_footer_actions_send_nft.py @@ -44,11 +44,11 @@ def test_wallet_send_nft(keys_screen, main_window, user_account, tab, receiver_a create_password_view = profile_view.next() confirm_password_view = create_password_view.create_password(user_account.password) confirm_password_view.confirm_password(user_account.password) - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": BiometricsView().wait_until_appears().prefer_password() SplashScreen().wait_until_appears().wait_until_hidden() next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() - if configs.system.IS_MAC: + if configs.system.get_platform() == "Darwin": next_view.start_using_status() SplashScreen().wait_until_appears().wait_until_hidden() if not configs.system.TEST_MODE: