transaction by unique amount, fixed simple DAap test, added new errors to rerun tests list

Signed-off-by: yevh-berdnyk <ie.berdnyk@gmail.com>
This commit is contained in:
Anton Danchenko 2018-05-25 20:29:07 +03:00 committed by yevh-berdnyk
parent e38ed4144a
commit a307d8e2d0
No known key found for this signature in database
GPG Key ID: E9B425FDFC4DEA9C
11 changed files with 144 additions and 124 deletions

View File

@ -0,0 +1,87 @@
import pytest
import requests
import time
from tests import info
class NetworkApi:
def __init__(self):
self.url = 'http://api-ropsten.etherscan.io/api?'
def get_transactions(self, address: str) -> dict:
method = self.url + 'module=account&action=txlist&address=0x%s&sort=desc' % address
return requests.request('GET', url=method).json()['result']
def is_transaction_successful(self, transaction_hash: str) -> int:
method = self.url + 'module=transaction&action=getstatus&txhash=%s' % transaction_hash
return not int(requests.request('GET', url=method).json()['result']['isError'])
def get_balance(self, address):
method = self.url + 'module=account&action=balance&address=0x%s&tag=latest' % address
for i in range(5):
try:
return int(requests.request('GET', method).json()["result"])
except ValueError:
pass
def find_transaction_by_hash(self, address: str, transaction_hash: str):
transactions = self.get_transactions(address=address)
for transaction in transactions:
if transaction['hash'] == transaction_hash:
info('Transaction is found in Ropsten network')
return
pytest.fail('Transaction is not found in Ropsten network')
def find_transaction_by_unique_amount(self, address, amount, wait_time=240):
counter = 0
while True:
if counter >= wait_time:
pytest.fail(
'Transaction with amount %s is not found in list of transactions, address is %s' %
(amount, address))
else:
counter += 10
time.sleep(10)
transactions = self.get_transactions(address=address)
for transaction in transactions:
if int(float(amount) * 10 ** 18) == int(transaction['value']):
info('Transaction with unique amount %s is found in list of transactions, address is %s' %
(amount, address))
return
def verify_balance_is_updated(self, initial_balance, recipient_address, wait_time=360):
counter = 0
while True:
if counter >= wait_time:
pytest.fail('Balance is not changed during %s seconds, funds were not received!' % wait_time)
elif initial_balance == self.get_balance(recipient_address):
counter += 10
time.sleep(10)
info('Waiting %s seconds for funds' % counter)
else:
info('Transaction is received')
return
def faucet(self, address):
return requests.request('GET', 'http://51.15.45.169:3001/donate/0x%s' % address).json()
def get_donate(self, address, wait_time=300):
initial_balance = self.get_balance(address)
counter = 0
if initial_balance < 1000000000000000000:
response = self.faucet(address)
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)
info('Waiting %s seconds for donation' % counter)
else:
info('Got %s for %s' % (response["amount_eth"], address))
return
def get_ethereum_price_in_usd(self) -> float:
url = 'https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD'
return float(requests.request('GET', url).json()['USD'])

View File

@ -6,7 +6,9 @@ RERUN_ERRORS = [
'The server returned an invalid or incomplete response.', 'The server returned an invalid or incomplete response.',
'502 Bad Gateway', '502 Bad Gateway',
'Unexpected server error', 'Unexpected server error',
'504 Gateway Time-out' '504 Gateway Time-out',
'Internal Server Error',
'Invalid message: ERROR Internal Server Error'
] ]

View File

