From d9755f546d87133bfc5f51c60be3c7e5fb1e3ede Mon Sep 17 00:00:00 2001 From: Lukasz Fryc Date: Thu, 26 Apr 2018 08:22:11 +0200 Subject: [PATCH] Add appium test about deleting 1-1 chat --- test/appium/tests/__init__.py | 16 +++++ test/appium/tests/base_test_case.py | 12 +++- test/appium/tests/test_chat_management.py | 75 +++++++++++++++++++++++ test/appium/tests/test_messaging.py | 5 +- test/appium/tests/test_sanity.py | 2 +- test/appium/tests/test_transaction.py | 43 +++---------- test/appium/views/base_element.py | 9 +++ test/appium/views/base_view.py | 4 +- test/appium/views/chat_view.py | 46 +++++++++++++- test/appium/views/home_view.py | 7 +++ test/appium/views/profile_view.py | 22 ++++++- test/appium/views/sign_in_view.py | 6 +- 12 files changed, 201 insertions(+), 46 deletions(-) create mode 100644 test/appium/tests/test_chat_management.py diff --git a/test/appium/tests/__init__.py b/test/appium/tests/__init__.py index d6a7de5b67..462dc866b9 100644 --- a/test/appium/tests/__init__.py +++ b/test/appium/tests/__init__.py @@ -96,6 +96,22 @@ transaction_users['F_USER']['address'] = "08fee8015ec71d78b1855937988d5bf45892bc transaction_users['F_USER']['public_key'] = "0x0445284807c9fb9080cec6f1bd24f8d546c5c2c0dd2d06bdbf91d1af70507885" \ "1b9ee0d3bb04736abd00f5a8dce2f20a579a437ee3bea9920eefba7fa46266f8df" +transaction_users['G_USER'] = dict() +transaction_users['G_USER']['password'] = 'qwerty' +transaction_users['G_USER']['passphrase'] = 'sorry assume clutch category grace lift text drift ankle tenant price inside' +transaction_users['G_USER']['username'] = 'Corny Jumpy Argusfish' +transaction_users['G_USER']['address'] = '0xcd22ac97164257fa832104b94286e0d839a42cfc' +transaction_users['G_USER']['public_key'] = '0x04e53b6e5c602208d34b436fec90d4b85d171e5583d4371be57c7994a247e4ab3333c8ea2' \ + '42978d80dda9a0279c90050f4d33ea83b1bb71b7b1297a68e769be9b7' + +transaction_users['H_USER'] = dict() +transaction_users['H_USER']['password'] = 'qwerty' +transaction_users['H_USER']['passphrase'] = 'expect attract panther inhale essence illegal muffin power cabbage correct market gun' +transaction_users['H_USER']['username'] = 'Marvelous Round Argali' +transaction_users['H_USER']['address'] = '0xbbb5bf58c92bd48e27fa508ed544da8472bbb26c' +transaction_users['H_USER']['public_key'] = '0x04862eb3a2f08bb0469380a0ea8deb06f1c9af57e839cc7e783edd209058b72a0049596a' \ + '16faba47f53b629958b435d19857b949fb3bb4a8cfc8f577cbac96609d' + transaction_users_wallet = dict() transaction_users_wallet['A_USER'] = dict() transaction_users_wallet['A_USER']['password'] = "new_unique_password" diff --git a/test/appium/tests/base_test_case.py b/test/appium/tests/base_test_case.py index fc27df6aaf..e6cfe428c7 100644 --- a/test/appium/tests/base_test_case.py +++ b/test/appium/tests/base_test_case.py @@ -8,7 +8,7 @@ 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 +from tests import test_suite_data, start_threads, api_requests from views.base_view import BaseView @@ -195,4 +195,12 @@ environments = {'local': LocalMultipleDeviceTestCase, class MultipleDeviceTestCase(environments[pytest.config.getoption('env')]): - pass + def setup_method(self, method): + super(MultipleDeviceTestCase, self).setup_method(method) + self.senders = dict() + + def teardown_method(self, method): + for user in self.senders: + api_requests.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 new file mode 100644 index 0000000000..c24d361757 --- /dev/null +++ b/test/appium/tests/test_chat_management.py @@ -0,0 +1,75 @@ +import time + +import pytest + +from tests import transaction_users +from tests.base_test_case import MultipleDeviceTestCase +from views.sign_in_view import SignInView + + +@pytest.mark.all +@pytest.mark.chat_management +class TestChatManagement(MultipleDeviceTestCase): + + @pytest.mark.testrail_case_id(3412) + def test_delete_1_1_chat(self): + self.senders['g_user'] = transaction_users['G_USER'] + self.senders['h_user'] = transaction_users['H_USER'] + + self.create_drivers(2) + device_1 = self.drivers[0] + device_2 = self.drivers[1] + + device_1_sign_in_view = SignInView(device_1) + device_1_sign_in_view.recover_access(self.senders['g_user']['passphrase'], self.senders['g_user']['password']) + device_2_sign_in_view = SignInView(device_2) + device_2_sign_in_view.recover_access(self.senders['h_user']['passphrase'], self.senders['h_user']['password']) + + device_1_home_view = device_1_sign_in_view.get_home_view() + device_2_home_view = device_2_sign_in_view.get_home_view() + + # Device 1: Start new 1-1 chat + device_1_home_view.add_contact(self.senders['h_user']['public_key']) + device_1_chat_view = device_1_home_view.get_chat_view() + chat_with_g_user = device_2_home_view.get_chat_with_user(self.senders['g_user']['username']) + chat_with_g_user.wait_for_element(30) + device_2_chat_view = chat_with_g_user.click() + + # 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.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.send_transaction_in_1_1_chat(transaction_amount, self.senders['h_user']['password']) + + # Device 1: Send message to device 2 + device_1_message = 'message from user 1' + device_1_chat_view.chat_message_input.send_keys(device_1_message) + device_1_chat_view.send_message_button.click() + + # Device 2: Send message to device 1 + device_2_message = 'message from user 2' + device_2_chat_view = device_2_home_view.get_chat_view() + device_2_chat_view.chat_message_input.send_keys(device_2_message) + device_2_chat_view.send_message_button.click() + + # Device 1: See the message from device 2 + device_1_chat_view.wait_for_message_in_one_to_one_chat(device_2_message, self.errors) + + # Stop device 2, it's not needed anymore + device_2.quit() + + # Device 1: Delete chat and make sure it does not reappear after logging in again + 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 + device_1_sign_in_view.account_button.click() + device_1_sign_in_view.sign_in(self.senders['g_user']['password']) + assert not device_1_home_view.get_chat_with_user(self.senders['h_user']['username']).is_element_present(20) + + # Device 1: Start 1-1 chat with device 2 + device_1_chat_view = device_1_home_view.start_1_1_chat(self.senders['h_user']['username']) + assert device_1_chat_view.no_messages_in_chat.is_element_present() + + self.verify_no_errors() diff --git a/test/appium/tests/test_messaging.py b/test/appium/tests/test_messaging.py index f716ebc945..2a35f81095 100644 --- a/test/appium/tests/test_messaging.py +++ b/test/appium/tests/test_messaging.py @@ -22,15 +22,13 @@ message_with_new_line = 'message' '\n' 'with new line' class TestMessages(MultipleDeviceTestCase): @pytest.mark.pr - def test_one_to_one_chat_messages_and_delete_chat(self): + def test_one_to_one_chat_messages(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() device_2_public_key = device_2_home.get_public_key() - device_2_profile = device_2_home.get_profile_view() - device_2_username = device_2_profile.username_text.text device_1_home.add_contact(device_2_public_key) device_1_chat = device_1_home.get_chat_view() @@ -77,7 +75,6 @@ class TestMessages(MultipleDeviceTestCase): web_view.find_full_text('Status, the Ethereum discovery tool.') device_1_chat.back_button.click() - device_1_chat.delete_chat(device_2_username[:25], self.errors) self.verify_no_errors() @pytest.mark.pr diff --git a/test/appium/tests/test_sanity.py b/test/appium/tests/test_sanity.py index ff4f0f4c46..8618fbcf59 100644 --- a/test/appium/tests/test_sanity.py +++ b/test/appium/tests/test_sanity.py @@ -28,7 +28,7 @@ class TestSanity(SingleDeviceTestCase): sign_in_view = SignInView(self.driver) sign_in_view.create_user() profile_view = sign_in_view.profile_button.click() - profile_view.logout_button.click() + profile_view.logout() recover_access_view = sign_in_view.add_existing_account_button.click() recover_access_view.passphrase_input.send_keys(basic_user['passphrase']) recover_access_view.password_input.send_keys(basic_user['password']) diff --git a/test/appium/tests/test_transaction.py b/test/appium/tests/test_transaction.py index 9c74c194b3..6eea61a188 100644 --- a/test/appium/tests/test_transaction.py +++ b/test/appium/tests/test_transaction.py @@ -21,22 +21,13 @@ class TestTransaction(SingleDeviceTestCase): sender_address = home_view.public_key_to_address(sender_public_key) home_view.home_button.click() api_requests.get_donate(sender_address) - initial_balance_recipient = api_requests.get_balance(recipient['address']) home_view.add_contact(recipient['public_key']) chat_view = home_view.get_chat_with_user(recipient['username']).click() - chat_view.commands_button.click() - chat_view.send_command.click() - chat_view.send_as_keyevent(transaction_amount) + initial_balance_recipient = api_requests.get_balance(recipient['address']) + chat_view.send_transaction_in_1_1_chat(transaction_amount, 'qwerty1234') send_transaction_view = chat_view.get_send_transaction_view() - chat_view.send_message_button.click_until_presence_of_element(send_transaction_view.sign_transaction_button) - send_transaction_view.sign_transaction('qwerty1234') - send_transaction_view.find_full_text(transaction_amount) - try: - chat_view.find_full_text('Sent', 10) - except TimeoutException: - chat_view.find_full_text('Delivered', 10) - api_requests.verify_balance_is_updated(initial_balance_recipient, recipient['address']) send_transaction_view.back_button.click() + api_requests.verify_balance_is_updated(initial_balance_recipient, recipient['address']) wallet_view = home_view.wallet_button.click() transactions_view = wallet_view.transactions_button.click() transactions_view.transactions_table.find_transaction(amount=transaction_amount) @@ -73,21 +64,13 @@ class TestTransaction(SingleDeviceTestCase): sender_address = home_view.public_key_to_address(sender_public_key) home_view.home_button.click() api_requests.get_donate(sender_address) - initial_balance_recipient = api_requests.get_balance(recipient['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() - chat_view.commands_button.click() - chat_view.send_command.click() - chat_view.first_recipient_button.click() - chat_view.send_as_keyevent(transaction_amount) - send_transaction_view = chat_view.get_send_transaction_view() - chat_view.send_message_button.click_until_presence_of_element(send_transaction_view.sign_transaction_button) - send_transaction_view.sign_transaction('qwerty1234') - send_transaction_view.find_full_text(transaction_amount) - chat_view.find_full_text('to ' + recipient['username'], 10) - api_requests.verify_balance_is_updated(initial_balance_recipient, recipient['address']) + 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']) @pytest.mark.pr def test_send_transaction_from_daap(self): @@ -203,15 +186,11 @@ class TestTransaction(SingleDeviceTestCase): @pytest.mark.all class TestTransactions(MultipleDeviceTestCase): - senders = dict() - senders['c_user'] = transaction_users_wallet['C_USER'] - senders['d_user'] = transaction_users['D_USER'] - senders['f_user'] = transaction_users['F_USER'] @pytest.mark.pr def test_send_eth_to_request_in_group_chat(self): recipient = transaction_users['E_USER'] - sender = self.senders['f_user'] + sender = self.senders['f_user'] = transaction_users['F_USER'] self.create_drivers(2) device_1, device_2 = SignInView(self.drivers[0]), SignInView(self.drivers[1]) for user_details in (recipient, device_1), (sender, device_2): @@ -240,7 +219,7 @@ class TestTransactions(MultipleDeviceTestCase): @pytest.mark.pr def test_send_eth_to_request_in_one_to_one_chat(self): recipient = transaction_users['C_USER'] - sender = self.senders['d_user'] + sender = self.senders['d_user'] = transaction_users['D_USER'] self.create_drivers(2) device_1, device_2 = SignInView(self.drivers[0]), SignInView(self.drivers[1]) for user_details in (recipient, device_1), (sender, device_2): @@ -279,7 +258,7 @@ class TestTransactions(MultipleDeviceTestCase): @pytest.mark.pr def test_send_eth_to_request_from_wallet(self): recipient = transaction_users_wallet['D_USER'] - sender = self.senders['c_user'] + sender = self.senders['c_user'] = transaction_users['C_USER'] self.create_drivers(2) device_1, device_2 = SignInView(self.drivers[0]), SignInView(self.drivers[1]) for user_details in (recipient, device_1), (sender, device_2): @@ -311,7 +290,3 @@ class TestTransactions(MultipleDeviceTestCase): device_2_chat.send_eth_to_request(request_button, sender['password']) api_requests.verify_balance_is_updated(initial_balance_recipient, recipient['address']) - def teardown_method(self, method): - for user in self.senders: - api_requests.faucet(address=self.senders[user]['address']) - super(TestTransactions, self).teardown_method(method) diff --git a/test/appium/views/base_element.py b/test/appium/views/base_element.py index 216dc8dc4f..f3567186c6 100644 --- a/test/appium/views/base_element.py +++ b/test/appium/views/base_element.py @@ -25,6 +25,15 @@ class BaseElement(object): def accessibility_id(locator, value): return locator(MobileBy.ACCESSIBILITY_ID, value) + @classmethod + def text_selector(locator, text): + return BaseElement.Locator.xpath_selector('//*[@text="' + text + '"]') + + @classmethod + def text_part_selector(locator, text): + return BaseElement.Locator.xpath_selector('//*[contains(@text, "' + text + '")]') + + def __str__(self, *args, **kwargs): return "%s:%s" % (self.by, self.value) diff --git a/test/appium/views/base_view.py b/test/appium/views/base_view.py index 926a3167e5..780d80a28f 100644 --- a/test/appium/views/base_view.py +++ b/test/appium/views/base_view.py @@ -231,13 +231,13 @@ class BaseView(object): def element_by_text(self, text, element_type='button'): info("Looking for an element by text: '%s'" % text) element = self.element_types[element_type](self.driver) - element.locator = element.Locator.xpath_selector('//*[@text="' + text + '"]') + element.locator = element.Locator.text_selector(text) return element def element_by_text_part(self, text, element_type='base'): info("Looking for an element by text part: '%s'" % text) element = self.element_types[element_type](self.driver) - element.locator = element.Locator.xpath_selector('//*[contains(@text, "' + text + '")]') + element.locator = element.Locator.text_part_selector(text) return element def element_starts_with_text(self, text, element_type='base'): diff --git a/test/appium/views/chat_view.py b/test/appium/views/chat_view.py index 6d6535a789..ee66209430 100644 --- a/test/appium/views/chat_view.py +++ b/test/appium/views/chat_view.py @@ -1,7 +1,7 @@ import time from selenium.common.exceptions import TimeoutException from tests import info -from views.base_element import BaseButton, BaseEditBox, BaseText +from views.base_element import BaseButton, BaseEditBox, BaseText, BaseElement from views.base_view import BaseView @@ -140,6 +140,12 @@ class ViewProfileButton(BaseButton): self.locator = self.Locator.xpath_selector('//*[@text="View profile"]') +class NoMessagesInChatText(BaseText): + def __init__(self, driver): + super(NoMessagesInChatText, self).__init__(driver) + self.locator = self.Locator.text_part_selector('There are no messages') + + class ProfileSendMessageButton(BaseButton): def __init__(self, driver): super(ProfileSendMessageButton, self).__init__(driver) @@ -159,6 +165,7 @@ class ChatView(BaseView): self.chat_message_input = ChatMessageInput(self.driver) self.add_to_contacts = AddToContacts(self.driver) self.user_name_text = UserNameText(self.driver) + self.no_messages_in_chat = NoMessagesInChatText(self.driver) self.commands_button = CommandsButton(self.driver) self.send_command = SendCommand(self.driver) @@ -244,3 +251,40 @@ class ChatView(BaseView): if not HomeView(self.driver).plus_button.is_element_present() or \ self.element_by_text(chat_name).is_element_present(): errors.append('Chat was not deleted') + + def send_transaction_in_1_1_chat(self, amount, password): + self.commands_button.click() + self.send_command.click() + self.send_as_keyevent(amount) + self.send_message_button.click() + + send_transaction_view = self.get_send_transaction_view() + self.send_message_button.click_until_presence_of_element(send_transaction_view.sign_transaction_button) + send_transaction_view.sign_transaction(password) + send_transaction_view.find_full_text(amount) + try: + self.find_full_text('Sent', 10) + except TimeoutException: + try: + self.find_full_text('Delivered', 10) + except TimeoutException: + self.find_full_text('Seen', 3) + + def send_transaction_in_group_chat(self, amount, password, recipient): + self.commands_button.click() + self.send_command.click() + self.find_full_text(recipient['username']).click() + self.send_as_keyevent(amount) + self.send_message_button.click() + + send_transaction_view = self.get_send_transaction_view() + self.send_message_button.click_until_presence_of_element(send_transaction_view.sign_transaction_button) + send_transaction_view.sign_transaction(password) + send_transaction_view.find_full_text(amount) + self.find_full_text('to ' + recipient['username'], 10) + + def request_transaction_in_1_1_chat(self, amount): + self.commands_button.click() + self.request_command.click() + self.send_as_keyevent(amount) + self.send_message_button.click() diff --git a/test/appium/views/home_view.py b/test/appium/views/home_view.py index 65ec14f6ae..529bd816cc 100644 --- a/test/appium/views/home_view.py +++ b/test/appium/views/home_view.py @@ -90,6 +90,13 @@ class HomeView(BaseView): one_to_one_chat = self.get_chat_view() one_to_one_chat.chat_message_input.wait_for_element(60) + def start_1_1_chat(self, username): + start_new_chat = self.plus_button.click() + start_new_chat.start_new_chat_button.click() + self.element_by_text(username).click() + from views.chat_view import ChatView + return ChatView(self.driver) + def create_group_chat(self, user_names_to_add: list, group_chat_name: str = 'new_group_chat'): start_new_chat = self.plus_button.click() start_new_chat.new_group_chat_button.click() diff --git a/test/appium/views/profile_view.py b/test/appium/views/profile_view.py index 21136c842a..23990c9262 100644 --- a/test/appium/views/profile_view.py +++ b/test/appium/views/profile_view.py @@ -1,5 +1,4 @@ import time - from tests import info from tests.base_test_case import AbstractTestCase from views.base_element import BaseText, BaseButton, BaseEditBox, BaseElement @@ -77,6 +76,21 @@ class LogoutButton(BaseButton): self.locator = self.Locator.accessibility_id('log-out-button') +class LogoutDialog(BaseView): + def __init__(self, driver): + super(LogoutDialog, self).__init__(driver) + self.logout_button = LogoutDialog.LogoutButton(driver) + + class LogoutButton(BaseButton): + def __init__(self, driver): + super(LogoutDialog.LogoutButton, self).__init__(driver) + self.locator = self.Locator.text_selector('LOG OUT') + + def navigate(self): + from views.sign_in_view import SignInView + return SignInView(self.driver) + + class ConfirmLogoutButton(BaseButton): def __init__(self, driver): @@ -227,6 +241,7 @@ class ProfileView(BaseView): self.network_settings_button = NetworkSettingsButton(self.driver) self.connect_button = NetworkSettingsButton.ConnectButton(self.driver) self.logout_button = LogoutButton(self.driver) + self.logout_dialog = LogoutDialog(self.driver) self.confirm_logout_button = ConfirmLogoutButton(self.driver) # new design @@ -279,3 +294,8 @@ class ProfileView(BaseView): self.confirm_button.click() else: raise NotImplementedError('Test case is implemented to run on SauceLabs only') + + def logout(self): + self.logout_button.click() + return self.logout_dialog.logout_button.click() + diff --git a/test/appium/views/sign_in_view.py b/test/appium/views/sign_in_view.py index d7e6b264ac..804e01accd 100644 --- a/test/appium/views/sign_in_view.py +++ b/test/appium/views/sign_in_view.py @@ -120,5 +120,9 @@ class SignInView(BaseView): self.do_not_share.wait_for_element(10) self.do_not_share.click_until_presence_of_element(self.home_button) + def sign_in(self, password): + self.password_input.set_value(password) + self.sign_in_button.click() + def click_account_by_position(self, position: int): - self.account_button.find_elements()[position].click() + self.account_button.find_elements()[position].click() \ No newline at end of file