2017-09-13 14:34:42 +00:00
|
|
|
from views.base_element import BaseElement, BaseButton, BaseEditBox, BaseText
|
2017-09-21 17:01:04 +00:00
|
|
|
import logging
|
|
|
|
import time
|
|
|
|
import pytest
|
|
|
|
import requests
|
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']")
|
|
|
|
|
2017-10-05 19:41:17 +00:00
|
|
|
def click(self):
|
|
|
|
self.wait_for_element(30)
|
|
|
|
self.find_element().click()
|
|
|
|
logging.info('Tap on %s' % self.name)
|
|
|
|
return self.navigate()
|
|
|
|
|
2017-08-28 10:02:20 +00:00
|
|
|
|
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']")
|
|
|
|
|
|
|
|
|
2017-09-21 17:01:04 +00:00
|
|
|
class ContactsButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ContactsButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Contacts']")
|
|
|
|
|
2017-10-05 19:41:17 +00:00
|
|
|
def navigate(self):
|
|
|
|
from views.contacts import ContactsViewObject
|
|
|
|
return ContactsViewObject(self.driver)
|
|
|
|
|
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)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Wallet']")
|
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
from views.wallet import WalletViewObject
|
|
|
|
return WalletViewObject(self.driver)
|
|
|
|
|
|
|
|
|
2017-10-30 11:11:58 +00:00
|
|
|
class DiscoverButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(DiscoverButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Discover']")
|
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
from views.discover import DiscoverView
|
|
|
|
return DiscoverView(self.driver)
|
|
|
|
|
|
|
|
|
2017-10-19 13:49:20 +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 OkButtonAPK(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(OkButtonAPK, 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']")
|
|
|
|
|
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
def get_ethereum_price_in_usd() -> float:
|
|
|
|
url = 'https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD'
|
|
|
|
return float(requests.request('GET', url).json()['USD'])
|
2017-08-28 10:02:20 +00:00
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
|
|
|
|
def get_transactions(address: str) -> dict:
|
|
|
|
url = 'http://ropsten.etherscan.io/api?module=account&action=txlist&address=0x%s&sort=desc' % address
|
|
|
|
return requests.request('GET', url=url).json()['result']
|
|
|
|
|
|
|
|
|
|
|
|
def is_transaction_successful(transaction_hash: str) -> int:
|
|
|
|
url = "https://ropsten.etherscan.io/api?module=transaction&action=getstatus&txhash=%s" % transaction_hash
|
|
|
|
return not int(requests.request('GET', url=url).json()['result']['isError'])
|
|
|
|
|
|
|
|
|
|
|
|
def verify_transaction_in_ropsten(address: str, transaction_hash: str):
|
|
|
|
transactions = get_transactions(address=address)
|
|
|
|
for transaction in transactions:
|
|
|
|
if transaction['hash'] == transaction_hash:
|
|
|
|
logging.info('Transaction is found in Ropsten network')
|
|
|
|
if not is_transaction_successful(transaction_hash=transaction_hash):
|
|
|
|
pytest.fail('Transaction is not successful')
|
|
|
|
return
|
|
|
|
pytest.fail('Transaction was not found via Ropsten API')
|
|
|
|
|
|
|
|
|
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']")
|
|
|
|
|
|
|
|
|
2017-11-09 10:58:11 +00:00
|
|
|
class ChatRequestInput(BaseEditBox):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ChatRequestInput, self).__init__(driver)
|
|
|
|
self.locator = \
|
|
|
|
self.Locator.xpath_selector("//android.widget.EditText[@content-desc!='chat-message-input']")
|
|
|
|
|
|
|
|
|
|
|
|
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']")
|
|
|
|
|
|
|
|
|
2017-10-23 20:46:49 +00:00
|
|
|
class BaseViewObject(object):
|
2017-08-28 10:02:20 +00:00
|
|
|
def __init__(self, driver):
|
|
|
|
self.driver = 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-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)
|
|
|
|
self.ok_button_apk = OkButtonAPK(self.driver)
|
|
|
|
self.apps_button = AppsButton(self.driver)
|
|
|
|
self.status_app_icon = StatusAppIcon(self.driver)
|
2017-10-19 13:49:20 +00:00
|
|
|
|
2017-09-21 17:01:04 +00:00
|
|
|
self.contacts_button = ContactsButton(self.driver)
|
2017-10-19 13:49:20 +00:00
|
|
|
self.wallet_button = WalletButton(self.driver)
|
2017-10-30 11:11:58 +00:00
|
|
|
self.discover_button = DiscoverButton(self.driver)
|
|
|
|
|
|
|
|
self.save_button = SaveButton(self.driver)
|
2017-08-28 10:02:20 +00:00
|
|
|
|
2017-11-09 10:58:11 +00:00
|
|
|
self.chat_request_input = ChatRequestInput(self.driver)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def logcat(self):
|
|
|
|
return self.driver.get_log("logcat")
|
|
|
|
|
2017-08-28 10:02:20 +00:00
|
|
|
def confirm(self):
|
2017-10-05 19:41:17 +00:00
|
|
|
logging.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,
|
|
|
|
',': 55, '-': 69}
|
|
|
|
for i in string:
|
|
|
|
logging.info("Tap '%s' on native keyboard" % i)
|
|
|
|
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):
|
2017-10-05 19:41:17 +00:00
|
|
|
logging.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):
|
2017-10-05 19:41:17 +00:00
|
|
|
logging.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
|
|
|
|
|
|
|
def element_by_text(self, text, element_type='base'):
|
|
|
|
|
|
|
|
element_types = {
|
|
|
|
'base': BaseElement,
|
|
|
|
'button': BaseButton,
|
|
|
|
'edit_box': BaseEditBox,
|
|
|
|
'text': BaseText
|
|
|
|
}
|
|
|
|
|
|
|
|
element = 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
|
|
|
|
|
|
|
def get_chats(self):
|
|
|
|
from views.chats import ChatsViewObject
|
|
|
|
return ChatsViewObject(self.driver)
|
2017-09-21 17:01:04 +00:00
|
|
|
|
2017-11-09 10:58:11 +00:00
|
|
|
def get_login(self):
|
|
|
|
from views.login import LoginView
|
|
|
|
return LoginView(self.driver)
|
|
|
|
|
2017-09-21 17:01:04 +00:00
|
|
|
def get_balance(self, address):
|
|
|
|
url = 'http://ropsten.etherscan.io/api?module=account&action=balance&address=0x%s&tag=latest' % address
|
2017-10-13 08:41:30 +00:00
|
|
|
for i in range(5):
|
|
|
|
try:
|
|
|
|
return int(requests.request('GET', url).json()["result"])
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2017-09-21 17:01:04 +00:00
|
|
|
|
|
|
|
def get_donate(self, address, wait_time=300):
|
2017-09-26 10:50:34 +00:00
|
|
|
initial_balance = self.get_balance(address)
|
2017-09-21 17:01:04 +00:00
|
|
|
counter = 0
|
2017-10-19 13:49:20 +00:00
|
|
|
if initial_balance < 1000000000000000000:
|
|
|
|
response = requests.request('GET', 'http://46.101.129.137:3001/donate/0x%s' % address).json()
|
|
|
|
while True:
|
|
|
|
if counter == wait_time:
|
|
|
|
pytest.fail("Donation was not received during %s seconds!" % wait_time)
|
|
|
|
elif self.get_balance(address) == initial_balance:
|
|
|
|
counter += 10
|
|
|
|
time.sleep(10)
|
|
|
|
logging.info('Waiting %s seconds for donation' % counter)
|
|
|
|
else:
|
|
|
|
logging.info('Got %s for %s' % (response["amount"], address))
|
|
|
|
break
|
2017-09-21 17:01:04 +00:00
|
|
|
|
|
|
|
def verify_balance_is_updated(self, initial_balance, recipient_address, wait_time=120):
|
|
|
|
counter = 0
|
|
|
|
while True:
|
|
|
|
if counter == wait_time:
|
2017-09-26 10:50:34 +00:00
|
|
|
pytest.fail('Balance is not changed during %s seconds, funds were not received!' % wait_time)
|
2017-09-21 17:01:04 +00:00
|
|
|
elif initial_balance == self.get_balance(recipient_address):
|
|
|
|
counter += 10
|
|
|
|
time.sleep(10)
|
|
|
|
logging.info('Waiting %s seconds for funds' % counter)
|
|
|
|
else:
|
|
|
|
logging.info('Transaction was received and verified on ropsten.etherscan.io')
|
|
|
|
break
|