2017-10-23 20:46:49 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from selenium.common.exceptions import NoSuchElementException
|
|
|
|
from views.base_element import BaseElement, BaseButton, BaseText
|
2018-01-03 09:34:40 +00:00
|
|
|
from views.base_view import BaseView
|
2017-10-23 20:46:49 +00:00
|
|
|
|
|
|
|
|
2018-04-23 18:42:12 +00:00
|
|
|
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]')
|
|
|
|
|
2018-06-29 17:27:30 +00:00
|
|
|
class CopyTransactionHashButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(OptionsButton.CopyTransactionHashButton, self).__init__(driver)
|
2018-08-08 15:30:48 +00:00
|
|
|
self.locator = self.Locator.text_selector('Copy transaction ID')
|
2018-06-29 17:27:30 +00:00
|
|
|
|
2018-04-23 18:42:12 +00:00
|
|
|
class OpenOnEtherscanButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(OptionsButton.OpenOnEtherscanButton, self).__init__(driver)
|
2018-06-29 17:27:30 +00:00
|
|
|
self.locator = self.Locator.text_selector('Open on Etherscan.io')
|
2018-04-23 18:42:12 +00:00
|
|
|
|
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
class TransactionTable(BaseElement):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(TransactionTable, self).__init__(driver)
|
|
|
|
self.driver = driver
|
2018-08-27 18:24:51 +00:00
|
|
|
self.locator = self.Locator.xpath_selector("//android.widget.ScrollView")
|
2017-10-23 20:46:49 +00:00
|
|
|
|
|
|
|
class TransactionElement(BaseButton):
|
2018-04-23 18:42:12 +00:00
|
|
|
def __init__(self, driver):
|
2017-10-23 20:46:49 +00:00
|
|
|
super(TransactionTable.TransactionElement, self).__init__(driver)
|
2018-04-23 18:42:12 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def by_amount(driver, amount: str):
|
|
|
|
element = TransactionTable.TransactionElement(driver)
|
|
|
|
element.locator = element.Locator.xpath_selector(
|
2017-10-23 20:46:49 +00:00
|
|
|
"(//android.widget.TextView[contains(@text,'%s ETH')])" % amount)
|
2018-04-23 18:42:12 +00:00
|
|
|
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
|
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']"
|
|
|
|
self.locators['recipient_address'] = "//*[@content-desc='recipient-address-text']"
|
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
class DetailsTextElement(BaseText):
|
|
|
|
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)
|
|
|
|
self.locator = self.Locator.xpath_selector(locator)
|
|
|
|
|
|
|
|
def get_transaction_hash(self) -> str:
|
|
|
|
return self.DetailsTextElement(driver=self.driver, locator=self.locators['transaction_hash']).text
|
|
|
|
|
2018-07-26 18:58:05 +00:00
|
|
|
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
|
|
|
|
|
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):
|
|
|
|
return self.TransactionElement.by_index(self.driver, index=index)
|
|
|
|
|
|
|
|
def transaction_by_amount(self, amount: str):
|
|
|
|
return self.TransactionElement.by_amount(self.driver, amount=amount.replace(',', '.'))
|
2017-10-23 20:46:49 +00:00
|
|
|
|
|
|
|
def find_transaction(self, amount: str) -> TransactionElement:
|
2018-07-26 18:58:05 +00:00
|
|
|
element = self.transaction_by_amount(amount=amount)
|
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:
|
2018-01-26 11:07:09 +00:00
|
|
|
time.sleep(5)
|
2018-04-23 18:42:12 +00:00
|
|
|
self.refresh_transactions()
|
2018-08-15 12:51:52 +00:00
|
|
|
self.driver.fail('Transaction was not found on Wallet/Transaction screen')
|
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)
|
|
|
|
element.locator = element.Locator.xpath_selector('//android.view.ViewGroup[@content-desc="transaction-item"]')
|
|
|
|
return len(element.find_elements())
|
2017-10-23 20:46:49 +00:00
|
|
|
|
|
|
|
|
2018-07-26 18:58:05 +00:00
|
|
|
class FiltersButton(BaseButton):
|
2017-10-23 20:46:49 +00:00
|
|
|
def __init__(self, driver):
|
2018-07-26 18:58:05 +00:00
|
|
|
super(FiltersButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.accessibility_id('filters-button')
|
2017-10-23 20:46:49 +00:00
|
|
|
|
2018-07-26 18:58:05 +00:00
|
|
|
|
|
|
|
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)
|
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):
|
2018-01-03 09:34:40 +00:00
|
|
|
super(TransactionsView, self).__init__(driver)
|
2017-10-23 20:46:49 +00:00
|
|
|
self.driver = driver
|
2018-07-26 18:58:05 +00:00
|
|
|
self.filters_button = FiltersButton(self.driver)
|
2017-10-23 20:46:49 +00:00
|
|
|
self.transactions_table = TransactionTable(self.driver)
|
2018-07-26 18:58:05 +00:00
|
|
|
|
|
|
|
def filter_checkbox(self, filter_name):
|
|
|
|
return FilterCheckbox(self.driver, filter_name)
|