chore: replace conditions with function call in system.py

This commit is contained in:
Anastasiya Semenkevich 2024-06-18 09:53:37 +03:00 committed by Anastasiya
parent dc628f300a
commit 1c5aad7733
17 changed files with 36 additions and 37 deletions

View File

@ -3,6 +3,7 @@ import logging
from os import path from os import path
from scripts.utils.system_path import SystemPath from scripts.utils.system_path import SystemPath
from . import testpath, timeouts, testrail, squish, system from . import testpath, timeouts, testrail, squish, system
from .system import get_platform
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -17,7 +18,7 @@ except ImportError:
if AUT_PATH is None: if AUT_PATH is None:
exit('Please add "AUT_PATH" in ./configs/_local.py') 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"') exit('Please use launcher from "bin" folder in "AUT_PATH"')
AUT_PATH = SystemPath(AUT_PATH) AUT_PATH = SystemPath(AUT_PATH)

View File

@ -1,11 +1,10 @@
import os import os
import platform 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') DISPLAY = os.getenv('DISPLAY', ':0')

View File

@ -7,7 +7,7 @@ import pytest
from PIL import ImageGrab from PIL import ImageGrab
import configs import configs
from configs.system import IS_LIN from configs.system import get_platform
from fixtures.path import generate_test_info from fixtures.path import generate_test_info
from scripts.utils.system_path import SystemPath 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: SystemPath = configs.testpath.RUN / test_path / test_name / test_params
node_dir.mkdir(parents=True, exist_ok=True) node_dir.mkdir(parents=True, exist_ok=True)
screenshot = node_dir / f'screenshot_{datetime.today().strftime("%Y-%m-%d %H-%M-%S")}.png' 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( allure.attach(
name='Screenshot on fail', name='Screenshot on fail',
body=screenshot.read_bytes(), body=screenshot.read_bytes(),

View File

@ -1,4 +1,4 @@
import configs.system from configs import system
# Buttons # Buttons
BACKSPACE = 'Backspace' BACKSPACE = 'Backspace'
@ -9,5 +9,5 @@ RETURN = 'Return'
SHIFT = 'Shift' SHIFT = 'Shift'
# Combinations # 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' OPEN_GOTO = f'{COMMAND}+{SHIFT}+G'

View File

@ -9,7 +9,7 @@ import configs
import driver import driver
import shortuuid import shortuuid
from datetime import datetime from datetime import datetime
from configs.system import IS_LIN from configs.system import get_platform
from driver import context from driver import context
from driver.server import SquishServer from driver.server import SquishServer
from gui.objects_map.names import statusDesktop_mainWindow from gui.objects_map.names import statusDesktop_mainWindow
@ -54,7 +54,7 @@ class AUT:
rect = driver.object.globalBounds(driver.waitForObject(statusDesktop_mainWindow)) rect = driver.object.globalBounds(driver.waitForObject(statusDesktop_mainWindow))
img = ImageGrab.grab( img = ImageGrab.grab(
bbox=(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height), 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) view = cv2.cvtColor(np.array(img), cv2.COLOR_BGR2RGB)
cv2.imwrite(str(screenshot), view) cv2.imwrite(str(screenshot), view)

View File

@ -183,11 +183,11 @@ class MainWindow(Window):
create_password_view = profile_view.next() create_password_view = profile_view.next()
confirm_password_view = create_password_view.create_password(user_account.password) confirm_password_view = create_password_view.create_password(user_account.password)
confirm_password_view.confirm_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() BiometricsView().wait_until_appears().prefer_password()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next()
if configs.system.IS_MAC: if configs.system.get_platform() == "Darwin":
AllowNotificationsView().start_using_status() AllowNotificationsView().start_using_status()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
if not configs.system.TEST_MODE: if not configs.system.TEST_MODE:

View File

@ -419,7 +419,7 @@ class YourEmojihashAndIdenticonRingView(OnboardingView):
def next(self): def next(self):
self._next_button.click() self._next_button.click()
time.sleep(1) time.sleep(1)
if configs.system.IS_MAC: if configs.system.get_platform() == "Darwin":
return AllowNotificationsView().wait_until_appears() return AllowNotificationsView().wait_until_appears()
@allure.step('Go back') @allure.step('Go back')

View File

@ -12,7 +12,7 @@ from PIL import ImageGrab
import configs import configs
import constants import constants
import driver import driver
from configs.system import IS_LIN from configs.system import get_platform
from scripts.tools.ocv import Ocv from scripts.tools.ocv import Ocv
from scripts.utils.system_path import SystemPath from scripts.utils.system_path import SystemPath
@ -57,7 +57,7 @@ class Image:
rect = driver.object.globalBounds(driver.waitForObject(self.object_name)) rect = driver.object.globalBounds(driver.waitForObject(self.object_name))
img = ImageGrab.grab( img = ImageGrab.grab(
bbox=(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height), 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) self._view = cv2.cvtColor(np.array(img), cv2.COLOR_BGR2RGB)
@ -212,7 +212,7 @@ def compare(actual: Image,
): ):
expected_fp = None expected_fp = None
if isinstance(expected, str): 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(): if not expected_fp.exists():
expected_fp = configs.testpath.TEST_VP / expected expected_fp = configs.testpath.TEST_VP / expected
expected = expected_fp expected = expected_fp

View File

@ -9,6 +9,7 @@ import allure
import psutil import psutil
import configs import configs
from configs.system import get_platform
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -35,15 +36,13 @@ def find_free_port(start: int, step: int):
def kill_process(pid): def kill_process(pid):
LOG.debug(f'Terminating process {pid}') LOG.debug(f'Terminating process {pid}')
current_platform = platform.system()
try: try:
if current_platform == "Windows": if get_platform() == "Windows":
subprocess.call(f"taskkill /F /T /PID {str(pid)}") 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) os.kill(pid, signal.SIGKILL)
else: else:
raise NotImplementedError(f"Unsupported platform: {current_platform}") raise NotImplementedError(f"Unsupported platform: {get_platform()}")
except Exception as e: except Exception as e:
print(f"Failed to terminate process {pid}: {e}") print(f"Failed to terminate process {pid}: {e}")

View File

@ -41,11 +41,11 @@ def test_mint_owner_token(keys_screen, main_window, user_account):
create_password_view = profile_view.next() create_password_view = profile_view.next()
confirm_password_view = create_password_view.create_password(user_account.password) confirm_password_view = create_password_view.create_password(user_account.password)
confirm_password_view.confirm_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() BiometricsView().wait_until_appears().prefer_password()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next()
if configs.system.IS_MAC: if configs.system.get_platform() == "Darwin":
next_view.start_using_status() next_view.start_using_status()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
if not configs.system.TEST_MODE: if not configs.system.TEST_MODE:

View File

@ -86,7 +86,7 @@ def test_generate_new_keys_sign_out_from_settings(aut, main_window, keys_screen,
with step('Confirm password and login'): with step('Confirm password and login'):
confirm_password_view.confirm_password(password) 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" assert BiometricsView().is_touch_id_button_visible(), f"TouchID button is not found"
BiometricsView().wait_until_appears().prefer_password() BiometricsView().wait_until_appears().prefer_password()
SplashScreen().wait_until_appears().wait_until_hidden() 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'): with step('Click Start using Status'):
next_view = emoji_hash_identicon_view.next() next_view = emoji_hash_identicon_view.next()
if configs.system.IS_MAC: if configs.system.get_platform() == "Darwin":
next_view.start_using_status() next_view.start_using_status()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
if not configs.system.TEST_MODE: if not configs.system.TEST_MODE:

View File

@ -45,11 +45,11 @@ def test_import_seed_phrase(keys_screen, main_window, aut: AUT, user_account, de
create_password_view = profile_view.next() create_password_view = profile_view.next()
confirm_password_view = create_password_view.create_password(user_account.password) confirm_password_view = create_password_view.create_password(user_account.password)
confirm_password_view.confirm_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() BiometricsView().wait_until_appears().prefer_password()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next()
if configs.system.IS_MAC: if configs.system.get_platform() == "Darwin":
next_view.start_using_status() next_view.start_using_status()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
if not configs.system.TEST_MODE: if not configs.system.TEST_MODE:

View File

@ -45,11 +45,11 @@ def test_login_with_wrong_password(aut: AUT, keys_screen, main_window, error: st
create_password_view = profile_view.next() create_password_view = profile_view.next()
confirm_password_view = create_password_view.create_password(user_one.password) confirm_password_view = create_password_view.create_password(user_one.password)
confirm_password_view.confirm_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() BiometricsView().wait_until_appears().prefer_password()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next()
if configs.system.IS_MAC: if configs.system.get_platform() == "Darwin":
next_view.start_using_status() next_view.start_using_status()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
if not configs.system.TEST_MODE: if not configs.system.TEST_MODE:

View File

@ -86,7 +86,7 @@ def test_sync_device_during_onboarding(multiple_instances):
sync_result.sign_in() sync_result.sign_in()
SplashScreen().wait_until_hidden() SplashScreen().wait_until_hidden()
YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next()
if configs.system.IS_MAC: if configs.system.get_platform() == "Darwin":
AllowNotificationsView().start_using_status() AllowNotificationsView().start_using_status()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
if not configs.system.TEST_MODE: if not configs.system.TEST_MODE:

View File

@ -46,11 +46,11 @@ def test_ens_name_purchase(keys_screen, main_window, user_account, ens_name):
create_password_view = profile_view.next() create_password_view = profile_view.next()
confirm_password_view = create_password_view.create_password(user_account.password) confirm_password_view = create_password_view.create_password(user_account.password)
confirm_password_view.confirm_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() BiometricsView().wait_until_appears().prefer_password()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next()
if configs.system.IS_MAC: if configs.system.get_platform() == "Darwin":
next_view.start_using_status() next_view.start_using_status()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
if not configs.system.TEST_MODE: if not configs.system.TEST_MODE:

View File

@ -44,11 +44,11 @@ def test_wallet_send_0_eth(keys_screen, main_window, user_account, receiver_acco
create_password_view = profile_view.next() create_password_view = profile_view.next()
confirm_password_view = create_password_view.create_password(user_account.password) confirm_password_view = create_password_view.create_password(user_account.password)
confirm_password_view.confirm_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() BiometricsView().wait_until_appears().prefer_password()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next()
if configs.system.IS_MAC: if configs.system.get_platform() == "Darwin":
next_view.start_using_status() next_view.start_using_status()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
if not configs.system.TEST_MODE: if not configs.system.TEST_MODE:

View File

@ -44,11 +44,11 @@ def test_wallet_send_nft(keys_screen, main_window, user_account, tab, receiver_a
create_password_view = profile_view.next() create_password_view = profile_view.next()
confirm_password_view = create_password_view.create_password(user_account.password) confirm_password_view = create_password_view.create_password(user_account.password)
confirm_password_view.confirm_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() BiometricsView().wait_until_appears().prefer_password()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next() next_view = YourEmojihashAndIdenticonRingView().verify_emojihash_view_present().next()
if configs.system.IS_MAC: if configs.system.get_platform() == "Darwin":
next_view.start_using_status() next_view.start_using_status()
SplashScreen().wait_until_appears().wait_until_hidden() SplashScreen().wait_until_appears().wait_until_hidden()
if not configs.system.TEST_MODE: if not configs.system.TEST_MODE: