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)
|
|
|
|
self.locator = self.Locator.text_selector('Copy transaction hash')
|
|
|
|
|
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
|
|
|
|
self.locator = self.Locator.xpath_selector("//android.support.v4.view.ViewPager")
|
|
|
|
|
|
|
|
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
|
|
|
|
self.locators = dict(transaction_hash="//android.widget.TextView[@text='Hash']/following-sibling::*[1]")
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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-04-23 18:42:12 +00:00
|
|
|
def get_first_transaction(self):
|
|
|
|
return self.TransactionElement.by_index(self.driver, 0)
|
2017-10-23 20:46:49 +00:00
|
|
|
|
|
|
|
def find_transaction(self, amount: str) -> TransactionElement:
|
2018-01-26 11:07:09 +00:00
|
|
|
for i in range(9):
|
2017-10-23 20:46:49 +00:00
|
|
|
try:
|
2018-04-23 18:42:12 +00:00
|
|
|
element = self.TransactionElement.by_amount(self.driver, amount=amount.replace(',', '.'))
|
2017-10-23 20:46:49 +00:00
|
|
|
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()
|
2017-10-23 20:46:49 +00:00
|
|
|
pytest.fail('Transaction was not found on Wallet/Transaction screen')
|
|
|
|
|
2018-04-23 18:42:12 +00:00
|
|
|
def refresh_transactions(self):
|
|
|
|
self.driver.swipe(500, 500, 500, 1000)
|
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
|
|
|
|
class HistoryTab(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(HistoryTab, self).__init__(driver)
|
2018-03-15 20:01:08 +00:00
|
|
|
self.locator = self.Locator.accessibility_id('history-button')
|
2017-10-23 20:46:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UnsignedTab(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(UnsignedTab, self).__init__(driver)
|
2018-03-15 20:01:08 +00:00
|
|
|
self.locator = self.Locator.accessibility_id('unsigned-transactions-button')
|
2017-10-23 20:46:49 +00:00
|
|
|
|
|
|
|
class SignButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(UnsignedTab.SignButton, self).__init__(driver)
|
2018-03-15 20:01:08 +00:00
|
|
|
self.locator = self.Locator.accessibility_id('sign-button')
|
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
|
|
|
|
self.history_tab = HistoryTab(self.driver)
|
|
|
|
self.unsigned_tab = UnsignedTab(self.driver)
|
|
|
|
self.sign_button = UnsignedTab.SignButton(self.driver)
|
|
|
|
self.transactions_table = TransactionTable(self.driver)
|