2017-10-23 20:46:49 +00:00
|
|
|
import logging
|
|
|
|
|
2017-10-19 13:49:20 +00:00
|
|
|
from views.base_view import BaseViewObject
|
2017-10-23 20:46:49 +00:00
|
|
|
from views.base_element import BaseButton, BaseEditBox, BaseText
|
2017-10-19 13:49:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SendButton(BaseButton):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(SendButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='SEND']")
|
|
|
|
|
|
|
|
|
2017-12-13 13:12:46 +00:00
|
|
|
class RequestButton(BaseButton):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(RequestButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='REQUEST']")
|
|
|
|
|
|
|
|
|
|
|
|
class SendRequestButton(BaseButton):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(SendRequestButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='SEND REQUEST']")
|
|
|
|
|
|
|
|
|
2017-10-19 13:49:20 +00:00
|
|
|
class AmountEditBox(BaseEditBox, BaseButton):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(AmountEditBox, self).__init__(driver)
|
2017-10-23 20:46:49 +00:00
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Amount']/..//android.widget.EditText")
|
2017-10-19 13:49:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ChooseRecipientButton(BaseButton):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ChooseRecipientButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Choose recipient...']")
|
|
|
|
|
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
class TransactionsButton(BaseButton):
|
2017-10-19 13:49:20 +00:00
|
|
|
|
|
|
|
def __init__(self, driver):
|
2017-10-23 20:46:49 +00:00
|
|
|
super(TransactionsButton, self).__init__(driver)
|
2017-10-19 13:49:20 +00:00
|
|
|
self.locator = self.Locator.xpath_selector('(//android.view.ViewGroup[@content-desc="icon"])[4]')
|
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
def navigate(self):
|
|
|
|
from views.transactions import TransactionsViewObject
|
|
|
|
return TransactionsViewObject(self.driver)
|
2017-10-19 13:49:20 +00:00
|
|
|
|
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
class ChooseFromContactsButton(BaseButton):
|
2017-10-19 13:49:20 +00:00
|
|
|
def __init__(self, driver):
|
2017-10-23 20:46:49 +00:00
|
|
|
super(ChooseFromContactsButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Choose From Contacts']")
|
2017-10-19 13:49:20 +00:00
|
|
|
|
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
class EthAssetText(BaseText):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(EthAssetText, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='ETH']/../android.widget.TextView[1]")
|
2017-10-19 13:49:20 +00:00
|
|
|
|
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
class UsdTotalValueText(BaseText):
|
2017-10-19 13:49:20 +00:00
|
|
|
def __init__(self, driver):
|
2017-10-23 20:46:49 +00:00
|
|
|
super(UsdTotalValueText, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='USD']/../android.widget.TextView[1]")
|
2017-10-19 13:49:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WalletViewObject(BaseViewObject):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(WalletViewObject, self).__init__(driver)
|
|
|
|
self.driver = driver
|
|
|
|
|
|
|
|
self.send_button = SendButton(self.driver)
|
|
|
|
self.amount_edit_box = AmountEditBox(self.driver)
|
|
|
|
self.chose_recipient_button = ChooseRecipientButton(self.driver)
|
|
|
|
self.chose_from_contacts_button = ChooseFromContactsButton(self.driver)
|
2017-10-23 20:46:49 +00:00
|
|
|
self.transactions_button = TransactionsButton(self.driver)
|
|
|
|
self.eth_asset = EthAssetText(self.driver)
|
|
|
|
self.usd_total_value = UsdTotalValueText(self.driver)
|
2017-12-13 13:12:46 +00:00
|
|
|
self.request_button = RequestButton(self.driver)
|
|
|
|
self.send_request_button = SendRequestButton(self.driver)
|
2017-10-23 20:46:49 +00:00
|
|
|
|
|
|
|
def get_usd_total_value(self):
|
|
|
|
return float(self.usd_total_value.text)
|
|
|
|
|
|
|
|
def get_eth_value(self):
|
|
|
|
return float(self.eth_asset.text)
|
|
|
|
|
2017-12-27 18:03:57 +00:00
|
|
|
def verify_currency_balance(self, expected_rate: int, errors: list):
|
2017-10-23 20:46:49 +00:00
|
|
|
usd = self.get_usd_total_value()
|
|
|
|
eth = self.get_eth_value()
|
2017-12-27 18:03:57 +00:00
|
|
|
expected_usd = round(eth * expected_rate, 2)
|
2017-12-27 18:03:57 +00:00
|
|
|
percentage_diff = abs((usd - expected_usd) / ((usd + expected_usd) / 2)) * 100
|
|
|
|
if percentage_diff > 2:
|
|
|
|
errors.append('Difference between current (%s) and expected (%s) USD balance > 2%%!!' % (usd, expected_usd))
|
2017-12-27 18:03:57 +00:00
|
|
|
logging.info('Current USD balance %s is ok' % usd)
|