@ -1,72 +0,0 @@
import pytest
import requests
import time
from tests import info
def get_transactions(address: str) -> dict:
url = 'http://api-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://api-ropsten.etherscan.io/api?module=transaction&action=getstatus&txhash=%s" % transaction_hash
return not int(requests.request('GET', url=url).json()['result']['isError'])
def get_balance(address):
url = 'http://api-ropsten.etherscan.io/api?module=account&action=balance&address=0x%s&tag=latest' % address
for i in range(5):
try:
return int(requests.request('GET', url).json()["result"])
except ValueError:
pass
def find_transaction_on_ropsten(address: str, transaction_hash: str):
transactions = get_transactions(address=address)
for transaction in transactions:
if transaction['hash'] == transaction_hash:
info('Transaction is found in Ropsten network')
return
pytest.fail('Transaction is not found in Ropsten network')
def verify_balance_is_updated(initial_balance, recipient_address, wait_time=360):
counter = 0
while True:
if counter >= wait_time:
pytest.fail('Balance is not changed during %s seconds, funds were not received!' % wait_time)
elif initial_balance == get_balance(recipient_address):
counter += 10
time.sleep(10)
info('Waiting %s seconds for funds' % counter)
else:
info('Transaction is received')
return
def faucet(address):
return requests.request('GET', 'http://51.15.45.169:3001/donate/0x%s' % address).json()
def get_donate(address, wait_time=300):
initial_balance = get_balance(address)
counter = 0
if initial_balance < 1000000000000000000:
response = faucet(address)
while True:
if counter >= wait_time:
pytest.fail("Donation was not received during %s seconds!" % wait_time)
elif get_balance(address) == initial_balance:
counter += 10
time.sleep(10)
info('Waiting %s seconds for donation' % counter)
else:
info('Got %s for %s' % (response["amount_eth"], address))
return
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'])

View File

