From a307d8e2d086ba00c07031985b949a69df9f6dff Mon Sep 17 00:00:00 2001 From: Anton Danchenko Date: Fri, 25 May 2018 20:29:07 +0300 Subject: [PATCH] transaction by unique amount, fixed simple DAap test, added new errors to rerun tests list Signed-off-by: yevh-berdnyk --- test/appium/support/network_api.py | 87 +++++++++++++++++++ test/appium/support/test_rerun.py | 4 +- test/appium/tests/api_requests.py | 72 --------------- test/appium/tests/base_test_case.py | 8 +- test/appium/tests/test_chat_management.py | 4 +- test/appium/tests/test_transaction.py | 52 ++++------- test/appium/tests/test_wallet.py | 8 +- test/appium/views/base_element.py | 10 +++ test/appium/views/contacts_view.py | 12 +-- test/appium/views/home_view.py | 7 +- .../{simple_dapp.py => status_test_dapp.py} | 4 +- 11 files changed, 144 insertions(+), 124 deletions(-) create mode 100644 test/appium/support/network_api.py delete mode 100644 test/appium/tests/api_requests.py rename test/appium/views/web_views/{simple_dapp.py => status_test_dapp.py} (87%) diff --git a/test/appium/support/network_api.py b/test/appium/support/network_api.py new file mode 100644 index 0000000000..1c1497e5e4 --- /dev/null +++ b/test/appium/support/network_api.py @@ -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']) diff --git a/test/appium/support/test_rerun.py b/test/appium/support/test_rerun.py index 37aa71be0c..53fa3bd496 100644 --- a/test/appium/support/test_rerun.py +++ b/test/appium/support/test_rerun.py @@ -6,7 +6,9 @@ RERUN_ERRORS = [ 'The server returned an invalid or incomplete response.', '502 Bad Gateway', 'Unexpected server error', - '504 Gateway Time-out' + '504 Gateway Time-out', + 'Internal Server Error', + 'Invalid message: ERROR Internal Server Error' ] diff --git a/test/appium/tests/api_requests.py b/test/appium/tests/api_requests.py deleted file mode 100644 index c9be96438b..0000000000 --- a/test/appium/tests/api_requests.py +++ /dev/null @@ -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']) diff --git a/test/appium/tests/base_test_case.py b/test/appium/tests/base_test_case.py index ec8bc3f381..8441326bd0 100644 --- a/test/appium/tests/base_test_case.py +++ b/test/appium/tests/base_test_case.py @@ -3,12 +3,12 @@ import sys import re import subprocess import asyncio - +from support.network_api import NetworkApi from os import environ from appium import webdriver from abc import ABCMeta, abstractmethod 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 @@ -106,6 +106,8 @@ class AbstractTestCase: errors = [] + network_api = NetworkApi() + def verify_no_errors(self): if 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): 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) diff --git a/test/appium/tests/test_chat_management.py b/test/appium/tests/test_chat_management.py index 38fae1cc04..dfe8e03265 100644 --- a/test/appium/tests/test_chat_management.py +++ b/test/appium/tests/test_chat_management.py @@ -2,11 +2,11 @@ import time import pytest import random import string -import emoji from tests import transaction_users, marks, group_chat_users, get_current_time from tests.base_test_case import MultipleDeviceTestCase, SingleDeviceTestCase from views.sign_in_view import SignInView + @marks.all @marks.chat_management 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_profile_view = device_1_sign_in_view.profile_button.click() 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.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): diff --git a/test/appium/tests/test_transaction.py b/test/appium/tests/test_transaction.py index 5750269aff..00c914fd9d 100644 --- a/test/appium/tests/test_transaction.py +++ b/test/appium/tests/test_transaction.py @@ -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 from selenium.common.exceptions import TimeoutException - -from tests import transaction_users, api_requests, get_current_time, transaction_users_wallet +from tests import transaction_users, get_current_time, transaction_users_wallet, marks from tests.base_test_case import SingleDeviceTestCase, MultipleDeviceTestCase from views.sign_in_view import SignInView 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_address = home_view.public_key_to_address(sender_public_key) 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']) 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') send_transaction_view = chat_view.get_send_transaction_view() 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.set_up_wallet() transactions_view = wallet_view.transactions_button.click() @@ -77,14 +68,13 @@ class TestTransaction(SingleDeviceTestCase): sender_public_key = home_view.get_public_key() sender_address = home_view.public_key_to_address(sender_public_key) 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.get_back_to_home_view() home_view.create_group_chat([recipient['username']], 'trg_%s' % get_current_time()) 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) - 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.testrail_case_id(3404) @@ -93,25 +83,22 @@ class TestTransaction(SingleDeviceTestCase): sign_in_view = SignInView(self.driver) sign_in_view.recover_access(sender['passphrase'], sender['password']) 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.advanced_button.click() profile_view.debug_mode_toggle.click() home_view = profile_view.home_button.click() start_new_chat_view = home_view.plus_button.click() start_new_chat_view.open_d_app_button.click() - start_new_chat_view.simple_dapp_button.scroll_to_element() - simple_dapp = start_new_chat_view.simple_dapp_button.click() + start_new_chat_view.status_test_dapp_button.scroll_to_element() + status_test_dapp = start_new_chat_view.status_test_dapp_button.click() start_new_chat_view.open_button.click() - - simple_dapp.wait_for_d_aap_to_load() - simple_dapp.assets_button.click() - simple_dapp.request_stt_button.click() - + status_test_dapp.wait_for_d_aap_to_load() + status_test_dapp.assets_button.click() + status_test_dapp.request_stt_button.click() send_transaction_view = home_view.get_send_transaction_view() send_transaction_view.sign_transaction(sender['password']) - - api_requests.verify_balance_is_updated(initial_balance, address) + self.network_api.verify_balance_is_updated(initial_balance, address) @pytest.mark.transactions @pytest.mark.testrail_case_id(3422) @@ -170,7 +157,8 @@ class TestTransaction(SingleDeviceTestCase): wallet_view = home_view.wallet_button.click() send_transaction = wallet_view.send_button.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.chose_recipient_button.click() send_transaction.recent_recipients_button.click() @@ -184,6 +172,7 @@ class TestTransaction(SingleDeviceTestCase): send_transaction.got_it_button.click() if sender['password'] in str(home_view.logcat): pytest.fail('Password in logcat!!!', pytrace=False) + self.network_api.find_transaction_by_unique_amount(sender['address'], transaction_amount) @marks.testrail_case_id(3452) def test_sign_transaction_twice(self): @@ -243,10 +232,9 @@ class TestTransactions(MultipleDeviceTestCase): device_1_chat.first_recipient_button.click() device_1_chat.send_as_keyevent(amount) 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') 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.testrail_case_id(3409) @@ -279,10 +267,9 @@ class TestTransactions(MultipleDeviceTestCase): device_1_chat.request_command.click() device_1_chat.send_as_keyevent(amount) 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') 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_wallet = device_2_home.wallet_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.wait_for_visibility_of_element(120) 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') 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) diff --git a/test/appium/tests/test_wallet.py b/test/appium/tests/test_wallet.py index 7a336dd6ef..180f7a2310 100644 --- a/test/appium/tests/test_wallet.py +++ b/test/appium/tests/test_wallet.py @@ -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 tests.base_test_case import SingleDeviceTestCase from views.sign_in_view import SignInView @@ -72,8 +72,8 @@ class TestWallet(SingleDeviceTestCase): password=transaction_users_wallet['A_USER']['password']) wallet = sign_in_view.wallet_button.click() address = transaction_users_wallet['A_USER']['address'] - balance = api_requests.get_balance(address) / 1000000000000000000 - eth_rate = api_requests.get_ethereum_price_in_usd() + balance = self.network_api.get_balance(address) / 1000000000000000000 + eth_rate = self.network_api.get_ethereum_price_in_usd() wallet_balance = wallet.get_eth_value() if 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() sender_public_key = home_view.get_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() sign_in_phrase = wallet_view.set_up_wallet() diff --git a/test/appium/views/base_element.py b/test/appium/views/base_element.py index d985dd2594..91e726662e 100644 --- a/test/appium/views/base_element.py +++ b/test/appium/views/base_element.py @@ -80,6 +80,16 @@ class BaseElement(object): seconds) 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): for _ in range(9): try: diff --git a/test/appium/views/contacts_view.py b/test/appium/views/contacts_view.py index acde3b7b20..87b6191998 100644 --- a/test/appium/views/contacts_view.py +++ b/test/appium/views/contacts_view.py @@ -2,15 +2,15 @@ from views.base_element import BaseButton, BaseEditBox from views.base_view import BaseView -class SimpleDAppButton(BaseButton): +class StatusTestDAppButton(BaseButton): def __init__(self, driver): - super(SimpleDAppButton, self).__init__(driver) - self.locator = self.Locator.text_selector('Simple Dapp') + super(StatusTestDAppButton, self).__init__(driver) + self.locator = self.Locator.text_selector('Status Test DApp') def navigate(self): - from views.web_views.simple_dapp import SimpleDAppWebView - return SimpleDAppWebView(self.driver) + from views.web_views.status_test_dapp import StatusTestDAppView + return StatusTestDAppView(self.driver) class PlusButton(BaseButton): @@ -43,4 +43,4 @@ class ContactsView(BaseView): self.public_key_edit_box = PublicKeyEditBox(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) diff --git a/test/appium/views/home_view.py b/test/appium/views/home_view.py index ed9f6d2aa4..ba376c9a8e 100644 --- a/test/appium/views/home_view.py +++ b/test/appium/views/home_view.py @@ -37,9 +37,14 @@ class ChatElement(BaseButton): from views.chat_view import ChatView 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 def swipe_delete_button(self): - class DeleteButton(BaseButton): def __init__(self, driver, parent_locator: str): super(DeleteButton, self).__init__(driver) diff --git a/test/appium/views/web_views/simple_dapp.py b/test/appium/views/web_views/status_test_dapp.py similarity index 87% rename from test/appium/views/web_views/simple_dapp.py rename to test/appium/views/web_views/status_test_dapp.py index 00b131062e..71415a3ea0 100644 --- a/test/appium/views/web_views/simple_dapp.py +++ b/test/appium/views/web_views/status_test_dapp.py @@ -13,10 +13,10 @@ class AssetsButton(BaseButton): self.locator = self.Locator.text_selector('Request STT') -class SimpleDAppWebView(BaseWebView): +class StatusTestDAppView(BaseWebView): def __init__(self, driver): - super(SimpleDAppWebView, self).__init__(driver) + super(StatusTestDAppView, self).__init__(driver) self.driver = driver self.assets_button = AssetsButton(self.driver)