2024-04-18 11:18:01 +00:00
|
|
|
import time
|
|
|
|
|
2023-12-05 13:23:02 +00:00
|
|
|
import allure
|
2024-04-05 13:04:04 +00:00
|
|
|
import typing
|
2023-12-05 13:23:02 +00:00
|
|
|
|
2024-04-18 11:18:01 +00:00
|
|
|
import configs.timeouts
|
2023-12-05 13:23:02 +00:00
|
|
|
import driver
|
2024-05-03 14:36:52 +00:00
|
|
|
from driver.objects_access import wait_for_template, walk_children
|
2023-12-05 13:23:02 +00:00
|
|
|
from gui.components.base_popup import BasePopup
|
|
|
|
from gui.elements.button import Button
|
|
|
|
from gui.elements.object import QObject
|
|
|
|
from gui.elements.text_edit import TextEdit
|
|
|
|
from gui.elements.text_label import TextLabel
|
2024-02-13 09:04:24 +00:00
|
|
|
from gui.objects_map import names
|
2023-12-05 13:23:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SendPopup(BasePopup):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
2024-05-03 14:36:52 +00:00
|
|
|
self._tokens_list = QObject(names.statusListView)
|
2024-02-13 09:04:24 +00:00
|
|
|
self._tab_item_template = QObject(names.tab_Status_template)
|
|
|
|
self._search_field = TextEdit(names.search_TextEdit)
|
|
|
|
self._asset_list_item = QObject(names.o_TokenBalancePerChainDelegate_template)
|
2024-04-10 11:37:41 +00:00
|
|
|
self._collectible_list_item = QObject(names.o_CollectibleNestedDelegate_template)
|
2024-02-13 09:04:24 +00:00
|
|
|
self._amount_text_edit = TextEdit(names.amountInput_TextEdit)
|
|
|
|
self._paste_button = Button(names.paste_StatusButton)
|
|
|
|
self._ens_address_text_edit = TextEdit(names.ens_or_address_TextEdit)
|
|
|
|
self._my_accounts_tab = Button(names.accountSelectionTabBar_My_Accounts_StatusTabButton)
|
|
|
|
self._account_list_item = QObject(names.status_account_WalletAccountListItem_template)
|
|
|
|
self._arbitrum_network = QObject(names.arbitrum_StatusListItem)
|
|
|
|
self._mainnet_network = QObject(names.mainnet_StatusListItem)
|
|
|
|
self._fiat_fees_label = TextLabel(names.fiatFees_StatusBaseText)
|
|
|
|
self._send_button = Button(names.send_StatusFlatButton)
|
2023-12-05 13:23:02 +00:00
|
|
|
|
2024-04-10 11:37:41 +00:00
|
|
|
@allure.step('Select asset or collectible by name')
|
2024-04-18 11:18:01 +00:00
|
|
|
def _select_asset_or_collectible(self, name: str, tab: str, attempts: int = 2):
|
2024-05-03 14:36:52 +00:00
|
|
|
if tab == 'Assets':
|
|
|
|
self._asset_list_item.wait_until_appears(timeout_msec=10000)
|
|
|
|
assets = self.get_assets_or_collectibles_list(tab)
|
|
|
|
for index, item in enumerate(assets):
|
|
|
|
if getattr(item, 'title', '') == name:
|
|
|
|
QObject(item).click()
|
|
|
|
break
|
|
|
|
assert driver.waitFor(lambda: self._amount_text_edit.is_visible, timeout_msec=6000)
|
|
|
|
|
|
|
|
elif tab == 'Collectibles':
|
|
|
|
self._collectible_list_item.wait_until_appears(timeout_msec=15000)
|
|
|
|
self._search_field.type_text(name)
|
|
|
|
time.sleep(3)
|
|
|
|
assets = self.get_assets_or_collectibles_list(tab)
|
|
|
|
for index, item in enumerate(assets):
|
|
|
|
if getattr(item, 'title', '') == name:
|
|
|
|
QObject(item).click()
|
|
|
|
break
|
|
|
|
try:
|
|
|
|
return self._ens_address_text_edit.wait_until_appears(timeout_msec=configs.timeouts.UI_LOAD_TIMEOUT_MSEC)
|
|
|
|
except AssertionError as err:
|
|
|
|
if attempts:
|
|
|
|
self._select_asset_or_collectible(attempts-1)
|
|
|
|
else:
|
|
|
|
raise err
|
2024-04-05 13:04:04 +00:00
|
|
|
|
2024-04-10 11:37:41 +00:00
|
|
|
@allure.step('Get assets or collectibles list')
|
|
|
|
def get_assets_or_collectibles_list(self, tab: str) -> typing.List[str]:
|
|
|
|
assets_or_collectibles_list = []
|
|
|
|
if tab == 'Assets':
|
|
|
|
for asset in driver.findAllObjects(self._asset_list_item.real_name):
|
|
|
|
assets_or_collectibles_list.append(asset)
|
|
|
|
elif tab == 'Collectibles':
|
2024-05-03 14:36:52 +00:00
|
|
|
for asset in walk_children(self._tokens_list.object):
|
2024-04-10 11:37:41 +00:00
|
|
|
assets_or_collectibles_list.append(asset)
|
|
|
|
return assets_or_collectibles_list
|
2023-12-05 13:23:02 +00:00
|
|
|
|
2024-04-10 11:37:41 +00:00
|
|
|
@allure.step('Open tab')
|
2023-12-05 13:23:02 +00:00
|
|
|
def _open_tab(self, name: str):
|
|
|
|
assets_tab = wait_for_template(self._tab_item_template.real_name, name, 'text')
|
|
|
|
driver.mouseClick(assets_tab)
|
|
|
|
|
|
|
|
@allure.step('Send {2} {3} to {1}')
|
2024-04-10 11:37:41 +00:00
|
|
|
def send(self, address: str, amount: int, name: str, tab: str):
|
|
|
|
self._open_tab(tab)
|
|
|
|
self._select_asset_or_collectible(name, tab)
|
|
|
|
if tab == 'Assets':
|
|
|
|
self._amount_text_edit.text = str(amount)
|
2024-05-03 14:36:52 +00:00
|
|
|
self._ens_address_text_edit.wait_until_appears(timeout_msec=configs.timeouts.UI_LOAD_TIMEOUT_MSEC)
|
2023-12-05 13:23:02 +00:00
|
|
|
self._ens_address_text_edit.type_text(address)
|
2024-04-10 11:37:41 +00:00
|
|
|
assert driver.waitFor(lambda: self._send_button.is_visible, timeout_msec=8000)
|
2023-12-11 07:20:57 +00:00
|
|
|
self.click_send()
|
|
|
|
|
|
|
|
@allure.step('Click send button')
|
|
|
|
def click_send(self):
|
2023-12-05 13:23:02 +00:00
|
|
|
self._send_button.click()
|
|
|
|
|
2024-04-10 11:37:41 +00:00
|
|
|
@allure.step('Get arbitrum network visibility state')
|
2023-12-05 13:23:02 +00:00
|
|
|
def is_arbitrum_network_identified(self) -> bool:
|
|
|
|
return self._arbitrum_network.is_visible
|
|
|
|
|
2024-04-10 11:37:41 +00:00
|
|
|
@allure.step('Get mainnet network visibility state')
|
2023-12-05 13:23:02 +00:00
|
|
|
def is_mainnet_network_identified(self) -> bool:
|
|
|
|
return self._mainnet_network.is_visible
|
|
|
|
|
2024-04-10 11:37:41 +00:00
|
|
|
@allure.step('Get fiat fees')
|
2023-12-05 13:23:02 +00:00
|
|
|
def get_fiat_fees(self) -> str:
|
|
|
|
return self._fiat_fees_label.text
|