From 6a17f9387c393352e44863816f07217d763ffb28 Mon Sep 17 00:00:00 2001 From: yevh-berdnyk Date: Tue, 3 Jul 2018 20:50:18 +0200 Subject: [PATCH] Added atomic tests for chats management and DApps Signed-off-by: yevh-berdnyk --- test/appium/support/api/network_api.py | 11 +- test/appium/tests/atomic/browsing/__init__.py | 0 .../atomic/{ => browsing}/test_browsing.py | 36 ++++- .../atomic/chats/test_chats_management.py | 123 ++++++++++++++++++ .../tests/atomic/chats/test_commands.py | 107 +++++++++++++-- .../tests/atomic/chats/test_one_to_one.py | 13 +- test/appium/tests/atomic/chats/test_public.py | 3 - .../tests/atomic/transactions/test_wallet.py | 11 +- test/appium/tests/marks.py | 1 + test/appium/tests/test_chat_management.py | 12 +- test/appium/tests/test_transaction.py | 10 +- test/appium/views/base_element.py | 2 +- test/appium/views/base_view.py | 26 +++- test/appium/views/chat_view.py | 61 ++++++--- test/appium/views/home_view.py | 36 +++-- test/appium/views/profile_view.py | 8 +- 16 files changed, 377 insertions(+), 83 deletions(-) create mode 100644 test/appium/tests/atomic/browsing/__init__.py rename test/appium/tests/atomic/{ => browsing}/test_browsing.py (62%) create mode 100644 test/appium/tests/atomic/chats/test_chats_management.py diff --git a/test/appium/support/api/network_api.py b/test/appium/support/api/network_api.py index 7abaeb3a57..d03e36d4e2 100644 --- a/test/appium/support/api/network_api.py +++ b/test/appium/support/api/network_api.py @@ -15,6 +15,10 @@ class NetworkApi: method = self.ropsten_url + 'module=account&action=txlist&address=0x%s&sort=desc' % address return requests.request('GET', url=method).json()['result'] + def get_token_transaction(self, address: str) -> dict: + method = self.ropsten_url + 'module=account&action=tokentx&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.ropsten_url + 'module=transaction&action=getstatus&txhash=%s' % transaction_hash return not int(requests.request('GET', url=method).json()['result']['isError']) @@ -39,7 +43,7 @@ class NetworkApi: return pytest.fail('Transaction is not found in Ropsten network') - def find_transaction_by_unique_amount(self, address, amount, wait_time=600): + def find_transaction_by_unique_amount(self, address, amount, token=False, wait_time=600): counter = 0 while True: if counter >= wait_time: @@ -49,7 +53,10 @@ class NetworkApi: else: counter += 10 time.sleep(10) - transactions = self.get_transactions(address=address) + if token: + transactions = self.get_token_transaction(address=address) + else: + transactions = self.get_transactions(address=address) info('Looking for a transaction with unique amount %s in list of transactions, address is %s' % (amount, address)) for transaction in transactions: diff --git a/test/appium/tests/atomic/browsing/__init__.py b/test/appium/tests/atomic/browsing/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/appium/tests/atomic/test_browsing.py b/test/appium/tests/atomic/browsing/test_browsing.py similarity index 62% rename from test/appium/tests/atomic/test_browsing.py rename to test/appium/tests/atomic/browsing/test_browsing.py index 0ba5ecf804..ad9d84f7e6 100644 --- a/test/appium/tests/atomic/test_browsing.py +++ b/test/appium/tests/atomic/browsing/test_browsing.py @@ -1,5 +1,5 @@ import pytest -from tests import transaction_users, marks +from tests import marks from tests.base_test_case import SingleDeviceTestCase from views.sign_in_view import SignInView @@ -57,7 +57,39 @@ class TestBrowsing(SingleDeviceTestCase): start_new_chat.confirm() browsing_view = home_view.get_base_web_view() browsing_view.browser_cross_icon.click() - home_view.swipe_and_delete_chat('Browser') + home_view.get_chat_with_user('Browser').swipe_and_delete() home_view.relogin() if home_view.get_chat_with_user('Browser').is_element_present(20): pytest.fail('The browser entry is present after re-login') + + @marks.testrail_id(1396) + def test_open_google_com_via_open_dapp(self): + sign_in_view = SignInView(self.driver) + home = sign_in_view.create_user() + start_new_chat = home.plus_button.click() + start_new_chat.open_d_app_button.click() + start_new_chat.enter_url_editbox.set_value('google.com') + start_new_chat.confirm() + browsing_view = start_new_chat.get_base_web_view() + browsing_view.wait_for_d_aap_to_load() + assert browsing_view.element_by_text('Google').is_element_displayed() + + @marks.testrail_id(1397) + def test_back_forward_buttons_browsing_website(self): + sign_in = SignInView(self.driver) + home = sign_in.create_user() + start_new_chat = home.plus_button.click() + start_new_chat.open_d_app_button.click() + start_new_chat.enter_url_editbox.set_value('www.wikipedia.org') + start_new_chat.confirm() + browsing_view = start_new_chat.get_base_web_view() + browsing_view.wait_for_d_aap_to_load() + + browsing_view.element_by_text_part('Русский', 'button').click() + browsing_view.find_text_part('Избранная статья') + browsing_view.browser_previous_page_button.click() + browsing_view.find_text_part('English', 15) + + browsing_view.browser_next_page_button.click() + browsing_view.find_text_part('Избранная статья') + browsing_view.back_to_home_button.click() diff --git a/test/appium/tests/atomic/chats/test_chats_management.py b/test/appium/tests/atomic/chats/test_chats_management.py new file mode 100644 index 0000000000..0e6529649f --- /dev/null +++ b/test/appium/tests/atomic/chats/test_chats_management.py @@ -0,0 +1,123 @@ +import pytest + +from tests import marks, group_chat_users, transaction_users +from tests.base_test_case import SingleDeviceTestCase +from views.sign_in_view import SignInView + + +@marks.chat +class TestChatManagement(SingleDeviceTestCase): + + @marks.testrail_id(1428) + def test_clear_history(self): + recipient = transaction_users['E_USER'] + sign_in_view = SignInView(self.driver) + sign_in_view.create_user() + home_view = sign_in_view.get_home_view() + home_view.add_contact(recipient['public_key']) + chat_view = home_view.get_chat_view() + for _ in range(4): + chat_view.chat_message_input.send_keys('test message') + chat_view.send_message_button.click() + chat_view.clear_history() + if not chat_view.no_messages_in_chat.is_element_present(): + pytest.fail('Message history is shown') + home_view.relogin() + home_view.get_chat_with_user(recipient['username']).click() + if not chat_view.no_messages_in_chat.is_element_present(): + pytest.fail('Message history is shown after re-login') + + @marks.testrail_id(1395) + def test_swipe_to_delete_1_1_chat(self): + sign_in = SignInView(self.driver) + home = sign_in.create_user() + chat = home.add_contact(group_chat_users['A_USER']['public_key']) + chat.chat_message_input.send_keys('test message') + chat.send_message_button.click() + chat.get_back_to_home_view() + home.get_chat_with_user(group_chat_users['A_USER']['username']).swipe_and_delete() + self.driver.close_app() + self.driver.launch_app() + sign_in.accept_agreements() + sign_in.sign_in() + if home.get_chat_with_user(group_chat_users['A_USER']['username']).is_element_displayed(): + pytest.fail('Deleted 1-1 chat is present after relaunch app') + + @marks.testrail_id(3718) + def test_swipe_to_delete_public_chat(self): + sign_in = SignInView(self.driver) + home = sign_in.create_user() + chat_name = home.get_public_chat_name() + chat = home.join_public_chat(chat_name) + message = 'test message' + chat.chat_message_input.send_keys(message) + chat.send_message_button.click() + chat.get_back_to_home_view() + home.get_chat_with_user('#' + chat_name).swipe_and_delete() + profile = home.profile_button.click() + profile.logout() + sign_in.click_account_by_position(0) + sign_in.sign_in() + if home.get_chat_with_user('#' + chat_name).is_element_displayed(): + self.errors.append('Deleted public chat is present after relogin') + home.join_public_chat(chat_name) + if chat.chat_element_by_text(message).is_element_displayed(): + self.errors.append('Chat history is shown') + self.verify_no_errors() + + @marks.testrail_id(3694) + def test_add_contact_from_public_chat(self): + sign_in = SignInView(self.driver) + home = sign_in.create_user() + chat_name = 'testaddcontact' + chat = home.join_public_chat(chat_name) + message = 'test message' + + chat_element = chat.chat_element_by_text(message) + chat_element.find_element() + username = chat_element.username.text + chat_element.member_photo.click() + for element in [chat.contact_profile_picture, chat.add_to_contacts, chat.profile_send_message, + chat.profile_send_transaction, chat.public_key_text, chat.element_by_text(username, 'text')]: + if not element.is_element_displayed(): + self.errors.append('%s is not visible' % 'user name' if 'Base' in element.name else element.name) + chat.add_to_contacts.click() + if not chat.element_by_text('In contacts').is_element_displayed(): + self.errors.append("'Add to contacts' is not changed to 'In contacts'") + + chat.get_back_to_home_view() + start_new_chat = home.plus_button.click() + start_new_chat.start_new_chat_button.click() + if not start_new_chat.element_by_text(username).is_element_displayed(): + self.errors.append("List of contacts doesn't contain added user") + start_new_chat.get_back_to_home_view() + + home.get_chat_with_user('#' + chat_name).click() + chat.chat_message_input.send_keys(message) + chat.send_message_button.click() + self.verify_no_errors() + + @marks.testrail_id(763) + def test_add_contact_by_pasting_public_key(self): + sign_in = SignInView(self.driver) + home = sign_in.create_user() + public_key = group_chat_users['A_USER']['public_key'] + + chat = home.join_public_chat(home.get_public_chat_name()) + chat.chat_message_input.send_keys(public_key) + chat.send_message_button.click() + chat.chat_element_by_text(public_key).long_press_element() + chat.element_by_text('Copy to clipboard').click() + chat.get_back_to_home_view() + + start_new_chat = home.plus_button.click() + start_new_chat.start_new_chat_button.click() + start_new_chat.public_key_edit_box.paste_text_from_clipboard() + if start_new_chat.public_key_edit_box.text != public_key: + pytest.fail('Public key is not pasted from clipboard') + start_new_chat.confirm() + start_new_chat.get_back_to_home_view() + home.plus_button.click() + start_new_chat.start_new_chat_button.click() + if not start_new_chat.element_by_text(group_chat_users['A_USER']['username']).is_element_displayed(): + pytest.fail("List of contacts doesn't contain added user") diff --git a/test/appium/tests/atomic/chats/test_commands.py b/test/appium/tests/atomic/chats/test_commands.py index 0b9fb1b097..060b9106d6 100644 --- a/test/appium/tests/atomic/chats/test_commands.py +++ b/test/appium/tests/atomic/chats/test_commands.py @@ -1,15 +1,17 @@ +import random + from _pytest.outcomes import Failed from decimal import Decimal as d from selenium.common.exceptions import TimeoutException from tests import marks, transaction_users, common_password, group_chat_users -from tests.base_test_case import MultipleDeviceTestCase +from tests.base_test_case import MultipleDeviceTestCase, SingleDeviceTestCase from views.sign_in_view import SignInView @marks.chat @marks.transaction -class TestCommands(MultipleDeviceTestCase): +class TestCommandsMultipleDevices(MultipleDeviceTestCase): @marks.testrail_case_id(3742) @marks.testrail_id(3697) @@ -29,7 +31,7 @@ class TestCommands(MultipleDeviceTestCase): device_1_chat = device_1_home.add_contact(public_key) amount_1 = device_1_chat.get_unique_amount() - device_1_chat.send_transaction_in_1_1_chat(amount_1, common_password, wallet_set_up=True) + device_1_chat.send_transaction_in_1_1_chat('ETH', amount_1, common_password, wallet_set_up=True) status_text_1 = device_1_chat.chat_element_by_text(amount_1).status.text if status_text_1 != 'Sent': self.errors.append("Message about sent funds has status '%s' instead of 'Sent'" % status_text_1) @@ -46,7 +48,7 @@ class TestCommands(MultipleDeviceTestCase): self.errors.append('Sent transaction message was not received') amount_2 = device_1_chat.get_unique_amount() - device_1_chat.request_transaction_in_1_1_chat(amount_2) + device_1_chat.request_transaction_in_1_1_chat('ETH', amount_2) status_text_2 = device_1_chat.chat_element_by_text(amount_2).status.text if status_text_2 != 'Sent': self.errors.append("Request funds message has status '%s' instead of 'Sent'" % status_text_2) @@ -83,7 +85,7 @@ class TestCommands(MultipleDeviceTestCase): amount = chat_1.get_unique_amount() chat_1.commands_button.click() chat_1.send_command.click() - chat_1.eth_asset.click() + chat_1.asset_by_name('ETH').click() chat_1.send_as_keyevent(amount) send_transaction_view = chat_1.get_send_transaction_view() chat_1.send_message_button.click_until_presence_of_element(send_transaction_view.sign_transaction_button) @@ -147,17 +149,15 @@ class TestCommands(MultipleDeviceTestCase): chat_2 = home_2.add_contact(sender['public_key']) amount = chat_2.get_unique_amount() - chat_2.request_transaction_in_1_1_chat(amount) + chat_2.request_transaction_in_1_1_chat('ETH', amount) chat_1 = home_1.get_chat_with_user(recipient['username']).click() - chat_1.send_eth_to_request(amount=amount, sender_password=sender['password']) + chat_1.send_funds_to_request(amount=amount, sender_password=sender['password']) if not chat_1.chat_element_by_text(amount).is_element_displayed(): self.errors.append('Message with the sent amount is not shown for the sender') if not chat_2.chat_element_by_text(amount).is_element_displayed(): self.errors.append('Message with the sent amount is not shown for the recipient') - if chat_2.chat_element_by_text(amount).send_request_button.is_element_displayed(): - self.errors.append("'Send' in a transaction request button is not disabled after receiving transaction") chat_2.get_back_to_home_view() home_2.wallet_button.click() @@ -228,10 +228,97 @@ class TestCommands(MultipleDeviceTestCase): chat_view.view_profile_button.click() chat_view.profile_send_transaction.click() chat_view.chat_message_input.click() - chat_view.eth_asset.click() + chat_view.asset_by_name('ETH').click() amount = chat_view.get_unique_amount() chat_view.send_as_keyevent(amount) chat_view.send_message_button.click() send_transaction_view = chat_view.get_send_transaction_view() send_transaction_view.sign_transaction(common_password) self.network_api.find_transaction_by_unique_amount(recipient['address'], amount) + + @marks.testrail_id(3744) + def test_send_tokens_in_1_1_chat(self): + recipient = transaction_users['D_USER'] + sender = transaction_users['C_USER'] + self.create_drivers(2) + device_1, device_2 = SignInView(self.drivers[0]), SignInView(self.drivers[1]) + home_1 = device_1.recover_access(passphrase=sender['passphrase'], password=sender['password']) + home_2 = device_2.recover_access(passphrase=recipient['passphrase'], password=recipient['password']) + wallet_1, wallet_2 = home_1.wallet_button.click(), home_2.wallet_button.click() + wallet_1.set_up_wallet() + wallet_1.home_button.click() + wallet_2.set_up_wallet() + wallet_2.home_button.click() + + chat_1 = home_1.add_contact(recipient['public_key']) + amount = chat_1.get_unique_amount() + chat_1.send_transaction_in_1_1_chat('STT', amount, sender['password']) + + message_1 = chat_1.chat_element_by_text(amount) + if not message_1.is_element_displayed() or not message_1.contains_text('STT'): + self.errors.append('Message with the sent amount is not shown for the sender') + chat_2 = home_2.get_chat_with_user(sender['username']).click() + message_2 = chat_2.chat_element_by_text(amount) + if not message_2.is_element_displayed() or not message_2.contains_text('STT'): + self.errors.append('Message with the sent amount is not shown for the recipient') + + try: + self.network_api.find_transaction_by_unique_amount(recipient['address'], amount, token=True) + except Failed as e: + self.errors.append(e.msg) + self.verify_no_errors() + + @marks.testrail_id(3748) + def test_request_and_receive_tokens_in_1_1_chat(self): + recipient = transaction_users['C_USER'] + sender = transaction_users['D_USER'] + self.create_drivers(2) + device_1, device_2 = SignInView(self.drivers[0]), SignInView(self.drivers[1]) + home_1 = device_1.recover_access(passphrase=sender['passphrase'], password=sender['password']) + home_2 = device_2.recover_access(passphrase=recipient['passphrase'], password=recipient['password']) + wallet_1, wallet_2 = home_1.wallet_button.click(), home_2.wallet_button.click() + wallet_1.set_up_wallet() + wallet_1.home_button.click() + wallet_2.set_up_wallet() + wallet_2.home_button.click() + + chat_2 = home_2.add_contact(sender['public_key']) + amount = chat_2.get_unique_amount() + chat_2.request_transaction_in_1_1_chat('STT', amount) + + chat_1 = home_1.get_chat_with_user(recipient['username']).click() + chat_1.send_funds_to_request(amount=amount, sender_password=sender['password']) + + message_1 = chat_1.chat_element_by_text(amount) + if not message_1.is_element_displayed() or not message_1.contains_text('STT'): + self.errors.append('Message with the sent amount is not shown for the sender') + message_2 = chat_2.chat_element_by_text(amount) + if not message_2.is_element_displayed() or not message_2.contains_text('STT'): + self.errors.append('Message with the sent amount is not shown for the recipient') + + try: + self.network_api.find_transaction_by_unique_amount(recipient['address'], amount, token=True) + except Failed as e: + self.errors.append(e.msg) + self.verify_no_errors() + + +@marks.chat +@marks.transaction +class TestCommandsSingleDevices(SingleDeviceTestCase): + + @marks.testrail_id(3745) + def test_send_request_not_enabled_tokens(self): + sign_in = SignInView(self.driver) + home = sign_in.create_user() + chat = home.add_contact(transaction_users['D_USER']['public_key']) + chat.commands_button.click() + chat.send_command.click() + if chat.asset_by_name('MDS').is_element_displayed(): + self.errors.append('Token which is not enabled in wallet can be sent in 1-1 chat') + chat.chat_message_input.clear() + chat.commands_button.click() + chat.request_command.click() + if chat.asset_by_name('MDS').is_element_displayed(): + self.errors.append('Token which is not enabled in wallet can be requested in 1-1 chat') + self.verify_no_errors() diff --git a/test/appium/tests/atomic/chats/test_one_to_one.py b/test/appium/tests/atomic/chats/test_one_to_one.py index 0c7d0631b5..d959d9c601 100644 --- a/test/appium/tests/atomic/chats/test_one_to_one.py +++ b/test/appium/tests/atomic/chats/test_one_to_one.py @@ -15,9 +15,8 @@ class TestMessagesOneToOneChatMultiple(MultipleDeviceTestCase): def test_text_message_1_1_chat(self): self.create_drivers(2) device_1, device_2 = SignInView(self.drivers[0]), SignInView(self.drivers[1]) - for sign_in in device_1, device_2: - sign_in.create_user() - device_1_home, device_2_home = device_1.get_home_view(), device_2.get_home_view() + username_1 = 'user_%s' % get_current_time() + device_1_home, device_2_home = device_1.create_user(username=username_1), device_2.create_user() device_2_public_key = device_2_home.get_public_key() device_2_home.home_button.click() @@ -27,8 +26,7 @@ class TestMessagesOneToOneChatMultiple(MultipleDeviceTestCase): device_1_chat.chat_message_input.send_keys(message) device_1_chat.send_message_button.click() - device_2_home.element_by_text(message, 'button').click() - device_2_home.connection_status.wait_for_invisibility_of_element(30) + device_2_home.get_chat_with_user(username_1).click() if device_1_chat.chat_element_by_text(message).status.text != 'Seen': pytest.fail("'Seen' status is not shown under the sent text message") @@ -53,6 +51,8 @@ class TestMessagesOneToOneChatMultiple(MultipleDeviceTestCase): device_1.set_network_connection(2) # turning on WiFi connection on primary device + if 'Tap to reconnect' in home_1.connection_status.text: + home_2.connection_status.click() chat_element = home_1.get_chat_with_user(username_2) chat_element.wait_for_visibility_of_element(20) chat_1 = chat_element.click() @@ -98,7 +98,7 @@ class TestMessagesOneToOneChatMultiple(MultipleDeviceTestCase): if not chat_1.element_by_text('Delete message').is_element_displayed(): self.errors.append("'Delete message' button is not shown for not sent message") - chat_1.connection_status.wait_for_invisibility_of_element(60) + chat_1.reconnect() chat_1.element_by_text('Resend').click() if chat_1.chat_element_by_text(message).status.text != 'Sent': self.errors.append("Message status is not 'Sent' after resending the message") @@ -235,7 +235,6 @@ class TestMessagesOneToOneChatMultiple(MultipleDeviceTestCase): chat_1.chat_message_input.send_keys(url_message) chat_1.send_message_button.click() chat_1.get_back_to_home_view() - home_2.connection_status.wait_for_invisibility_of_element(30) chat_2 = home_2.get_chat_with_user(username_1).click() chat_2.element_starts_with_text(url_message, 'button').click() web_view = chat_2.open_in_browser_button.click() diff --git a/test/appium/tests/atomic/chats/test_public.py b/test/appium/tests/atomic/chats/test_public.py index ec07b04915..559b1bb8ac 100644 --- a/test/appium/tests/atomic/chats/test_public.py +++ b/test/appium/tests/atomic/chats/test_public.py @@ -22,9 +22,6 @@ class TestPublicChat(MultipleDeviceTestCase): public_chat_name = home_1.get_public_chat_name() chat_1, chat_2 = home_1.join_public_chat(public_chat_name), home_2.join_public_chat(public_chat_name) - if chat_2.connection_status.text != 'Fetching messages...': - self.errors.append("'Fetching messages...' status is not shown") - message = 'hello' chat_1.chat_message_input.send_keys(message) chat_1.send_message_button.click() diff --git a/test/appium/tests/atomic/transactions/test_wallet.py b/test/appium/tests/atomic/transactions/test_wallet.py index 6a511d65e7..a73e3be354 100644 --- a/test/appium/tests/atomic/transactions/test_wallet.py +++ b/test/appium/tests/atomic/transactions/test_wallet.py @@ -1,9 +1,6 @@ -import pytest -from selenium.common.exceptions import TimeoutException -from tests import transaction_users, get_current_time, transaction_users_wallet, marks, common_password -from tests.base_test_case import SingleDeviceTestCase, MultipleDeviceTestCase +from tests import transaction_users, transaction_users_wallet, marks, common_password +from tests.base_test_case import SingleDeviceTestCase from views.sign_in_view import SignInView -from views.web_views.base_web_view import BaseWebView @marks.transaction @@ -77,7 +74,8 @@ class TestTransactionWallet(SingleDeviceTestCase): send_transaction.select_asset_button.click_until_presence_of_element(send_transaction.stt_button) send_transaction.stt_button.click() send_transaction.amount_edit_box.click() - send_transaction.amount_edit_box.set_value(send_transaction.get_unique_amount()) + amount = send_transaction.get_unique_amount() + send_transaction.amount_edit_box.set_value(amount) send_transaction.confirm() send_transaction.chose_recipient_button.click() send_transaction.enter_recipient_address_button.click() @@ -87,6 +85,7 @@ class TestTransactionWallet(SingleDeviceTestCase): send_transaction.enter_password_input.send_keys(sender['password']) send_transaction.sign_transaction_button.click() send_transaction.got_it_button.click() + self.network_api.find_transaction_by_unique_amount(recipient['address'], amount, token=True) @marks.testrail_id(2164) def test_transaction_wrong_password_wallet(self): diff --git a/test/appium/tests/marks.py b/test/appium/tests/marks.py index 1b980a2a45..da31f7d70f 100644 --- a/test/appium/tests/marks.py +++ b/test/appium/tests/marks.py @@ -9,6 +9,7 @@ all = pytest.mark.all api = pytest.mark.api chat = pytest.mark.chat chat_management = pytest.mark.chat_management +dapps = pytest.mark.dapps message_reliability = pytest.mark.message_reliability transaction = pytest.mark.transaction wallet = pytest.mark.wallet diff --git a/test/appium/tests/test_chat_management.py b/test/appium/tests/test_chat_management.py index 4964489528..6cad9b66ff 100644 --- a/test/appium/tests/test_chat_management.py +++ b/test/appium/tests/test_chat_management.py @@ -41,9 +41,9 @@ class TestChatManagementMultiple(MultipleDeviceTestCase): # Devices: Request and send transactions transaction_amount = '0.00001' - device_1_chat_view.request_transaction_in_1_1_chat(transaction_amount) + device_1_chat_view.request_transaction_in_1_1_chat('ETH', transaction_amount) device_1_chat_view.send_transaction_in_1_1_chat(transaction_amount, self.senders['g_user']['password']) - device_2_chat_view.request_transaction_in_1_1_chat(transaction_amount) + device_2_chat_view.request_transaction_in_1_1_chat('ETH', transaction_amount) device_2_chat_view.send_transaction_in_1_1_chat(transaction_amount, self.senders['h_user']['password']) # Device 1: Send message to device 2 @@ -117,7 +117,7 @@ class TestChatManagementMultiple(MultipleDeviceTestCase): chat_1.get_back_to_home_view() home_1 = chat_1.get_home_view() - home_1.swipe_and_delete_chat(public_chat_name) + home_1.get_chat_with_user(public_chat_name).swipe_and_delete() for home in home_2, home_1: home.relogin() @@ -144,7 +144,7 @@ class TestChatManagement(SingleDeviceTestCase): chat_view.chat_message_input.send_keys('test message') chat_view.send_message_button.click() chat_view.get_back_to_home_view() - home_view.swipe_and_delete_chat(recipient['username'][:20]) + home_view.get_chat_with_user(recipient['username']).swipe_and_delete() home_view.relogin() if home_view.get_chat_with_user(recipient['username']).is_element_present(20): pytest.fail('The chat is present after re-login') @@ -161,7 +161,7 @@ class TestChatManagement(SingleDeviceTestCase): chat_view.chat_message_input.send_keys('test message') chat_view.send_message_button.click() transaction_amount = '0.00001' - chat_view.request_transaction_in_1_1_chat(transaction_amount) + chat_view.request_transaction_in_1_1_chat('ETH', transaction_amount) chat_view.send_transaction_in_1_1_chat(transaction_amount, sender['password'], wallet_set_up=True) chat_view.delete_chat(recipient['username'], self.errors) if home_view.get_chat_with_user(recipient['username']).is_element_present(5): @@ -189,7 +189,7 @@ class TestChatManagement(SingleDeviceTestCase): chat_view.chat_message_input.send_keys('This is text message!') chat_view.send_message_button.click() chat_view.get_back_to_home_view() - home_view.swipe_and_delete_chat(chat_name) + home_view.get_chat_with_user(chat_name).swipe_and_delete() home_view.relogin() if home_view.get_chat_with_user(chat_name).is_element_displayed(): pytest.fail('The chat is present after re-login') diff --git a/test/appium/tests/test_transaction.py b/test/appium/tests/test_transaction.py index 8c3b5e5e8f..2e0fba65aa 100644 --- a/test/appium/tests/test_transaction.py +++ b/test/appium/tests/test_transaction.py @@ -48,7 +48,7 @@ class TestTransaction(SingleDeviceTestCase): chat_view = home_view.get_chat_with_user(recipient['username']).click() chat_view.commands_button.click() chat_view.send_command.click() - chat_view.eth_asset.click() + chat_view.asset_by_name('ETH').click() chat_view.send_as_keyevent(transaction_amount) wallet_view = chat_view.get_wallet_view() chat_view.send_message_button.click_until_presence_of_element(wallet_view.sign_in_phrase) @@ -220,7 +220,7 @@ class TestTransactions(MultipleDeviceTestCase): device_1_chat.first_recipient_button.click() device_1_chat.send_as_keyevent(amount) device_1_chat.send_message_button.click() - device_2_chat.send_eth_to_request(amount, sender['password']) + device_2_chat.send_funds_to_request(amount, sender['password']) self.network_api.find_transaction_by_unique_amount(recipient['address'], amount) @marks.pr @@ -252,10 +252,10 @@ class TestTransactions(MultipleDeviceTestCase): one_to_one_chat_device_2.click_until_presence_of_element(device_2_chat.commands_button) device_1_chat.commands_button.click_until_presence_of_element(device_1_chat.request_command) device_1_chat.request_command.click() - device_1_chat.eth_asset.click() + device_1_chat.asset_by_name('ETH').click() device_1_chat.send_as_keyevent(amount) device_1_chat.send_message_button.click() - device_2_chat.send_eth_to_request(amount, sender['password'], wallet_set_up=True) + device_2_chat.send_funds_to_request(amount, sender['password'], wallet_set_up=True) 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() @@ -294,5 +294,5 @@ 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() - device_2_chat.send_eth_to_request(amount, sender['password'], wallet_set_up=True) + device_2_chat.send_funds_to_request(amount, sender['password'], wallet_set_up=True) self.network_api.find_transaction_by_unique_amount(recipient['address'], amount) diff --git a/test/appium/views/base_element.py b/test/appium/views/base_element.py index ce5c6a912b..a81defa689 100644 --- a/test/appium/views/base_element.py +++ b/test/appium/views/base_element.py @@ -151,7 +151,7 @@ class BaseElement(object): location, size = element.location, element.size x, y = location['x'], location['y'] width, height = size['width'], size['height'] - self.driver.swipe(start_x=x + width * 2, start_y=y + height / 2, end_x=x, end_y=y + height / 2) + self.driver.swipe(start_x=x + width * 0.75, start_y=y + height / 2, end_x=x, end_y=y + height / 2) def long_press_element(self): element = self.find_element() diff --git a/test/appium/views/base_view.py b/test/appium/views/base_view.py index f9b13bd62b..56af580e8a 100644 --- a/test/appium/views/base_view.py +++ b/test/appium/views/base_view.py @@ -212,13 +212,13 @@ class BaseView(object): def accept_agreements(self): iterations = int() from views.sign_in_view import CreateAccountButton, PasswordInput - while iterations <= 3 and not (CreateAccountButton(self.driver).is_element_displayed() or PasswordInput( - self.driver).is_element_displayed()): + if self.test_fairy_warning.is_element_displayed(10): + self.test_fairy_warning.is_shown = True + while iterations <= 3 and not (CreateAccountButton(self.driver).is_element_displayed(2) or PasswordInput( + self.driver).is_element_displayed(2)): for button in self.ok_button, self.continue_button: - if self.test_fairy_warning.is_element_displayed(): - self.test_fairy_warning.is_shown = True try: - button.wait_for_element(15) + button.wait_for_element(3) button.click() except (NoSuchElementException, TimeoutException): pass @@ -236,6 +236,10 @@ class BaseView(object): info('Click system back button') self.driver.press_keycode(4) + def cut_text(self): + info('Cut text') + self.driver.press_keycode(277) + def copy_text(self): info('Copy text') self.driver.press_keycode(278) @@ -391,3 +395,15 @@ class BaseView(object): self.send_as_keyevent('+0') self.confirm() self.element_by_accessibility_id('Send Message').click() + + def reconnect(self): + connect_status = self.connection_status + for i in range(3): + if connect_status.is_element_displayed(5) and 'Tap to reconnect' in connect_status.text: + connect_status.click() + try: + connect_status.wait_for_invisibility_of_element() + except TimeoutException as e: + if i == 2: + e.msg = "Can't reconnect to mail server after 3 attempts" + raise e diff --git a/test/appium/views/chat_view.py b/test/appium/views/chat_view.py index 1ac3bf3ae6..83c1c47341 100644 --- a/test/appium/views/chat_view.py +++ b/test/appium/views/chat_view.py @@ -1,11 +1,11 @@ import time import pytest -from selenium.common.exceptions import TimeoutException +from selenium.common.exceptions import TimeoutException, NoSuchElementException from tests import info from views.base_element import BaseButton, BaseEditBox, BaseText, BaseElement from views.base_view import BaseView -from views.profile_view import ProfilePictureElement +from views.profile_view import ProfilePictureElement, PublicKeyText class ChatMessageInput(BaseEditBox): @@ -45,10 +45,10 @@ class RequestCommand(BaseButton): self.locator = self.Locator.accessibility_id('request-payment-button') -class EthAsset(BaseButton): - def __init__(self, driver): - super(EthAsset, self).__init__(driver) - self.locator = self.Locator.text_selector('ETH') +class AssetCommand(BaseButton): + def __init__(self, driver, asset): + super(AssetCommand, self).__init__(driver) + self.locator = self.Locator.text_selector(asset) class ChatMenuButton(BaseButton): @@ -173,9 +173,18 @@ class ProfileSendTransactionButton(BaseButton): class ChatElementByText(BaseText): def __init__(self, driver, text): super(ChatElementByText, self).__init__(driver) + self.message_text = text self.locator = self.Locator.xpath_selector( "//*[starts-with(@text,'%s')]/ancestor::android.view.ViewGroup[@content-desc='chat-item']" % text) + def find_element(self): + info("Looking for message with text '%s'" % self.message_text) + for _ in range(2): + try: + return super(ChatElementByText, self).find_element() + except NoSuchElementException: + ChatView(self.driver).reconnect() + @property def status(self): class StatusText(BaseText): @@ -194,11 +203,14 @@ class ChatElementByText(BaseText): return ProgressBar(self.driver, self.locator.value) - def contains_text(self, text) -> bool: - element = BaseText(self.driver) - element.locator = element.Locator.xpath_selector( - self.locator.value + "//android.view.ViewGroup//android.widget.TextView[@text='%s']" % text) - return element.is_element_displayed() + @property + def member_photo(self): + class MemberPhoto(BaseButton): + def __init__(self, driver, parent_locator): + super(MemberPhoto, self).__init__(driver) + self.locator = self.Locator.xpath_selector(parent_locator + "//*[@content-desc='member-photo']") + + return MemberPhoto(self.driver, self.locator.value) @property def username(self): @@ -218,6 +230,12 @@ class ChatElementByText(BaseText): return SendRequestButton(self.driver, self.locator.value) + def contains_text(self, text) -> bool: + element = BaseText(self.driver) + element.locator = element.Locator.xpath_selector( + self.locator.value + "//android.view.ViewGroup//android.widget.TextView[contains(@text,'%s')]" % text) + return element.is_element_displayed() + class ChatView(BaseView): def __init__(self, driver): @@ -231,7 +249,6 @@ class ChatView(BaseView): self.commands_button = CommandsButton(self.driver) self.send_command = SendCommand(self.driver) self.request_command = RequestCommand(self.driver) - self.eth_asset = EthAsset(self.driver) self.chat_options = ChatMenuButton(self.driver) self.members_button = MembersButton(self.driver) @@ -255,6 +272,7 @@ class ChatView(BaseView): self.contact_profile_picture = ProfilePictureElement(self.driver) self.profile_send_message = ProfileSendMessageButton(self.driver) self.profile_send_transaction = ProfileSendTransactionButton(self.driver) + self.public_key_text = PublicKeyText(self.driver) def wait_for_syncing_complete(self): info('Waiting for syncing complete:') @@ -288,7 +306,7 @@ class ChatView(BaseView): errors.append('Not received messages from user %s: "%s"' % (username, ', '.join( [i for i in list(set(expected_messages) - set(received_messages))]))) - def send_eth_to_request(self, amount, sender_password, wallet_set_up=False): + def send_funds_to_request(self, amount, sender_password, wallet_set_up=False): gas_popup = self.element_by_text_part('Specify amount') send_request_button = self.chat_element_by_text(amount).send_request_button send_request_button.click_until_presence_of_element(gas_popup) @@ -312,10 +330,10 @@ class ChatView(BaseView): self.clear_history_button.click() self.clear_button.click() - def send_transaction_in_1_1_chat(self, amount, password, wallet_set_up=False): + def send_transaction_in_1_1_chat(self, asset, amount, password, wallet_set_up=False): self.commands_button.click() self.send_command.click() - self.eth_asset.click() + self.asset_by_name(asset).click() self.send_as_keyevent(amount) send_transaction_view = self.get_send_transaction_view() if wallet_set_up: @@ -345,15 +363,15 @@ class ChatView(BaseView): send_transaction_view.find_full_text(amount) self.find_full_text('to ' + recipient['username'], 10) - def request_transaction_in_1_1_chat(self, amount): + def request_transaction_in_1_1_chat(self, asset, amount): self.commands_button.click() self.request_command.click() - self.eth_asset.click() + self.asset_by_name(asset).click() self.send_as_keyevent(amount) self.send_message_button.click() def chat_element_by_text(self, text): - info("Looking for full text: '%s'" % text) + info("Looking for a message by text: '%s'" % text) return ChatElementByText(self.driver, text) def verify_message_is_under_today_text(self, text, errors): @@ -364,4 +382,9 @@ class ChatView(BaseView): today_location = today_text_element.location['y'] today_height = today_text_element.size['height'] if message_location < today_location + today_height: - errors.append("Message '%s' is not uder 'Today' text" % text) + errors.append("Message '%s' is not under 'Today' text" % text) + + def asset_by_name(self, asset_name): + element = BaseButton(self.driver) + element.locator = element.Locator.text_selector(asset_name) + return element diff --git a/test/appium/views/home_view.py b/test/appium/views/home_view.py index 115f0b0cc3..4c8e22dff4 100644 --- a/test/appium/views/home_view.py +++ b/test/appium/views/home_view.py @@ -1,6 +1,6 @@ from tests import info import time -from selenium.common.exceptions import TimeoutException +from selenium.common.exceptions import TimeoutException, NoSuchElementException from views.base_element import BaseButton, BaseText from views.base_view import BaseView @@ -32,7 +32,8 @@ class ChatElement(BaseButton): def __init__(self, driver, username_part): super(ChatElement, self).__init__(driver) self.username = username_part - self.locator = self.Locator.xpath_selector("//*[starts-with(@text,'%s')]" % self.username) + self.locator = self.Locator.xpath_selector( + "//*[@content-desc='chat-item'][.//*[starts-with(@text,'%s')]]" % self.username) def navigate(self): if self.username == 'Status Console': @@ -48,16 +49,34 @@ class ChatElement(BaseButton): self.click_until_presence_of_element(desired_element=desired_element) return self.navigate() + def find_element(self): + info('Looking for %s' % self.name) + for _ in range(2): + try: + return super(ChatElement, self).find_element() + except NoSuchElementException: + HomeView(self.driver).reconnect() + @property def swipe_delete_button(self): class DeleteButton(BaseButton): def __init__(self, driver, parent_locator: str): super(DeleteButton, self).__init__(driver) - locator_str = "/../../following-sibling::*[1][name()='android.view.ViewGroup']/*[@content-desc='icon']" + locator_str = "/android.view.ViewGroup/*[@content-desc='icon']" self.locator = self.Locator.xpath_selector(parent_locator + locator_str) return DeleteButton(self.driver, self.locator.value) + def swipe_and_delete(self): + counter = 0 + while counter < 10: + self.swipe_element() + if self.swipe_delete_button.is_element_present(): + break + time.sleep(10) + counter += 1 + self.swipe_delete_button.click() + class ChatNameText(BaseText): def __init__(self, driver): @@ -127,14 +146,3 @@ class HomeView(BaseView): start_new_chat.confirm() from views.chat_view import ChatView return ChatView(self.driver) - - def swipe_and_delete_chat(self, chat_name: str): - chat_element = self.get_chat_with_user(chat_name) - counter = 0 - while counter < 10: - chat_element.swipe_element() - if chat_element.swipe_delete_button.is_element_present(): - break - time.sleep(10) - counter += 1 - chat_element.swipe_delete_button.click() diff --git a/test/appium/views/profile_view.py b/test/appium/views/profile_view.py index 49ef36da65..3b6e84929f 100644 --- a/test/appium/views/profile_view.py +++ b/test/appium/views/profile_view.py @@ -371,9 +371,11 @@ class ProfileView(BaseView): self.select_from_gallery_button.click() if self.allow_button.is_element_displayed(sec=10): self.allow_button.click() - for element_text in 'Images', 'DCIM': - self.element_by_text(element_text).click() - self.element_by_text(file_name).click() + picture = self.element_by_text(file_name) + if not picture.is_element_displayed(2): + for element_text in 'Images', 'DCIM': + self.element_by_text(element_text).click() + picture.click() self.confirm_button.click() def logout(self):