@ -3,12 +3,12 @@ import sys
import re import re
import subprocess import subprocess
import asyncio import asyncio
from support.network_api import NetworkApi
from os import environ from os import environ
from appium import webdriver from appium import webdriver
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from selenium.common.exceptions import WebDriverException from selenium.common.exceptions import WebDriverException
from tests import test_suite_data, start_threads, api_requests from tests import test_suite_data, start_threads
from views.base_view import BaseView from views.base_view import BaseView
@ -106,6 +106,8 @@ class AbstractTestCase:
errors = [] errors = []
network_api = NetworkApi()
def verify_no_errors(self): def verify_no_errors(self):
if self.errors: if self.errors:
pytest.fail('. '.join([self.errors.pop(0) for _ in range(len(self.errors))])) pytest.fail('. '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
@ -210,6 +212,6 @@ class MultipleDeviceTestCase(environments[pytest.config.getoption('env')]):
def teardown_method(self, method): def teardown_method(self, method):
for user in self.senders: for user in self.senders:
api_requests.faucet(address=self.senders[user]['address']) self.network_api.faucet(address=self.senders[user]['address'])
super(MultipleDeviceTestCase, self).teardown_method(method) super(MultipleDeviceTestCase, self).teardown_method(method)

View File

@ -2,11 +2,11 @@ import time
import pytest import pytest
import random import random
import string import string
import emoji
from tests import transaction_users, marks, group_chat_users, get_current_time from tests import transaction_users, marks, group_chat_users, get_current_time
from tests.base_test_case import MultipleDeviceTestCase, SingleDeviceTestCase from tests.base_test_case import MultipleDeviceTestCase, SingleDeviceTestCase
from views.sign_in_view import SignInView from views.sign_in_view import SignInView
@marks.all @marks.all
@marks.chat_management @marks.chat_management
class TestChatManagementMultiple(MultipleDeviceTestCase): class TestChatManagementMultiple(MultipleDeviceTestCase):
@ -63,7 +63,7 @@ class TestChatManagementMultiple(MultipleDeviceTestCase):
device_1_chat_view.delete_chat(self.senders['h_user']['username'], self.errors) device_1_chat_view.delete_chat(self.senders['h_user']['username'], self.errors)
device_1_profile_view = device_1_sign_in_view.profile_button.click() device_1_profile_view = device_1_sign_in_view.profile_button.click()
device_1_sign_in_view = device_1_profile_view.logout() device_1_sign_in_view = device_1_profile_view.logout()
time.sleep(5) # Prevent stale element exception for first_account_button time.sleep(5) # Prevent stale element exception for first_account_button
device_1_sign_in_view.account_button.click() device_1_sign_in_view.account_button.click()
device_1_sign_in_view.sign_in(self.senders['g_user']['password']) device_1_sign_in_view.sign_in(self.senders['g_user']['password'])
if device_1_home_view.get_chat_with_user(self.senders['h_user']['username']).is_element_present(20): if device_1_home_view.get_chat_with_user(self.senders['h_user']['username']).is_element_present(20):

View File

@ -1,15 +1,6 @@
import pytest
from tests.base_test_case import SingleDeviceTestCase, MultipleDeviceTestCase
from tests import transaction_users, api_requests, get_current_time, transaction_users_wallet, marks
from selenium.common.exceptions import TimeoutException
import time
import pytest import pytest
from selenium.common.exceptions import TimeoutException from selenium.common.exceptions import TimeoutException
from tests import transaction_users, get_current_time, transaction_users_wallet, marks
from tests import transaction_users, api_requests, get_current_time, transaction_users_wallet
from tests.base_test_case import SingleDeviceTestCase, MultipleDeviceTestCase from tests.base_test_case import SingleDeviceTestCase, MultipleDeviceTestCase
from views.sign_in_view import SignInView from views.sign_in_view import SignInView
from views.web_views.base_web_view import BaseWebView from views.web_views.base_web_view import BaseWebView
@ -30,14 +21,14 @@ class TestTransaction(SingleDeviceTestCase):
sender_public_key = home_view.get_public_key() sender_public_key = home_view.get_public_key()
sender_address = home_view.public_key_to_address(sender_public_key) sender_address = home_view.public_key_to_address(sender_public_key)
home_view.home_button.click() home_view.home_button.click()
api_requests.get_donate(sender_address) self.network_api.get_donate(sender_address)
home_view.add_contact(recipient['public_key']) home_view.add_contact(recipient['public_key'])
chat_view = home_view.get_chat_with_user(recipient['username']).click() chat_view = home_view.get_chat_with_user(recipient['username']).click()
initial_balance_recipient = api_requests.get_balance(recipient['address']) initial_balance_recipient = self.network_api.get_balance(recipient['address'])
chat_view.send_transaction_in_1_1_chat(transaction_amount, 'qwerty1234') chat_view.send_transaction_in_1_1_chat(transaction_amount, 'qwerty1234')
send_transaction_view = chat_view.get_send_transaction_view() send_transaction_view = chat_view.get_send_transaction_view()
send_transaction_view.back_button.click() send_transaction_view.back_button.click()
api_requests.verify_balance_is_updated(initial_balance_recipient, recipient['address']) self.network_api.verify_balance_is_updated(initial_balance_recipient, recipient['address'])
wallet_view = home_view.wallet_button.click() wallet_view = home_view.wallet_button.click()
wallet_view.set_up_wallet() wallet_view.set_up_wallet()
transactions_view = wallet_view.transactions_button.click() transactions_view = wallet_view.transactions_button.click()
@ -77,14 +68,13 @@ class TestTransaction(SingleDeviceTestCase):
sender_public_key = home_view.get_public_key() sender_public_key = home_view.get_public_key()
sender_address = home_view.public_key_to_address(sender_public_key) sender_address = home_view.public_key_to_address(sender_public_key)
home_view.home_button.click() home_view.home_button.click()
api_requests.get_donate(sender_address) self.network_api.get_donate(sender_address)
home_view.add_contact(recipient['public_key']) home_view.add_contact(recipient['public_key'])
home_view.get_back_to_home_view() home_view.get_back_to_home_view()
home_view.create_group_chat([recipient['username']], 'trg_%s' % get_current_time()) home_view.create_group_chat([recipient['username']], 'trg_%s' % get_current_time())
chat_view = home_view.get_chat_view() chat_view = home_view.get_chat_view()
initial_recipient_balance = api_requests.get_balance(recipient['address'])
chat_view.send_transaction_in_group_chat(transaction_amount, 'qwerty1234', recipient) chat_view.send_transaction_in_group_chat(transaction_amount, 'qwerty1234', recipient)
api_requests.verify_balance_is_updated(initial_recipient_balance, recipient['address']) self.network_api.find_transaction_by_unique_amount(transaction_amount, recipient['address'])
@marks.pr @marks.pr
@marks.testrail_case_id(3404) @marks.testrail_case_id(3404)
@ -93,25 +83,22 @@ class TestTransaction(SingleDeviceTestCase):
sign_in_view = SignInView(self.driver) sign_in_view = SignInView(self.driver)
sign_in_view.recover_access(sender['passphrase'], sender['password']) sign_in_view.recover_access(sender['passphrase'], sender['password'])
address = transaction_users['B_USER']['address'] address = transaction_users['B_USER']['address']
initial_balance = api_requests.get_balance(address) initial_balance = self.network_api.get_balance(address)
profile_view = sign_in_view.profile_button.click() profile_view = sign_in_view.profile_button.click()
profile_view.advanced_button.click() profile_view.advanced_button.click()
profile_view.debug_mode_toggle.click() profile_view.debug_mode_toggle.click()
home_view = profile_view.home_button.click() home_view = profile_view.home_button.click()
start_new_chat_view = home_view.plus_button.click() start_new_chat_view = home_view.plus_button.click()
start_new_chat_view.open_d_app_button.click() start_new_chat_view.open_d_app_button.click()
start_new_chat_view.simple_dapp_button.scroll_to_element() start_new_chat_view.status_test_dapp_button.scroll_to_element()
simple_dapp = start_new_chat_view.simple_dapp_button.click() status_test_dapp = start_new_chat_view.status_test_dapp_button.click()
start_new_chat_view.open_button.click() start_new_chat_view.open_button.click()
status_test_dapp.wait_for_d_aap_to_load()
simple_dapp.wait_for_d_aap_to_load() status_test_dapp.assets_button.click()
simple_dapp.assets_button.click() status_test_dapp.request_stt_button.click()
simple_dapp.request_stt_button.click()
send_transaction_view = home_view.get_send_transaction_view() send_transaction_view = home_view.get_send_transaction_view()
send_transaction_view.sign_transaction(sender['password']) send_transaction_view.sign_transaction(sender['password'])
self.network_api.verify_balance_is_updated(initial_balance, address)
api_requests.verify_balance_is_updated(initial_balance, address)
@pytest.mark.transactions @pytest.mark.transactions
@pytest.mark.testrail_case_id(3422) @pytest.mark.testrail_case_id(3422)
@ -170,7 +157,8 @@ class TestTransaction(SingleDeviceTestCase):
wallet_view = home_view.wallet_button.click() wallet_view = home_view.wallet_button.click()
send_transaction = wallet_view.send_button.click() send_transaction = wallet_view.send_button.click()
send_transaction.amount_edit_box.click() send_transaction.amount_edit_box.click()
send_transaction.amount_edit_box.set_value(send_transaction.get_unique_amount()) transaction_amount = send_transaction.get_unique_amount()
send_transaction.amount_edit_box.set_value(transaction_amount)
send_transaction.confirm() send_transaction.confirm()
send_transaction.chose_recipient_button.click() send_transaction.chose_recipient_button.click()
send_transaction.recent_recipients_button.click() send_transaction.recent_recipients_button.click()
@ -184,6 +172,7 @@ class TestTransaction(SingleDeviceTestCase):
send_transaction.got_it_button.click() send_transaction.got_it_button.click()
if sender['password'] in str(home_view.logcat): if sender['password'] in str(home_view.logcat):
pytest.fail('Password in logcat!!!', pytrace=False) pytest.fail('Password in logcat!!!', pytrace=False)
self.network_api.find_transaction_by_unique_amount(sender['address'], transaction_amount)
@marks.testrail_case_id(3452) @marks.testrail_case_id(3452)
def test_sign_transaction_twice(self): def test_sign_transaction_twice(self):
@ -243,10 +232,9 @@ class TestTransactions(MultipleDeviceTestCase):
device_1_chat.first_recipient_button.click() device_1_chat.first_recipient_button.click()
device_1_chat.send_as_keyevent(amount) device_1_chat.send_as_keyevent(amount)
device_1_chat.send_message_button.click() device_1_chat.send_message_button.click()
initial_balance_recipient = api_requests.get_balance(recipient['address'])
request_button = device_2_chat.element_by_text_part('Requesting %s ETH' % amount, 'button') request_button = device_2_chat.element_by_text_part('Requesting %s ETH' % amount, 'button')
device_2_chat.send_eth_to_request(request_button, sender['password']) device_2_chat.send_eth_to_request(request_button, sender['password'])
api_requests.verify_balance_is_updated(initial_balance_recipient, recipient['address']) self.network_api.find_transaction_by_unique_amount(recipient['address'], amount)
@marks.pr @marks.pr
@marks.testrail_case_id(3409) @marks.testrail_case_id(3409)
@ -279,10 +267,9 @@ class TestTransactions(MultipleDeviceTestCase):
device_1_chat.request_command.click() device_1_chat.request_command.click()
device_1_chat.send_as_keyevent(amount) device_1_chat.send_as_keyevent(amount)
device_1_chat.send_message_button.click() device_1_chat.send_message_button.click()
initial_balance_recipient = api_requests.get_balance(recipient['address'])
request_button = device_2_chat.element_by_text_part('Requesting %s ETH' % amount, 'button') request_button = device_2_chat.element_by_text_part('Requesting %s ETH' % amount, 'button')
device_2_chat.send_eth_to_request(request_button, sender['password']) device_2_chat.send_eth_to_request(request_button, sender['password'])
api_requests.verify_balance_is_updated(initial_balance_recipient, recipient['address']) self.network_api.find_transaction_by_unique_amount(recipient['address'], amount)
device_2_chat.back_button.click() device_2_chat.back_button.click()
device_2_wallet = device_2_home.wallet_button.click() device_2_wallet = device_2_home.wallet_button.click()
transactions_view = device_2_wallet.transactions_button.click() transactions_view = device_2_wallet.transactions_button.click()
@ -319,7 +306,6 @@ class TestTransactions(MultipleDeviceTestCase):
one_to_one_chat_device_2 = device_2_chat.element_by_text_part(recipient['username'][:25], 'button') one_to_one_chat_device_2 = device_2_chat.element_by_text_part(recipient['username'][:25], 'button')
one_to_one_chat_device_2.wait_for_visibility_of_element(120) one_to_one_chat_device_2.wait_for_visibility_of_element(120)
one_to_one_chat_device_2.click() one_to_one_chat_device_2.click()
initial_balance_recipient = api_requests.get_balance(recipient['address'])
request_button = device_2_chat.element_by_text_part('Requesting %s ETH' % amount, 'button') request_button = device_2_chat.element_by_text_part('Requesting %s ETH' % amount, 'button')
device_2_chat.send_eth_to_request(request_button, sender['password']) device_2_chat.send_eth_to_request(request_button, sender['password'])
api_requests.verify_balance_is_updated(initial_balance_recipient, recipient['address']) self.network_api.find_transaction_by_unique_amount(recipient['address'], amount)

View File

@ -1,4 +1,4 @@
from tests import api_requests, transaction_users_wallet, marks from tests import transaction_users_wallet, marks
from selenium.common.exceptions import TimeoutException from selenium.common.exceptions import TimeoutException
from tests.base_test_case import SingleDeviceTestCase from tests.base_test_case import SingleDeviceTestCase
from views.sign_in_view import SignInView from views.sign_in_view import SignInView
@ -72,8 +72,8 @@ class TestWallet(SingleDeviceTestCase):
password=transaction_users_wallet['A_USER']['password']) password=transaction_users_wallet['A_USER']['password'])
wallet = sign_in_view.wallet_button.click() wallet = sign_in_view.wallet_button.click()
address = transaction_users_wallet['A_USER']['address'] address = transaction_users_wallet['A_USER']['address']
balance = api_requests.get_balance(address) / 1000000000000000000 balance = self.network_api.get_balance(address) / 1000000000000000000
eth_rate = api_requests.get_ethereum_price_in_usd() eth_rate = self.network_api.get_ethereum_price_in_usd()
wallet_balance = wallet.get_eth_value() wallet_balance = wallet.get_eth_value()
if wallet_balance != balance: if wallet_balance != balance:
errors.append('Balance %s is not equal to the expected %s' % (wallet_balance, balance)) errors.append('Balance %s is not equal to the expected %s' % (wallet_balance, balance))
@ -87,7 +87,7 @@ class TestWallet(SingleDeviceTestCase):
home_view = sign_in_view.get_home_view() home_view = sign_in_view.get_home_view()
sender_public_key = home_view.get_public_key() sender_public_key = home_view.get_public_key()
sender_address = home_view.public_key_to_address(sender_public_key) sender_address = home_view.public_key_to_address(sender_public_key)
api_requests.get_donate(sender_address) self.network_api.get_donate(sender_address)
wallet_view = sign_in_view.wallet_button.click() wallet_view = sign_in_view.wallet_button.click()
sign_in_phrase = wallet_view.set_up_wallet() sign_in_phrase = wallet_view.set_up_wallet()

