status-react/test/appium/views/transactions_view.py

135 lines
5.8 KiB
Python

import time
from selenium.common.exceptions import NoSuchElementException
from views.base_element import BaseElement, BaseButton, BaseText
from views.base_view import BaseView
class OptionsButton(BaseButton):
def __init__(self, driver):
super(OptionsButton, self).__init__(driver)
self.locator = self.Locator.xpath_selector(
'(//android.view.ViewGroup[@content-desc="icon"])[2]')
def click(self):
self.click_until_presence_of_element(OptionsButton.CopyTransactionHashButton(self.driver))
class CopyTransactionHashButton(BaseButton):
def __init__(self, driver):
super(OptionsButton.CopyTransactionHashButton, self).__init__(driver)
self.locator = self.Locator.text_selector('Copy transaction ID')
class OpenOnEtherscanButton(BaseButton):
def __init__(self, driver):
super(OptionsButton.OpenOnEtherscanButton, self).__init__(driver)
self.locator = self.Locator.text_selector('Open on Etherscan.io')
class TransactionTable(BaseElement):
def __init__(self, driver):
super(TransactionTable, self).__init__(driver)
self.driver = driver
self.locator = self.Locator.xpath_selector("//android.widget.ScrollView")
class TransactionElement(BaseButton):
def __init__(self, driver):
super(TransactionTable.TransactionElement, self).__init__(driver)
@staticmethod
def by_amount(driver, amount: str, asset):
element = TransactionTable.TransactionElement(driver)
element.locator = element.Locator.xpath_selector(
"(//android.widget.TextView[contains(@text,'%s %s')])" % (amount, asset))
return element
@staticmethod
def by_index(driver, index: int):
element = TransactionTable.TransactionElement(driver)
element.locator = element.Locator.xpath_selector(
'(//android.view.ViewGroup[@content-desc="transaction-item"])[%d]' % (index + 1))
return element
class TransactionDetailsView(BaseView):
def __init__(self, driver):
super(TransactionTable.TransactionElement.TransactionDetailsView, self).__init__(driver)
self.driver = driver
self.locators = dict()
self.options_button = OptionsButton(driver)
self.copy_transaction_hash_button = OptionsButton.CopyTransactionHashButton(driver)
self.open_transaction_on_etherscan_button = OptionsButton.OpenOnEtherscanButton(driver)
self.locators['transaction_hash'] = "//android.widget.TextView[@text='Hash']/following-sibling::*[1]"
self.locators['sender_address'] = "//*[@content-desc='sender-address-text']"
self.locators['recipient_address'] = "//*[@content-desc='recipient-address-text'][last()]"
class DetailsTextElement(BaseText):
def __init__(self, driver, locator):
super(TransactionTable.TransactionElement.TransactionDetailsView.DetailsTextElement,
self).__init__(driver)
self.locator = self.Locator.xpath_selector(locator)
def text(self):
text = self.find_element().text
self.driver.info('%s is %s' % (self.name, text))
return text
def get_transaction_hash(self) -> str:
return self.DetailsTextElement(driver=self.driver, locator=self.locators['transaction_hash']).text()
def get_sender_address(self) -> str:
return self.DetailsTextElement(driver=self.driver, locator=self.locators['sender_address']).text()
def get_recipient_address(self) -> str:
return self.DetailsTextElement(driver=self.driver, locator=self.locators['recipient_address']).text()
def navigate(self):
return self.TransactionDetailsView(self.driver)
def transaction_by_index(self, index: int):
return self.TransactionElement.by_index(self.driver, index=index)
def transaction_by_amount(self, amount: str, asset):
return self.TransactionElement.by_amount(self.driver, amount=amount.replace(',', '.'), asset=asset)
def find_transaction(self, amount: str, asset='ETH') -> TransactionElement:
element = self.transaction_by_amount(amount=amount, asset=asset)
for i in range(9):
try:
element.find_element()
return element
except NoSuchElementException:
time.sleep(5)
self.refresh_transactions()
self.driver.fail('Transaction %s %s was not found on Wallet/Transaction screen' %(amount, asset))
def refresh_transactions(self):
self.driver.swipe(500, 500, 500, 1000)
def get_transactions_number(self):
element = self.TransactionElement(self.driver)
element.locator = element.Locator.xpath_selector('//android.view.ViewGroup[@content-desc="transaction-item"]')
return len(element.wait_for_elements())
class FiltersButton(BaseButton):
def __init__(self, driver):
super(FiltersButton, self).__init__(driver)
self.locator = self.Locator.accessibility_id('filters-button')
class FilterCheckbox(BaseButton):
def __init__(self, driver, filter_name):
super(FilterCheckbox, self).__init__(driver)
self.locator = self.Locator.xpath_selector(
"//*[@text='%s']/following-sibling::*[@content-desc='checkbox']" % filter_name)
class TransactionsView(BaseView):
def __init__(self, driver):
super(TransactionsView, self).__init__(driver)
self.driver = driver
self.filters_button = FiltersButton(self.driver)
self.transactions_table = TransactionTable(self.driver)
def filter_checkbox(self, filter_name):
return FilterCheckbox(self.driver, filter_name)