2017-09-21 17:01:04 +00:00
|
|
|
import time
|
2018-01-26 11:07:09 +00:00
|
|
|
import base64
|
|
|
|
import zbarlight
|
|
|
|
from tests import info
|
|
|
|
from eth_keys import datatypes
|
2018-02-14 13:48:18 +00:00
|
|
|
from selenium.common.exceptions import NoSuchElementException
|
2018-01-26 11:07:09 +00:00
|
|
|
from PIL import Image
|
2018-01-03 09:34:40 +00:00
|
|
|
from datetime import datetime
|
2018-01-26 11:07:09 +00:00
|
|
|
from io import BytesIO
|
2018-01-14 17:43:36 +00:00
|
|
|
from views.base_element import BaseButton, BaseElement, BaseEditBox, BaseText
|
|
|
|
|
2017-08-28 10:02:20 +00:00
|
|
|
|
|
|
|
class BackButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(BackButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@content-desc='toolbar-back-button']")
|
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
def click(self, times_to_click: int = 1):
|
|
|
|
for _ in range(times_to_click):
|
2018-02-07 13:18:55 +00:00
|
|
|
self.find_element().click()
|
|
|
|
info('Tap on %s' % self.name)
|
2017-10-05 19:41:17 +00:00
|
|
|
return self.navigate()
|
|
|
|
|
2017-08-28 10:02:20 +00:00
|
|
|
|
2017-11-09 10:55:02 +00:00
|
|
|
class AllowButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(AllowButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Allow']")
|
|
|
|
|
|
|
|
def click(self):
|
|
|
|
try:
|
|
|
|
for _ in range(3):
|
|
|
|
self.find_element().click()
|
2018-01-26 11:07:09 +00:00
|
|
|
info('Tap on %s' % self.name)
|
2017-11-09 10:55:02 +00:00
|
|
|
except NoSuchElementException:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2017-10-19 13:49:20 +00:00
|
|
|
class DenyButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(DenyButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Deny']")
|
|
|
|
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
class YesButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(YesButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Yes']")
|
|
|
|
|
|
|
|
|
|
|
|
class NoButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(NoButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='No']")
|
|
|
|
|
|
|
|
|
|
|
|
class OkButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(OkButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='OK']")
|
|
|
|
|
|
|
|
|
|
|
|
class ContinueButtonAPK(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ContinueButtonAPK, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Continue']")
|
|
|
|
|
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
class HomeButton(BaseButton):
|
2017-09-21 17:01:04 +00:00
|
|
|
def __init__(self, driver):
|
2018-01-14 17:43:36 +00:00
|
|
|
super(HomeButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Home']/..")
|
2017-09-21 17:01:04 +00:00
|
|
|
|
2017-10-05 19:41:17 +00:00
|
|
|
def navigate(self):
|
2018-01-14 17:43:36 +00:00
|
|
|
from views.home_view import HomeView
|
|
|
|
return HomeView(self.driver)
|
2017-10-05 19:41:17 +00:00
|
|
|
|
2017-09-21 17:01:04 +00:00
|
|
|
|
2017-10-19 13:49:20 +00:00
|
|
|
class WalletButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(WalletButton, self).__init__(driver)
|
2018-01-03 09:34:40 +00:00
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Wallet']/..")
|
2017-10-19 13:49:20 +00:00
|
|
|
|
2018-02-09 15:16:07 +00:00
|
|
|
def click(self):
|
|
|
|
from views.wallet_view import TransactionsButton
|
|
|
|
self.click_until_presence_of_element(desired_element=TransactionsButton(self.driver), attempts=3)
|
|
|
|
return self.navigate()
|
|
|
|
|
2017-10-19 13:49:20 +00:00
|
|
|
def navigate(self):
|
2018-01-03 09:34:40 +00:00
|
|
|
from views.wallet_view import WalletView
|
|
|
|
return WalletView(self.driver)
|
2017-10-19 13:49:20 +00:00
|
|
|
|
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
class ProfileButton(BaseButton):
|
2017-10-30 11:11:58 +00:00
|
|
|
def __init__(self, driver):
|
2018-01-14 17:43:36 +00:00
|
|
|
super(ProfileButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Profile']/..")
|
2017-10-30 11:11:58 +00:00
|
|
|
|
|
|
|
def navigate(self):
|
2018-01-14 17:43:36 +00:00
|
|
|
from views.profile_view import ProfileView
|
|
|
|
return ProfileView(self.driver)
|
2017-10-23 20:46:49 +00:00
|
|
|
|
|
|
|
|
2017-10-30 11:11:58 +00:00
|
|
|
class SaveButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(SaveButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector(
|
|
|
|
"//android.widget.TextView[@text='SAVE']")
|
|
|
|
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
class NextButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(NextButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector(
|
2018-03-01 13:22:01 +00:00
|
|
|
"//android.widget.TextView[@text='NEXT']")
|
2018-01-03 09:34:40 +00:00
|
|
|
|
|
|
|
|
2018-01-26 11:07:09 +00:00
|
|
|
class DoneButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(DoneButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector(
|
2018-02-07 13:18:55 +00:00
|
|
|
"//android.widget.TextView[@text='DONE']")
|
2018-01-26 11:07:09 +00:00
|
|
|
|
|
|
|
|
2017-11-09 10:58:11 +00:00
|
|
|
class AppsButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(AppsButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.accessibility_id("Apps")
|
|
|
|
|
|
|
|
|
|
|
|
class StatusAppIcon(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(StatusAppIcon, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector(
|
|
|
|
"//*[@text='Status']")
|
|
|
|
|
|
|
|
|
2018-03-01 13:22:01 +00:00
|
|
|
class DeleteButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(DeleteButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Delete']")
|
|
|
|
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
class BaseView(object):
|
2017-08-28 10:02:20 +00:00
|
|
|
def __init__(self, driver):
|
|
|
|
self.driver = driver
|
2017-10-19 13:49:20 +00:00
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
self.home_button = HomeButton(self.driver)
|
2018-02-09 15:16:07 +00:00
|
|
|
self.wallet_button = WalletButton(self.driver)
|
2018-01-14 17:43:36 +00:00
|
|
|
self.profile_button = ProfileButton(self.driver)
|
|
|
|
|
2017-10-19 13:49:20 +00:00
|
|
|
self.yes_button = YesButton(self.driver)
|
|
|
|
self.no_button = NoButton(self.driver)
|
2017-08-28 10:02:20 +00:00
|
|
|
self.back_button = BackButton(self.driver)
|
2017-11-09 10:55:02 +00:00
|
|
|
self.allow_button = AllowButton(self.driver)
|
2017-10-19 13:49:20 +00:00
|
|
|
self.deny_button = DenyButton(self.driver)
|
2017-11-09 10:58:11 +00:00
|
|
|
self.continue_button_apk = ContinueButtonAPK(self.driver)
|
2018-01-03 09:34:40 +00:00
|
|
|
self.ok_button_apk = OkButton(self.driver)
|
|
|
|
self.next_button = NextButton(self.driver)
|
2017-10-30 11:11:58 +00:00
|
|
|
self.save_button = SaveButton(self.driver)
|
2018-01-26 11:07:09 +00:00
|
|
|
self.done_button = DoneButton(self.driver)
|
2018-03-01 13:22:01 +00:00
|
|
|
self.delete_button = DeleteButton(self.driver)
|
2017-08-28 10:02:20 +00:00
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
self.apps_button = AppsButton(self.driver)
|
|
|
|
self.status_app_icon = StatusAppIcon(self.driver)
|
2017-11-09 10:58:11 +00:00
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
self.element_types = {
|
|
|
|
'base': BaseElement,
|
|
|
|
'button': BaseButton,
|
|
|
|
'edit_box': BaseEditBox,
|
|
|
|
'text': BaseText
|
|
|
|
}
|
|
|
|
|
2017-11-09 10:58:11 +00:00
|
|
|
@property
|
|
|
|
def logcat(self):
|
|
|
|
return self.driver.get_log("logcat")
|
|
|
|
|
2017-08-28 10:02:20 +00:00
|
|
|
def confirm(self):
|
2018-01-26 11:07:09 +00:00
|
|
|
info("Tap 'Confirm' on native keyboard")
|
2017-08-28 10:02:20 +00:00
|
|
|
self.driver.keyevent(66)
|
|
|
|
|
2017-10-05 19:41:17 +00:00
|
|
|
def send_as_keyevent(self, string):
|
|
|
|
keys = {'0': 7, '1': 8, '2': 9, '3': 10, '4': 11, '5': 12, '6': 13, '7': 14, '8': 15, '9': 16,
|
2017-11-17 11:43:38 +00:00
|
|
|
|
|
|
|
',': 55, '-': 69, '+': 81, '.': 56, '/': 76, '\\': 73, ';': 74, ' ': 62,
|
2018-02-14 13:48:18 +00:00
|
|
|
'[': 71, ']': 72, '=': 70, '\n': 66,
|
2017-11-17 11:43:38 +00:00
|
|
|
|
|
|
|
'a': 29, 'b': 30, 'c': 31, 'd': 32, 'e': 33, 'f': 34, 'g': 35, 'h': 36, 'i': 37, 'j': 38,
|
|
|
|
'k': 39, 'l': 40, 'm': 41, 'n': 42, 'o': 43, 'p': 44, 'q': 45, 'r': 46, 's': 47, 't': 48,
|
|
|
|
'u': 49, 'v': 50, 'w': 51, 'x': 52, 'y': 53, 'z': 54}
|
2017-10-05 19:41:17 +00:00
|
|
|
for i in string:
|
2018-01-26 11:07:09 +00:00
|
|
|
info("Tap '%s' on native keyboard" % i)
|
2017-10-05 19:41:17 +00:00
|
|
|
time.sleep(1)
|
|
|
|
self.driver.keyevent(keys[i])
|
2017-09-21 17:01:04 +00:00
|
|
|
|
|
|
|
def find_full_text(self, text, wait_time=60):
|
2018-01-26 11:07:09 +00:00
|
|
|
info("Looking for full text: '%s'" % text)
|
2017-09-13 14:34:42 +00:00
|
|
|
element = BaseElement(self.driver)
|
|
|
|
element.locator = element.Locator.xpath_selector('//*[@text="' + text + '"]')
|
2017-09-21 17:01:04 +00:00
|
|
|
return element.wait_for_element(wait_time)
|
2017-09-13 14:34:42 +00:00
|
|
|
|
2017-09-21 17:01:04 +00:00
|
|
|
def find_text_part(self, text, wait_time=60):
|
2018-01-26 11:07:09 +00:00
|
|
|
info("Looking for a text part: '%s'" % text)
|
2017-09-11 10:43:42 +00:00
|
|
|
element = BaseElement(self.driver)
|
2017-09-13 14:34:42 +00:00
|
|
|
element.locator = element.Locator.xpath_selector('//*[contains(@text, "' + text + '")]')
|
2017-09-21 17:01:04 +00:00
|
|
|
return element.wait_for_element(wait_time)
|
2017-09-13 14:34:42 +00:00
|
|
|
|
2018-02-09 15:16:07 +00:00
|
|
|
def element_by_text(self, text, element_type='button'):
|
2018-01-26 11:07:09 +00:00
|
|
|
info("Looking for an element by text: '%s'" % text)
|
2018-01-03 09:34:40 +00:00
|
|
|
element = self.element_types[element_type](self.driver)
|
2017-08-28 10:02:20 +00:00
|
|
|
element.locator = element.Locator.xpath_selector('//*[@text="' + text + '"]')
|
2017-09-13 14:34:42 +00:00
|
|
|
return element
|
2017-08-28 10:02:20 +00:00
|
|
|
|
2017-11-09 10:55:02 +00:00
|
|
|
def element_by_text_part(self, text, element_type='base'):
|
2018-01-26 11:07:09 +00:00
|
|
|
info("Looking for an element by text part: '%s'" % text)
|
2018-01-03 09:34:40 +00:00
|
|
|
element = self.element_types[element_type](self.driver)
|
2017-11-09 10:55:02 +00:00
|
|
|
element.locator = element.Locator.xpath_selector('//*[contains(@text, "' + text + '")]')
|
|
|
|
return element
|
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
def get_home_view(self):
|
|
|
|
from views.home_view import HomeView
|
|
|
|
return HomeView(self.driver)
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
def get_chat_view(self):
|
|
|
|
from views.chat_view import ChatView
|
|
|
|
return ChatView(self.driver)
|
|
|
|
|
|
|
|
def get_sign_in_view(self):
|
|
|
|
from views.sign_in_view import SignInView
|
|
|
|
return SignInView(self.driver)
|
|
|
|
|
|
|
|
def get_send_transaction_view(self):
|
|
|
|
from views.send_transaction_view import SendTransactionView
|
|
|
|
return SendTransactionView(self.driver)
|
|
|
|
|
2018-02-13 17:22:41 +00:00
|
|
|
def get_base_web_view(self):
|
|
|
|
from views.web_views.base_web_view import BaseWebView
|
|
|
|
return BaseWebView(self.driver)
|
|
|
|
|
2018-02-14 13:48:18 +00:00
|
|
|
def get_profile_view(self):
|
|
|
|
from views.profile_view import ProfileView
|
|
|
|
return ProfileView(self.driver)
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
def get_unique_amount(self):
|
|
|
|
return '0.0%s' % datetime.now().strftime('%-m%-d%-H%-M%-S').strip('0')
|
2018-01-26 11:07:09 +00:00
|
|
|
|
|
|
|
def get_text_from_qr(self):
|
|
|
|
image = Image.open(BytesIO(base64.b64decode(self.driver.get_screenshot_as_base64())))
|
|
|
|
image.load()
|
|
|
|
try:
|
|
|
|
return str(zbarlight.scan_codes('qrcode', image)[0])[2:][:132]
|
|
|
|
except IndexError:
|
|
|
|
raise BaseException('No data in QR code')
|
|
|
|
|
|
|
|
def public_key_to_address(self, public_key):
|
|
|
|
raw_public_key = bytearray.fromhex(public_key.replace('0x04', ''))
|
|
|
|
return datatypes.PublicKey(raw_public_key).to_address()[2:]
|