2018-01-26 11:07:09 +00:00
|
|
|
|
from tests import info
|
2018-05-16 07:22:02 +00:00
|
|
|
|
import time
|
|
|
|
|
import pytest
|
2018-01-03 09:34:40 +00:00
|
|
|
|
from views.base_view import BaseView
|
2018-01-14 17:43:36 +00:00
|
|
|
|
from views.base_element import BaseButton, BaseText
|
2017-10-19 13:49:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SendButton(BaseButton):
|
|
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
|
super(SendButton, self).__init__(driver)
|
2018-03-15 20:01:08 +00:00
|
|
|
|
self.locator = self.Locator.accessibility_id('send-transaction-button')
|
2018-01-14 17:43:36 +00:00
|
|
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
|
from views.send_transaction_view import SendTransactionView
|
|
|
|
|
return SendTransactionView(self.driver)
|
2017-10-19 13:49:20 +00:00
|
|
|
|
|
|
|
|
|
|
2017-12-13 13:12:46 +00:00
|
|
|
|
class RequestButton(BaseButton):
|
|
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
|
super(RequestButton, self).__init__(driver)
|
2018-03-15 20:01:08 +00:00
|
|
|
|
self.locator = self.Locator.accessibility_id('receive-transaction-button')
|
2017-12-13 13:12:46 +00:00
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
|
def navigate(self):
|
2018-01-14 17:43:36 +00:00
|
|
|
|
from views.send_transaction_view import SendTransactionView
|
|
|
|
|
return SendTransactionView(self.driver)
|
2018-01-03 09:34:40 +00:00
|
|
|
|
|
2017-12-13 13:12:46 +00:00
|
|
|
|
|
|
|
|
|
class SendRequestButton(BaseButton):
|
|
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
|
super(SendRequestButton, self).__init__(driver)
|
2018-03-15 20:01:08 +00:00
|
|
|
|
self.locator = self.Locator.accessibility_id('sent-request-button')
|
2017-12-13 13:12:46 +00:00
|
|
|
|
|
|
|
|
|
|
2017-10-19 13:49:20 +00:00
|
|
|
|
class ChooseRecipientButton(BaseButton):
|
|
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
|
super(ChooseRecipientButton, self).__init__(driver)
|
2018-03-15 20:01:08 +00:00
|
|
|
|
self.locator = self.Locator.accessibility_id('choose-recipient-button')
|
2017-10-19 13:49:20 +00:00
|
|
|
|
|
|
|
|
|
|
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)
|
2018-03-15 20:01:08 +00:00
|
|
|
|
self.locator = self.Locator.accessibility_id('transaction-history-button')
|
2017-10-19 13:49:20 +00:00
|
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
|
def navigate(self):
|
2018-01-03 09:34:40 +00:00
|
|
|
|
from views.transactions_view import TransactionsView
|
|
|
|
|
return TransactionsView(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
|
|
|
|
|
|
|
|
|
|
2018-02-09 15:16:07 +00:00
|
|
|
|
class SendTransactionRequestButton(BaseButton):
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
|
super(SendTransactionRequestButton, self).__init__(driver)
|
2018-03-15 20:01:08 +00:00
|
|
|
|
self.locator = self.Locator.accessibility_id('sent-transaction-request-button')
|
2018-02-09 15:16:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OptionsButton(BaseButton):
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
|
super(OptionsButton, self).__init__(driver)
|
2018-03-15 20:01:08 +00:00
|
|
|
|
self.locator = self.Locator.accessibility_id('options-menu-button')
|
2018-02-09 15:16:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ManageAssetsButton(BaseButton):
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
|
super(ManageAssetsButton, self).__init__(driver)
|
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Manage Assets']")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class STTCheckBox(BaseButton):
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
|
super(STTCheckBox, self).__init__(driver)
|
2018-03-15 20:01:08 +00:00
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='STT']/../android.widget.CheckBox")
|
2018-02-09 15:16:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DoneButton(BaseButton):
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
|
super(DoneButton, self).__init__(driver)
|
2018-03-15 20:01:08 +00:00
|
|
|
|
self.locator = self.Locator.accessibility_id('done-button')
|
2018-02-09 15:16:07 +00:00
|
|
|
|
|
|
|
|
|
|
2018-05-02 16:01:17 +00:00
|
|
|
|
class QRCodeImage(BaseButton):
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
|
super(QRCodeImage, self).__init__(driver)
|
|
|
|
|
self.locator = self.Locator.accessibility_id('qr-code-image')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AddressText(BaseButton):
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
|
super(AddressText, self).__init__(driver)
|
|
|
|
|
self.locator = self.Locator.accessibility_id('address-text')
|
|
|
|
|
|
|
|
|
|
|
2018-05-11 19:15:39 +00:00
|
|
|
|
class SetUpButton(BaseButton):
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
|
super(SetUpButton, self).__init__(driver)
|
|
|
|
|
self.locator = self.Locator.text_selector("LET’S GET SET UP")
|
|
|
|
|
|
|
|
|
|
|
2018-05-16 19:59:36 +00:00
|
|
|
|
class SignInPhraseText(BaseText):
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
|
super(SignInPhraseText, self).__init__(driver)
|
|
|
|
|
self.locator = self.Locator.xpath_selector(
|
|
|
|
|
"//*[contains(@text,'phrase')]/preceding-sibling::*[1]/android.widget.TextView")
|
|
|
|
|
|
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
|
class WalletView(BaseView):
|
2017-10-19 13:49:20 +00:00
|
|
|
|
def __init__(self, driver):
|
2018-01-03 09:34:40 +00:00
|
|
|
|
super(WalletView, self).__init__(driver)
|
2017-10-19 13:49:20 +00:00
|
|
|
|
self.driver = driver
|
|
|
|
|
|
|
|
|
|
self.send_button = SendButton(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)
|
2018-02-09 15:16:07 +00:00
|
|
|
|
|
|
|
|
|
self.send_transaction_request = SendTransactionRequestButton(self.driver)
|
2017-12-13 13:12:46 +00:00
|
|
|
|
self.request_button = RequestButton(self.driver)
|
2018-01-03 09:34:40 +00:00
|
|
|
|
|
2017-12-13 13:12:46 +00:00
|
|
|
|
self.send_request_button = SendRequestButton(self.driver)
|
2018-02-09 15:16:07 +00:00
|
|
|
|
self.options_button = OptionsButton(self.driver)
|
|
|
|
|
self.manage_assets_button = ManageAssetsButton(self.driver)
|
|
|
|
|
self.stt_check_box = STTCheckBox(self.driver)
|
|
|
|
|
self.done_button = DoneButton(self.driver)
|
2017-10-23 20:46:49 +00:00
|
|
|
|
|
2018-05-02 16:01:17 +00:00
|
|
|
|
self.qr_code_image = QRCodeImage(self.driver)
|
|
|
|
|
self.address_text = AddressText(self.driver)
|
|
|
|
|
|
2018-05-11 19:15:39 +00:00
|
|
|
|
self.set_up_button = SetUpButton(self.driver)
|
2018-05-16 19:59:36 +00:00
|
|
|
|
self.sign_in_phrase = SignInPhraseText(self.driver)
|
2018-05-11 19:15:39 +00:00
|
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
|
def get_usd_total_value(self):
|
2018-05-29 14:06:32 +00:00
|
|
|
|
import re
|
|
|
|
|
return float(re.sub('[$,]', '', self.usd_total_value.text))
|
2017-10-23 20:46:49 +00:00
|
|
|
|
|
|
|
|
|
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))
|
2018-01-14 17:43:36 +00:00
|
|
|
|
else:
|
2018-01-26 11:07:09 +00:00
|
|
|
|
info('Current USD balance %s is ok' % usd)
|
2018-05-11 19:15:39 +00:00
|
|
|
|
|
2018-05-16 07:22:02 +00:00
|
|
|
|
def wait_balance_changed_on_wallet_screen(self, initial_balance=0, wait_time=300):
|
|
|
|
|
counter = 0
|
|
|
|
|
while True:
|
|
|
|
|
if counter >= wait_time:
|
|
|
|
|
pytest.fail('Balance is not changed during %s seconds!' % wait_time)
|
|
|
|
|
elif self.get_eth_value() == initial_balance:
|
|
|
|
|
counter += 10
|
|
|
|
|
time.sleep(10)
|
|
|
|
|
self.driver.swipe(500, 500, 500, 1000)
|
|
|
|
|
info('Waiting %s seconds for ETH update' % counter)
|
|
|
|
|
else:
|
|
|
|
|
info('Transaction received, balance updated!')
|
|
|
|
|
return
|
|
|
|
|
|
2018-05-16 19:59:36 +00:00
|
|
|
|
def get_sign_in_phrase(self):
|
|
|
|
|
return ' '.join([element.text for element in self.sign_in_phrase.find_elements()])
|
|
|
|
|
|
2018-05-11 19:15:39 +00:00
|
|
|
|
def set_up_wallet(self):
|
|
|
|
|
self.set_up_button.click()
|
2018-05-16 19:59:36 +00:00
|
|
|
|
phrase = self.get_sign_in_phrase()
|
2018-05-11 19:15:39 +00:00
|
|
|
|
self.done_button.click()
|
|
|
|
|
self.yes_button.click()
|
2018-05-16 19:59:36 +00:00
|
|
|
|
return phrase
|