2017-10-23 20:46:49 +00:00
|
|
|
import time
|
|
|
|
from selenium.common.exceptions import NoSuchElementException
|
2021-01-25 16:35:40 +00:00
|
|
|
from views.base_element import BaseElement, Button, Text
|
2018-01-03 09:34:40 +00:00
|
|
|
from views.base_view import BaseView
|
2017-10-23 20:46:49 +00:00
|
|
|
|
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class OptionsButton(Button):
|
2018-04-23 18:42:12 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, xpath="(//android.view.ViewGroup[@content-desc='icon'])[2]")
|
2020-11-09 15:27:43 +00:00
|
|
|
def click(self):
|
|
|
|
self.click_until_presence_of_element(OptionsButton.CopyTransactionHashButton(self.driver))
|
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class CopyTransactionHashButton(Button):
|
2018-06-29 17:27:30 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, translation_id="copy-transaction-hash")
|
2018-06-29 17:27:30 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class OpenOnEtherscanButton(Button):
|
2018-04-23 18:42:12 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, translation_id="open-on-etherscan")
|
2018-04-23 18:42:12 +00:00
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
class TransactionTable(BaseElement):
|
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, xpath="//android.widget.ScrollView")
|
2017-10-23 20:46:49 +00:00
|
|
|
self.driver = driver
|
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class TransactionElement(Button):
|
2018-04-23 18:42:12 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver)
|
2018-04-23 18:42:12 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2020-05-14 10:41:09 +00:00
|
|
|
def by_amount(driver, amount: str, asset):
|
2018-04-23 18:42:12 +00:00
|
|
|
element = TransactionTable.TransactionElement(driver)
|
2021-01-25 16:35:40 +00:00
|
|
|
element.locator = "(//android.widget.TextView[contains(@text,'%s %s')])" % (amount, asset)
|
2018-04-23 18:42:12 +00:00
|
|
|
return element
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def by_index(driver, index: int):
|
|
|
|
element = TransactionTable.TransactionElement(driver)
|
2021-01-25 16:35:40 +00:00
|
|
|
element.locator = '(//android.view.ViewGroup[@content-desc="transaction-item"])[%d]' % (index + 1)
|
2018-04-23 18:42:12 +00:00
|
|
|
return element
|
2017-10-23 20:46:49 +00:00
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
class TransactionDetailsView(BaseView):
|
2017-10-23 20:46:49 +00:00
|
|
|
def __init__(self, driver):
|
2018-01-03 09:34:40 +00:00
|
|
|
super(TransactionTable.TransactionElement.TransactionDetailsView, self).__init__(driver)
|
2017-10-23 20:46:49 +00:00
|
|
|
self.driver = driver
|
2018-07-26 18:58:05 +00:00
|
|
|
self.locators = dict()
|
2018-04-23 18:42:12 +00:00
|
|
|
self.options_button = OptionsButton(driver)
|
2018-06-29 17:27:30 +00:00
|
|
|
self.copy_transaction_hash_button = OptionsButton.CopyTransactionHashButton(driver)
|
2018-04-23 18:42:12 +00:00
|
|
|
self.open_transaction_on_etherscan_button = OptionsButton.OpenOnEtherscanButton(driver)
|
2017-10-23 20:46:49 +00:00
|
|
|
|
2018-07-26 18:58:05 +00:00
|
|
|
self.locators['transaction_hash'] = "//android.widget.TextView[@text='Hash']/following-sibling::*[1]"
|
|
|
|
self.locators['sender_address'] = "//*[@content-desc='sender-address-text']"
|
2018-11-14 21:50:19 +00:00
|
|
|
self.locators['recipient_address'] = "//*[@content-desc='recipient-address-text'][last()]"
|
2018-07-26 18:58:05 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class DetailsTextElement(Text):
|
2017-10-23 20:46:49 +00:00
|
|
|
def __init__(self, driver, locator):
|
2018-01-03 09:34:40 +00:00
|
|
|
super(TransactionTable.TransactionElement.TransactionDetailsView.DetailsTextElement,
|
2017-10-23 20:46:49 +00:00
|
|
|
self).__init__(driver)
|
2021-01-25 16:35:40 +00:00
|
|
|
self.locator = locator
|
2017-10-23 20:46:49 +00:00
|
|
|
|
2018-10-11 20:28:52 +00:00
|
|
|
def text(self):
|
|
|
|
text = self.find_element().text
|
|
|
|
self.driver.info('%s is %s' % (self.name, text))
|
|
|
|
return text
|
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
def get_transaction_hash(self) -> str:
|
2018-10-11 20:28:52 +00:00
|
|
|
return self.DetailsTextElement(driver=self.driver, locator=self.locators['transaction_hash']).text()
|
2017-10-23 20:46:49 +00:00
|
|
|
|
2018-07-26 18:58:05 +00:00
|
|
|
def get_sender_address(self) -> str:
|
2018-10-11 20:28:52 +00:00
|
|
|
return self.DetailsTextElement(driver=self.driver, locator=self.locators['sender_address']).text()
|
2018-07-26 18:58:05 +00:00
|
|
|
|
|
|
|
def get_recipient_address(self) -> str:
|
2018-10-11 20:28:52 +00:00
|
|
|
return self.DetailsTextElement(driver=self.driver, locator=self.locators['recipient_address']).text()
|
2018-07-26 18:58:05 +00:00
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
def navigate(self):
|
2018-01-03 09:34:40 +00:00
|
|
|
return self.TransactionDetailsView(self.driver)
|
2017-10-23 20:46:49 +00:00
|
|
|
|
2018-07-26 18:58:05 +00:00
|
|
|
def transaction_by_index(self, index: int):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info('**Finding transaction by index %s**' % index)
|
2018-07-26 18:58:05 +00:00
|
|
|
return self.TransactionElement.by_index(self.driver, index=index)
|
|
|
|
|
2020-05-14 10:41:09 +00:00
|
|
|
def transaction_by_amount(self, amount: str, asset):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info('**Finding transaction by amount %s**' % amount)
|
2020-05-14 10:41:09 +00:00
|
|
|
return self.TransactionElement.by_amount(self.driver, amount=amount.replace(',', '.'), asset=asset)
|
2017-10-23 20:46:49 +00:00
|
|
|
|
2020-05-14 10:41:09 +00:00
|
|
|
def find_transaction(self, amount: str, asset='ETH') -> TransactionElement:
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info('**Finding %s %s transaction**' % (amount, asset))
|
2020-05-14 10:41:09 +00:00
|
|
|
element = self.transaction_by_amount(amount=amount, asset=asset)
|
2018-01-26 11:07:09 +00:00
|
|
|
for i in range(9):
|
2017-10-23 20:46:49 +00:00
|
|
|
try:
|
|
|
|
element.find_element()
|
|
|
|
return element
|
|
|
|
except NoSuchElementException:
|
2020-12-01 14:56:42 +00:00
|
|
|
time.sleep(20)
|
2018-04-23 18:42:12 +00:00
|
|
|
self.refresh_transactions()
|
2020-05-14 10:41:09 +00:00
|
|
|
self.driver.fail('Transaction %s %s was not found on Wallet/Transaction screen' %(amount, asset))
|
2017-10-23 20:46:49 +00:00
|
|
|
|
2018-04-23 18:42:12 +00:00
|
|
|
def refresh_transactions(self):
|
|
|
|
self.driver.swipe(500, 500, 500, 1000)
|
|
|
|
|
2018-07-26 18:58:05 +00:00
|
|
|
def get_transactions_number(self):
|
|
|
|
element = self.TransactionElement(self.driver)
|
2021-01-25 16:35:40 +00:00
|
|
|
element.locator = '//android.view.ViewGroup[@content-desc="transaction-item"]'
|
2018-08-29 14:04:12 +00:00
|
|
|
return len(element.wait_for_elements())
|
2017-10-23 20:46:49 +00:00
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
class TransactionsView(BaseView):
|
2017-10-23 20:46:49 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver)
|
2017-10-23 20:46:49 +00:00
|
|
|
self.transactions_table = TransactionTable(self.driver)
|