2024-08-07 16:26:51 +00:00
|
|
|
import time
|
|
|
|
|
2024-04-02 14:59:56 +00:00
|
|
|
import pytest
|
2019-08-16 10:14:23 +00:00
|
|
|
|
|
|
|
from tests import common_password
|
2024-06-12 22:55:38 +00:00
|
|
|
from views.base_element import Button, EditBox, Text, BaseElement
|
2018-01-03 09:34:40 +00:00
|
|
|
from views.base_view import BaseView
|
2024-04-02 14:59:56 +00:00
|
|
|
from views.home_view import HomeView
|
|
|
|
from views.sign_in_view import SignInView
|
2017-10-19 13:49:20 +00:00
|
|
|
|
|
|
|
|
2024-04-02 14:59:56 +00:00
|
|
|
class AssetElement(Button):
|
2017-10-19 13:49:20 +00:00
|
|
|
|
2018-06-29 17:27:30 +00:00
|
|
|
def __init__(self, driver, asset_name):
|
2024-04-02 14:59:56 +00:00
|
|
|
self.asset_name = asset_name
|
|
|
|
self.locator = "//android.view.ViewGroup[@content-desc='container']/android.widget.TextView[@text='%s']" % \
|
|
|
|
self.asset_name
|
|
|
|
super().__init__(driver=driver, xpath=self.locator)
|
|
|
|
|
|
|
|
def get_amount(self):
|
|
|
|
element = Text(self.driver, xpath=self.locator + "/../android.widget.TextView[3]")
|
|
|
|
element.scroll_to_element(down_start_y=0.89, down_end_y=0.8)
|
|
|
|
try:
|
|
|
|
amount = element.text.split()[0]
|
|
|
|
if '<' in amount:
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
return float(amount)
|
|
|
|
except ValueError:
|
|
|
|
pytest.fail("Cannot get %s amount" % self.asset_name)
|
2019-08-16 10:14:23 +00:00
|
|
|
|
|
|
|
|
2024-06-12 22:55:38 +00:00
|
|
|
class ActivityElement(BaseElement):
|
|
|
|
def __init__(self, driver, index: int):
|
|
|
|
self.locator = "(//*[@content-desc='wallet-activity'])[%s]" % index
|
|
|
|
super().__init__(driver=driver, xpath=self.locator)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def header(self):
|
|
|
|
return Text(self.driver, prefix=self.locator, xpath="//*[@content-desc='transaction-header']").text
|
|
|
|
|
|
|
|
@property
|
|
|
|
def timestamp(self):
|
|
|
|
return Text(self.driver, prefix=self.locator, xpath="//*[@content-desc='transaction-timestamp']").text
|
|
|
|
|
|
|
|
@property
|
|
|
|
def amount(self):
|
|
|
|
return Text(self.driver, prefix=self.locator,
|
|
|
|
xpath="//*[@content-desc='context-tag'][1]/android.widget.TextView").text
|
|
|
|
|
|
|
|
@property
|
|
|
|
def from_text(self):
|
|
|
|
return Text(self.driver, prefix=self.locator,
|
|
|
|
xpath="//*[@content-desc='context-tag'][2]/android.widget.TextView").text
|
|
|
|
|
|
|
|
@property
|
|
|
|
def to_text(self):
|
|
|
|
return Text(self.driver, prefix=self.locator,
|
|
|
|
xpath="//*[@content-desc='context-tag'][3]/android.widget.TextView").text
|
|
|
|
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
class WalletView(BaseView):
|
2017-10-19 13:49:20 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver)
|
2024-04-02 14:59:56 +00:00
|
|
|
# Wallet view
|
2024-05-14 20:13:02 +00:00
|
|
|
self.network_drop_down = Button(self.driver, accessibility_id='network-dropdown')
|
2024-06-12 22:55:38 +00:00
|
|
|
self.collectibles_tab = Button(self.driver, accessibility_id='collectibles-tab')
|
2024-04-02 14:59:56 +00:00
|
|
|
self.add_account_button = Button(self.driver, accessibility_id='add-account')
|
|
|
|
|
|
|
|
# Account adding
|
|
|
|
# ToDo: add unique accessibility ids for the next 2 elements:
|
|
|
|
self.create_account_button = HomeView(self.driver).start_a_new_chat_bottom_sheet_button
|
|
|
|
self.add_account_to_watch = HomeView(self.driver).add_a_contact_chat_bottom_sheet_button
|
|
|
|
self.address_to_watch_input = EditBox(self.driver, accessibility_id='add-address-to-watch')
|
|
|
|
self.account_has_activity_label = Text(self.driver, accessibility_id='account-has-activity')
|
|
|
|
self.add_account_continue_button = Button(self.driver, accessibility_id='Continue')
|
|
|
|
self.add_watched_address_button = Button(self.driver, accessibility_id='confirm-button-label')
|
|
|
|
|
|
|
|
# Account view
|
|
|
|
self.close_account_button = Button(self.driver, accessibility_id='top-bar')
|
|
|
|
self.account_name_text = Text(
|
|
|
|
self.driver, xpath="//*[@content-desc='account-avatar']/../following-sibling::android.widget.TextView[1]")
|
|
|
|
self.account_emoji_button = Button(self.driver, accessibility_id='account-emoji')
|
|
|
|
self.send_button = Button(self.driver, accessibility_id='send')
|
2024-05-03 09:17:22 +00:00
|
|
|
self.send_from_drawer_button = Button(
|
|
|
|
self.driver, xpath="//*[@content-desc='send']/*[@content-desc='left-icon-for-action']")
|
2024-04-02 14:59:56 +00:00
|
|
|
self.copy_address_button = Button(self.driver, accessibility_id='copy-address')
|
|
|
|
self.share_address_button = Button(self.driver, accessibility_id='share-account')
|
|
|
|
self.remove_account_button = Button(self.driver, accessibility_id='remove-account')
|
|
|
|
self.derivation_path_note_checkbox = Button(self.driver, accessibility_id='checkbox-off')
|
|
|
|
|
2024-06-12 22:55:38 +00:00
|
|
|
self.activity_tab = Button(self.driver, accessibility_id='activity-tab')
|
|
|
|
|
2024-04-02 14:59:56 +00:00
|
|
|
# Sending transaction
|
|
|
|
self.address_text_input = EditBox(self.driver, accessibility_id='address-text-input')
|
|
|
|
self.amount_input = EditBox(self.driver, xpath="//android.widget.EditText")
|
2024-07-17 16:39:41 +00:00
|
|
|
self.from_network_text = Text(
|
|
|
|
self.driver, xpath="(//*[@content-desc='loading']/following-sibling::android.widget.TextView)[1]")
|
2024-04-02 14:59:56 +00:00
|
|
|
self.confirm_button = Button(self.driver, accessibility_id='button-one')
|
|
|
|
self.done_button = Button(self.driver, accessibility_id='done')
|
|
|
|
|
2024-07-17 16:39:41 +00:00
|
|
|
def select_network(self, network_name: str):
|
|
|
|
self.network_drop_down.click()
|
|
|
|
Button(self.driver, accessibility_id="%s, label-component" % network_name.capitalize()).click()
|
|
|
|
self.network_drop_down.click()
|
|
|
|
|
2024-04-02 14:59:56 +00:00
|
|
|
def get_account_element(self, account_name: str = 'Account 1'):
|
|
|
|
return Button(self.driver, xpath="//android.view.ViewGroup[contains(@content-desc,'%s')]" % account_name)
|
|
|
|
|
|
|
|
def get_asset(self, asset_name: str):
|
|
|
|
element = AssetElement(driver=self.driver, asset_name=asset_name)
|
|
|
|
element.scroll_to_element(down_start_y=0.89, down_end_y=0.8)
|
|
|
|
return element
|
|
|
|
|
|
|
|
def select_asset(self, asset_name: str):
|
|
|
|
return Button(driver=self.driver,
|
|
|
|
xpath="//*[@content-desc='token-network']/android.widget.TextView[@text='%s']" % asset_name)
|
|
|
|
|
|
|
|
def slide_and_confirm_with_password(self):
|
|
|
|
self.slide_button_track.slide()
|
|
|
|
self.password_input.send_keys(common_password)
|
|
|
|
self.login_button.click()
|
|
|
|
|
|
|
|
def confirm_transaction(self):
|
2024-08-07 16:26:51 +00:00
|
|
|
self.confirm_button.click()
|
|
|
|
for _ in range(3):
|
|
|
|
if self.slide_button_track.is_element_displayed():
|
|
|
|
break
|
|
|
|
time.sleep(1)
|
|
|
|
self.confirm_button.click()
|
2024-04-02 14:59:56 +00:00
|
|
|
self.slide_and_confirm_with_password()
|
|
|
|
|
2024-04-25 09:11:47 +00:00
|
|
|
def set_amount(self, amount: float):
|
|
|
|
for i in '{:f}'.format(amount).rstrip('0'):
|
|
|
|
Button(self.driver, accessibility_id='keyboard-key-%s' % i).click()
|
|
|
|
|
2024-07-17 16:39:41 +00:00
|
|
|
def disable_mainnet_in_from_network(self):
|
|
|
|
if self.from_network_text.text == 'Mainnet':
|
|
|
|
self.from_network_text.click()
|
|
|
|
|
2024-04-02 14:59:56 +00:00
|
|
|
def send_asset(self, address: str, asset_name: str, amount: float):
|
|
|
|
self.send_button.click()
|
|
|
|
self.address_text_input.send_keys(address)
|
2024-06-12 22:55:38 +00:00
|
|
|
self.continue_button.click()
|
2024-04-02 14:59:56 +00:00
|
|
|
self.select_asset(asset_name).click()
|
2024-04-25 09:11:47 +00:00
|
|
|
self.set_amount(amount)
|
2024-07-17 16:39:41 +00:00
|
|
|
self.disable_mainnet_in_from_network()
|
2024-04-02 14:59:56 +00:00
|
|
|
self.confirm_transaction()
|
|
|
|
|
|
|
|
def send_asset_from_drawer(self, address: str, asset_name: str, amount: float):
|
|
|
|
asset_element = self.get_asset(asset_name)
|
|
|
|
asset_element.long_press_element()
|
2024-05-03 09:17:22 +00:00
|
|
|
self.send_from_drawer_button.click()
|
2024-04-02 14:59:56 +00:00
|
|
|
self.address_text_input.send_keys(address)
|
2024-06-12 22:55:38 +00:00
|
|
|
self.continue_button.click()
|
2024-04-25 09:11:47 +00:00
|
|
|
self.set_amount(amount)
|
2024-07-17 16:39:41 +00:00
|
|
|
self.disable_mainnet_in_from_network()
|
2024-04-02 14:59:56 +00:00
|
|
|
self.confirm_transaction()
|
|
|
|
|
|
|
|
def add_regular_account(self, account_name: str):
|
2019-08-16 10:14:23 +00:00
|
|
|
self.add_account_button.click()
|
2024-04-02 14:59:56 +00:00
|
|
|
self.create_account_button.click()
|
|
|
|
SignInView(self.driver).profile_title_input.send_keys(account_name)
|
|
|
|
self.slide_and_confirm_with_password()
|
2021-10-15 10:26:36 +00:00
|
|
|
|
2024-04-02 14:59:56 +00:00
|
|
|
def add_watch_only_account(self, address: str, account_name: str):
|
|
|
|
self.add_account_button.click()
|
|
|
|
self.add_account_to_watch.click()
|
|
|
|
self.address_to_watch_input.send_keys(address)
|
|
|
|
self.add_account_continue_button.click()
|
|
|
|
SignInView(self.driver).profile_title_input.send_keys(account_name)
|
|
|
|
self.add_watched_address_button.click()
|
|
|
|
|
|
|
|
def remove_account(self, account_name: str, watch_only: bool = False):
|
|
|
|
self.get_account_element(account_name=account_name).click()
|
|
|
|
self.account_emoji_button.click()
|
|
|
|
self.remove_account_button.click()
|
|
|
|
if not watch_only:
|
|
|
|
self.derivation_path_note_checkbox.click()
|
|
|
|
self.confirm_button.click()
|
2024-06-12 22:55:38 +00:00
|
|
|
|
|
|
|
def get_activity_element(self, index=1):
|
|
|
|
return ActivityElement(self.driver, index=index)
|