View File

@ -80,6 +80,16 @@ class BaseElement(object):
seconds) seconds)
raise exception raise exception
def wait_for_invisibility_of_element(self, seconds=10):
try:
return WebDriverWait(self.driver, seconds) \
.until(expected_conditions.invisibility_of_element_located((self.locator.by, self.locator.value)))
except TimeoutException as exception:
exception.msg = "'%s' is still present on screen, using: '%s', during '%s' seconds" % (self.name,
self.locator,
seconds)
raise exception
def scroll_to_element(self): def scroll_to_element(self):
for _ in range(9): for _ in range(9):
try: try:

View File

@ -2,15 +2,15 @@ from views.base_element import BaseButton, BaseEditBox
from views.base_view import BaseView from views.base_view import BaseView
class SimpleDAppButton(BaseButton): class StatusTestDAppButton(BaseButton):
def __init__(self, driver): def __init__(self, driver):
super(SimpleDAppButton, self).__init__(driver) super(StatusTestDAppButton, self).__init__(driver)
self.locator = self.Locator.text_selector('Simple Dapp') self.locator = self.Locator.text_selector('Status Test DApp')
def navigate(self): def navigate(self):
from views.web_views.simple_dapp import SimpleDAppWebView from views.web_views.status_test_dapp import StatusTestDAppView
return SimpleDAppWebView(self.driver) return StatusTestDAppView(self.driver)
class PlusButton(BaseButton): class PlusButton(BaseButton):
@ -43,4 +43,4 @@ class ContactsView(BaseView):
self.public_key_edit_box = PublicKeyEditBox(self.driver) self.public_key_edit_box = PublicKeyEditBox(self.driver)
self.confirm_public_key_button = ConfirmPublicKeyButton(self.driver) self.confirm_public_key_button = ConfirmPublicKeyButton(self.driver)
self.simple_dapp_button = SimpleDAppButton(self.driver) self.status_test_dapp_button = StatusTestDAppButton(self.driver)

