2018-09-17 08:50:01 +00:00
|
|
|
from tests import common_password
|
2021-01-25 16:35:40 +00:00
|
|
|
from views.base_element import Text, SilentButton
|
|
|
|
from views.base_element import Button, EditBox
|
|
|
|
from views.base_view import BaseView
|
2018-01-03 09:34:40 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class AmountEditBox(EditBox, Button):
|
2018-01-03 09:34:40 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super(AmountEditBox, self).__init__(driver, accessibility_id="amount-input")
|
2018-01-03 09:34:40 +00:00
|
|
|
|
2020-09-17 13:14:55 +00:00
|
|
|
def set_value(self, value):
|
2021-01-25 16:35:40 +00:00
|
|
|
EditBox.set_value(self, value)
|
2020-09-17 13:14:55 +00:00
|
|
|
self.driver.press_keycode(66)
|
|
|
|
|
2020-07-29 15:54:45 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class ChooseRecipientButton(Button):
|
2020-07-29 15:54:45 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super(ChooseRecipientButton, self).__init__(driver, accessibility_id="choose-recipient-button")
|
2018-01-03 09:34:40 +00:00
|
|
|
|
2020-10-14 12:09:01 +00:00
|
|
|
def click(self):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.click_until_presence_of_element(Button(self.driver, translation_id="my-accounts"))
|
2020-10-14 12:09:01 +00:00
|
|
|
return self.navigate()
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
|
2018-06-28 18:46:51 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class UpdateFeeButton(Button):
|
2018-06-28 18:46:51 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super(UpdateFeeButton, self).__init__(driver, translation_id="update")
|
2018-06-28 18:46:51 +00:00
|
|
|
|
2019-10-21 07:15:06 +00:00
|
|
|
def click(self):
|
|
|
|
for _ in range(3):
|
|
|
|
self.find_element().click()
|
2019-10-23 17:17:54 +00:00
|
|
|
if not self.is_element_displayed():
|
2019-10-21 07:15:06 +00:00
|
|
|
return self.navigate()
|
|
|
|
|
2018-06-28 18:46:51 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class ValidationErrorOnSendTransaction(Button):
|
2020-06-24 13:25:53 +00:00
|
|
|
def __init__(self, driver, field):
|
2021-01-25 16:35:40 +00:00
|
|
|
super(ValidationErrorOnSendTransaction, self).__init__(driver, xpath="//*[@text='%s']/../*[@content-desc='icon']" % field)
|
2018-10-07 15:12:21 +00:00
|
|
|
|
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class NotEnoughEthForGas(Text):
|
2018-11-26 14:06:34 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, translation_id="wallet-insufficient-gas")
|
2018-11-26 14:06:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ValidationWarnings(object):
|
|
|
|
def __init__(self, driver):
|
|
|
|
self.not_enough_eth_for_gas = NotEnoughEthForGas(driver)
|
|
|
|
|
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class SignWithKeycardButton(Button):
|
2019-06-12 08:38:02 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super(SignWithKeycardButton, self).__init__(driver, xpath="//*[contains(@text,'%s')]" % self.get_translation_by_key("sign-with"))
|
2020-05-14 10:41:09 +00:00
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
from views.keycard_view import KeycardView
|
|
|
|
return KeycardView(self.driver)
|
|
|
|
|
|
|
|
def click(self):
|
2021-01-25 16:35:40 +00:00
|
|
|
from views.keycard_view import KeycardView
|
2021-06-23 15:12:42 +00:00
|
|
|
self.click_until_presence_of_element(KeycardView(self.driver).two_button)
|
2020-05-14 10:41:09 +00:00
|
|
|
return self.navigate()
|
|
|
|
|
2020-04-02 10:30:20 +00:00
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
class SendTransactionView(BaseView):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(SendTransactionView, self).__init__(driver)
|
|
|
|
|
|
|
|
self.chose_recipient_button = ChooseRecipientButton(self.driver)
|
2021-01-25 16:35:40 +00:00
|
|
|
self.accounts_button = Button(self.driver, translation_id="my-accounts")
|
|
|
|
self.enter_recipient_address_button = Button(self.driver, accessibility_id="choose-recipient-recipient-code")
|
|
|
|
self.scan_qr_code_button = Button(self.driver, accessibility_id="scan-contact-code-button")
|
|
|
|
self.enter_recipient_address_input = EditBox(self.driver, accessibility_id="recipient-address-input")
|
|
|
|
self.first_recipient_button = Button(self.driver, accessibility_id="chat-icon")
|
|
|
|
self.enter_recipient_address_text = Text(self.driver, xpath="//*[@content-desc='choose-recipient-button']//android.widget.TextView")
|
|
|
|
|
|
|
|
self.recent_recipients_button = Button(self.driver, translation_id="recent-recipients")
|
2018-01-03 09:34:40 +00:00
|
|
|
self.amount_edit_box = AmountEditBox(self.driver)
|
2021-01-25 16:35:40 +00:00
|
|
|
self.set_max_button = Button(self.driver, translation_id="set-max")
|
|
|
|
self.validation_error_element = Text(self.driver, xpath="//*[@content-desc='custom-gas-fee']/../android.view.ViewGroup//*[@content-desc='icon']")
|
2018-06-28 18:46:51 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
self.network_fee_button = Button(self.driver, accessibility_id="custom-gas-fee")
|
2021-09-02 16:00:55 +00:00
|
|
|
self.gas_limit_input = EditBox(self.driver, accessibility_id="gas-amount-limit")
|
|
|
|
self.per_gas_tip_limit_input = EditBox(self.driver, accessibility_id="per-gas-tip-limit")
|
|
|
|
self.per_gas_price_limit_input = EditBox(self.driver, accessibility_id="per-gas-tip-limit")
|
2021-08-20 09:47:30 +00:00
|
|
|
|
2018-06-28 18:46:51 +00:00
|
|
|
|
2018-01-26 11:07:09 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
self.sign_transaction_button = Button(self.driver, accessibility_id="send-transaction-bottom-sheet")
|
|
|
|
self.sign_with_keycard_button = SignWithKeycardButton(self.driver)
|
|
|
|
self.sign_with_password = Button(self.driver, translation_id="sign-with-password")
|
|
|
|
self.sign_button = Button(self.driver, translation_id="transactions-sign")
|
|
|
|
self.sign_in_phrase_text = Text(self.driver, accessibility_id="signing-phrase-text")
|
|
|
|
self.enter_password_input = EditBox(self.driver, accessibility_id="enter-password-input")
|
|
|
|
self.got_it_button = Button(self.driver, accessibility_id="got-it-button")
|
2018-02-09 15:16:07 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
self.select_asset_button = Button(self.driver, accessibility_id="choose-asset-button")
|
|
|
|
self.asset_text = Text(self.driver, xpath="//*[@content-desc='choose-asset-button']//android.widget.TextView")
|
|
|
|
self.recipient_text = Text(self.driver, xpath="//*[@content-desc='choose-recipient-button']//android.widget.TextView")
|
2018-04-23 18:42:12 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
self.share_button = Button(self.driver, accessibility_id="share-address-button")
|
2018-06-29 17:27:30 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
self.onboarding_message = Text(self.driver, translation_id="this-is-you-signing")
|
2018-11-26 14:06:34 +00:00
|
|
|
self.validation_warnings = ValidationWarnings(self.driver)
|
2021-01-25 16:35:40 +00:00
|
|
|
self.eth_asset_in_select_asset_bottom_sheet_button = Button(self.driver, accessibility_id=":ETH-asset-value")
|
2018-10-07 15:12:21 +00:00
|
|
|
|
2020-03-24 15:45:15 +00:00
|
|
|
# Elements for commands in 1-1 chat
|
2021-01-25 16:35:40 +00:00
|
|
|
self.select_button = Button(self.driver, accessibility_id="select-account-bottom-sheet")
|
|
|
|
self.request_transaction_button = Button(self.driver, accessibility_id="request-transaction-bottom-sheet")
|
2020-03-24 15:45:15 +00:00
|
|
|
|
2020-10-06 14:48:08 +00:00
|
|
|
# Elements on set recipient screen
|
2021-01-25 16:35:40 +00:00
|
|
|
self.recipient_add_to_favorites = Button(self.driver, accessibility_id="participant-add-to-favs")
|
|
|
|
self.recipient_done = Button(self.driver, accessibility_id="participant-done")
|
|
|
|
self.new_favorite_name_input = EditBox(self.driver, accessibility_id="fav-name")
|
|
|
|
self.new_favorite_add_favorite = Button(self.driver, accessibility_id="add-fav")
|
2020-10-06 14:48:08 +00:00
|
|
|
|
2018-11-07 13:09:23 +00:00
|
|
|
|
2020-09-17 13:14:55 +00:00
|
|
|
def set_recipient_address(self, address):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Setting recipient address to %s**" % address)
|
2020-09-17 13:14:55 +00:00
|
|
|
self.chose_recipient_button.click()
|
|
|
|
self.enter_recipient_address_input.set_value(address)
|
|
|
|
self.enter_recipient_address_input.click()
|
2020-11-26 17:33:43 +00:00
|
|
|
self.done_button.click_until_absense_of_element(self.done_button)
|
2020-09-17 13:14:55 +00:00
|
|
|
|
2021-08-20 09:47:30 +00:00
|
|
|
def sign_transaction(self, sender_password: str = common_password, keycard=False, default_gas_price=True):
|
2021-08-19 11:41:41 +00:00
|
|
|
self.driver.info("**Signing transaction (keycard:%s, default gas price:%s)**" % (str(keycard), str(default_gas_price)))
|
|
|
|
if self.sign_in_phrase.is_element_displayed(30):
|
2021-06-14 17:52:58 +00:00
|
|
|
self.set_up_wallet_when_sending_tx()
|
2020-05-15 11:51:05 +00:00
|
|
|
if not default_gas_price:
|
|
|
|
self.network_fee_button.click()
|
2021-08-20 09:47:30 +00:00
|
|
|
# to be updated with new fast/slow/normal fee
|
2020-05-14 10:41:09 +00:00
|
|
|
if keycard:
|
|
|
|
keycard_view = self.sign_with_keycard_button.click()
|
|
|
|
keycard_view.enter_default_pin()
|
|
|
|
else:
|
|
|
|
self.sign_with_password.click_until_presence_of_element(self.enter_password_input)
|
|
|
|
self.enter_password_input.send_keys(sender_password)
|
|
|
|
self.sign_button.click_until_absense_of_element(self.sign_button)
|
2019-12-20 17:35:36 +00:00
|
|
|
self.ok_button.wait_for_element(120)
|
2020-12-03 12:59:20 +00:00
|
|
|
if self.element_by_text_part('Transaction failed').is_element_displayed():
|
|
|
|
self.driver.fail('Transaction failed')
|
2021-02-04 12:51:01 +00:00
|
|
|
self.driver.info("**Transaction is signed!**")
|
2019-06-12 08:38:02 +00:00
|
|
|
self.ok_button.click()
|
2019-02-15 16:14:42 +00:00
|
|
|
|
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_formatted_recipient_address(address):
|
2019-11-29 17:32:47 +00:00
|
|
|
return address[:6] + '…' + address[-4:]
|
|
|
|
|
2020-03-24 15:45:15 +00:00
|
|
|
def get_username_in_transaction_bottom_sheet_button(self, username_part):
|
2021-02-04 12:51:01 +00:00
|
|
|
self.driver.info("**Getting username by '%s' in transaction fee bottom sheet**" % username_part)
|
2021-01-25 16:35:40 +00:00
|
|
|
return SilentButton(self.driver, xpath="//*[@content-desc='amount-input']/..//*[starts-with(@text,'%s')]" % username_part)
|
2020-03-24 15:45:15 +00:00
|
|
|
|
|
|
|
def get_account_in_select_account_bottom_sheet_button(self, account_name):
|
2021-02-04 12:51:01 +00:00
|
|
|
self.driver.info("**Getting account by '%s' in transaction fee bottom sheet**" % account_name)
|
2021-01-25 16:35:40 +00:00
|
|
|
return SilentButton(self.driver, translation_id="select-account", suffix="/..//*[starts-with(@text,'%s')]" % account_name)
|
2020-03-24 15:45:15 +00:00
|
|
|
|
2020-06-24 13:25:53 +00:00
|
|
|
def get_validation_icon(self, field='Network fee'):
|
|
|
|
return ValidationErrorOnSendTransaction(self.driver, field)
|
|
|
|
|
2020-04-15 14:25:18 +00:00
|
|
|
def get_values_from_send_transaction_bottom_sheet(self, gas=False):
|
2021-02-04 12:51:01 +00:00
|
|
|
self.driver.info("**Getting values from send transaction bottom sheet**")
|
2020-04-15 14:25:18 +00:00
|
|
|
data = {
|
|
|
|
'amount': self.amount_edit_box.text,
|
|
|
|
'asset': self.asset_text.text,
|
2020-10-20 15:34:52 +00:00
|
|
|
'address': self.enter_recipient_address_text.text
|
2020-04-15 14:25:18 +00:00
|
|
|
}
|
|
|
|
if gas:
|
|
|
|
self.sign_transaction_button.click_until_presence_of_element(self.sign_with_password)
|
|
|
|
self.network_fee_button.click_until_presence_of_element(self.gas_limit_input)
|
|
|
|
data['gas_limit'] = self.gas_limit_input.text
|
|
|
|
data['gas_price'] = self.gas_price_input.text
|
|
|
|
self.cancel_button.click()
|
|
|
|
return data
|
2020-10-06 14:48:08 +00:00
|
|
|
|
|
|
|
def add_to_favorites(self, name):
|
2021-02-04 12:51:01 +00:00
|
|
|
self.driver.info("**Adding '%s' to favorite recipients**" % name)
|
2020-10-06 14:48:08 +00:00
|
|
|
self.recipient_add_to_favorites.click()
|
|
|
|
self.new_favorite_name_input.set_value(name)
|
|
|
|
self.new_favorite_add_favorite.click()
|