View File

@ -37,9 +37,14 @@ class ChatElement(BaseButton):
from views.chat_view import ChatView from views.chat_view import ChatView
return ChatView(self.driver) return ChatView(self.driver)
def click(self):
from views.chat_view import ChatMessageInput
desired_element = ChatMessageInput(self.driver)
self.click_until_presence_of_element(desired_element=desired_element)
return self.navigate()
@property @property
def swipe_delete_button(self): def swipe_delete_button(self):
class DeleteButton(BaseButton): class DeleteButton(BaseButton):
def __init__(self, driver, parent_locator: str): def __init__(self, driver, parent_locator: str):
super(DeleteButton, self).__init__(driver) super(DeleteButton, self).__init__(driver)

View File

@ -13,10 +13,10 @@ class AssetsButton(BaseButton):
self.locator = self.Locator.text_selector('Request STT') self.locator = self.Locator.text_selector('Request STT')
class SimpleDAppWebView(BaseWebView): class StatusTestDAppView(BaseWebView):
def __init__(self, driver): def __init__(self, driver):
super(SimpleDAppWebView, self).__init__(driver) super(StatusTestDAppView, self).__init__(driver)
self.driver = driver self.driver = driver
self.assets_button = AssetsButton(self.driver) self.assets_button = AssetsButton(self.driver)