diff --git a/test/appium/tests/atomic/chats/test_group_chat.py b/test/appium/tests/atomic/chats/test_group_chat.py new file mode 100644 index 0000000000..b001b1ed2a --- /dev/null +++ b/test/appium/tests/atomic/chats/test_group_chat.py @@ -0,0 +1,170 @@ +from tests import marks, get_current_time +from tests.base_test_case import MultipleDeviceTestCase +from tests.users import chat_users +from views.sign_in_view import SignInView + + +def create_users(driver_1, driver_2, username_1=None, username_2=None): + device_1_sign_in, device_2_sign_in = SignInView(driver_1), SignInView(driver_2) + if username_1 is not None and username_2 is not None: + return device_1_sign_in.create_user(username_1), device_2_sign_in.create_user(username_1) + return device_1_sign_in.create_user(), device_2_sign_in.create_user() + + +def create_and_join_group_chat(device_1_home, device_2_home, chat_name): + # device 2: get public key and default username + device_2_public_key = device_2_home.get_public_key() + device_2_profile_view = device_2_home.profile_button.click() + device_2_default_username = device_2_profile_view.default_username_text.text + device_2_home.home_button.click() + + # device 1: add device 2 as contact + device_1_chat = device_1_home.add_contact(device_2_public_key) + device_1_chat.get_back_to_home_view() + + # device 1: create group chat with some user + device_1_chat = device_1_home.create_group_chat([device_2_default_username], chat_name) + + # device 2: open group chat + device_2_chat = device_2_home.get_chat_with_user(chat_name).click() + + return device_1_chat, device_2_chat + + +@marks.chat +class TestGroupChatMultipleDevice(MultipleDeviceTestCase): + + @marks.testrail_id(3994) + @marks.high + def test_create_new_group_chat(self): + self.create_drivers(2) + + device_1_home, device_2_home = create_users(self.drivers[0], self.drivers[1]) + chat_name = device_1_home.get_public_chat_name() + device_1_chat, device_2_chat = create_and_join_group_chat(device_1_home, device_2_home, chat_name) + + for chat in (device_1_chat, device_2_chat): + if chat.user_name_text.text != chat_name: + self.errors.append('Oops! Chat screen does not match the entered chat name %s' % chat_name) + + self.verify_no_errors() + + @marks.testrail_id(3993) + @marks.high + def test_send_message_in_group_chat(self): + message_from_device_1 = 'Hello from device 1' + message_from_device_2 = 'Hi there! Sent from device 2' + + self.create_drivers(2) + + device_1_home, device_2_home = create_users(self.drivers[0], self.drivers[1]) + chat_name = device_1_home.get_public_chat_name() + device_1_chat, device_2_chat = create_and_join_group_chat(device_1_home, device_2_home, chat_name) + + device_1_chat.send_message(message_from_device_1) + device_2_chat.send_message(message_from_device_2) + + if not device_2_chat.chat_element_by_text(message_from_device_1).is_element_displayed(): + self.errors.append("Message with test '%s' was not received" % message_from_device_1) + if not device_1_chat.chat_element_by_text(message_from_device_2).is_element_displayed(): + self.errors.append("Message with test '%s' was not received" % message_from_device_2) + self.verify_no_errors() + + @marks.testrail_id(5674) + @marks.high + def test_group_chat_system_messages(self): + username_1 = 'user1_%s' % get_current_time() + username_2 = 'user2_%s' % get_current_time() + + self.create_drivers(2) + + device_1_home, device_2_home = create_users(self.drivers[0], self.drivers[1], username_1, username_2) + chat_name = device_1_home.get_public_chat_name() + device_2_profile = device_2_home.profile_button.click() + device_2_default_username = device_2_profile.default_username_text.text + + device_1_chat, device_2_chat = create_and_join_group_chat(device_1_home, device_2_home, chat_name) + + admin_created_chat_system_message = "*%s* created the group *%s*" % (username_1, chat_name) + user2_joined_chat_system_message = "*%s* joined the group" % device_2_default_username + user2_left_chat_system_message = "*%s* left the group" % device_2_default_username + + # device 2: delete group chat + device_2_chat = device_2_home.get_chat_with_user(chat_name).click() + device_2_chat.delete_chat() + + # device 1: check system messages in the group chat + if not device_1_chat.element_by_text(admin_created_chat_system_message).is_element_displayed(): + self.errors.append("System message: '%s' in group chat is not shown" % admin_created_chat_system_message) + if not device_1_chat.element_by_text(user2_joined_chat_system_message).is_element_displayed(): + self.errors.append( + "System message: '%s' in group chat is not shown" % user2_joined_chat_system_message) + if not device_1_chat.element_by_text(user2_left_chat_system_message).is_element_displayed(): + self.errors.append( + "System message: '%s' in group chat is not shown" % user2_left_chat_system_message) + self.verify_no_errors() + + @marks.testrail_id(3997) + @marks.high + def test_delete_group_chat_via_delete_button(self): + message_from_device_1 = 'Hello from device 1' + message_from_device_2 = 'Hi there! Sent from device 2' + + self.create_drivers(2) + + device_1_home, device_2_home = create_users(self.drivers[0], self.drivers[1]) + chat_name = device_1_home.get_public_chat_name() + device_1_chat, device_2_chat = create_and_join_group_chat(device_1_home, device_2_home, chat_name) + + # send some messages and delete chat + device_1_chat.send_message(message_from_device_1) + device_2_chat.send_message(message_from_device_2) + device_1_chat.delete_chat() + device_2_chat.send_message(message_from_device_2) + + # device_1: check if chat is was deleted + if device_1_home.element_by_text(chat_name).is_element_displayed(): + self.errors.append("Public chat '%s' is shown, but the chat has been deleted" % chat_name) + self.verify_no_errors() + + @marks.testrail_id(3998) + @marks.high + def test_add_new_group_chat_member(self): + username_1 = 'user1_%s' % get_current_time() + username_2 = 'user2_%s' % get_current_time() + message_for_device_2 = 'This message should be visible for device 2' + chat_member = chat_users['A'] + + self.create_drivers(2) + + # create accounts on each device + device_1_home, device_2_home = create_users(self.drivers[0], self.drivers[1], username_1, username_2) + chat_name = device_1_home.get_public_chat_name() + + # device 2: get public key and default username + device_2_public_key = device_2_home.get_public_key() + device_2_profile_view = device_2_home.profile_button.click() + device_2_default_username = device_2_profile_view.default_username_text.text + device_2_home.home_button.click() + + # device 1: add contacts + device_1_home.add_contact(chat_member['public_key']) + device_1_home.get_back_to_home_view() + device_1_chat = device_1_home.add_contact(device_2_public_key) + device_1_chat.get_back_to_home_view() + + # device 1: create group chat with some user + device_1_chat = device_1_home.create_group_chat([chat_member['username']], chat_name) + + # device 1: add device 2 as a new member of the group chat + device_1_chat.add_members_to_group_chat([device_2_default_username]) + + # device 1: send a message that should be visible for device 2 + device_1_chat.send_message(message_for_device_2) + + # device 2: open the chat and check messages + device_2_chat = device_2_home.get_chat_with_user(chat_name).click() + if not device_2_chat.chat_element_by_text(message_for_device_2).is_element_displayed(): + self.errors.append('Message that was sent after device 2 has joined is not visible') + + self.verify_no_errors() diff --git a/test/appium/tests/users.py b/test/appium/tests/users.py index eaf190ee64..0d96f7ddf1 100644 --- a/test/appium/tests/users.py +++ b/test/appium/tests/users.py @@ -41,6 +41,23 @@ wallet_users['E']['address'] = "0x3e2e4077753d3c229a9ae332b9ca46958945e2f6" wallet_users['E']['public_key'] = "0x04a30d58c2c65c654a521455dabc139a9c26be7ca565f152a8182376150c1e12fe362c017a21b0e" \ "58676b84a945e34030c7150ae8d03758e94bf017f930d6189b2" +# Users used in chats. E.g. as members of a group chat +chat_users = dict() + +chat_users['A'] = dict() +chat_users['A']['passphrase'] = "canoe edit leg exit game glue blame electric bar now box point" +chat_users['A']['username'] = "Woozy Dopey Zander" +chat_users['A']['address'] = "0x5626db866676d70f5fa58366d8df3b1053b8d9cc" +chat_users['A']['public_key'] = "0x0455614888aa78b24bb0ddee94edb5f15a6a61c9053c4a9b671415" \ + "ce8047222f24fe48a4ecaa4d34e900cf8f01227910b925f6f8de0c435c83c6374c13d979c2e3" + +chat_users['B'] = dict() +chat_users['B']['passphrase'] = "found ridge build seven whisper enact weekend nation during law external december" +chat_users['B']['username'] = "Hospitable Dizzy Ichneumonfly" +chat_users['B']['address'] = "0x0b6f148eb4b87e1fd112374078fef2624727f030" +chat_users['B']['public_key'] = "0x043bd46619c7c09e300a0c4ae002a6aba82b3408db6026cdd21a45e85955c76aa6aa044daaa2606d" \ + "440a46463092372b48b0c7ab420e70fb7da4f0253ccd4554b6" + transaction_senders = dict() transaction_senders['A'] = dict() @@ -276,4 +293,5 @@ transaction_recipients['I']['passphrase'] = "engine equal wisdom saddle icon spr transaction_recipients['I']['username'] = "Sharp Sour Greathornedowl" transaction_recipients['I']['address'] = "0x4e6c60f344b13d730682f0a6d8ae1255c75e730e" transaction_recipients['I']['public_key'] = "0x049d6fe0c874d11ddd92f72ac75659703a7b58211b934fc22f0c7eae835b71651c8" \ - "3ae5e4fd688f1c898d39a657ea08a39d05d20a830bbf7eaffb6ccda9bef348f" \ No newline at end of file + "3ae5e4fd688f1c898d39a657ea08a39d05d20a830bbf7eaffb6ccda9bef348f" + diff --git a/test/appium/views/base_view.py b/test/appium/views/base_view.py index aaf7d7bf57..f176726208 100644 --- a/test/appium/views/base_view.py +++ b/test/appium/views/base_view.py @@ -152,6 +152,13 @@ class NextButton(BaseButton): "//android.widget.TextView[@text='NEXT']") +class AddButton(BaseButton): + def __init__(self, driver): + super(AddButton, self).__init__(driver) + self.locator = self.Locator.xpath_selector( + "//android.widget.TextView[@text='ADD']") + + class DoneButton(BaseButton): def __init__(self, driver): super(DoneButton, self).__init__(driver) @@ -263,6 +270,7 @@ class BaseView(object): self.continue_button = ContinueButton(self.driver) self.ok_button = OkButton(self.driver) self.next_button = NextButton(self.driver) + self.add_button = AddButton(self.driver) self.save_button = SaveButton(self.driver) self.done_button = DoneButton(self.driver) self.delete_button = DeleteButton(self.driver) diff --git a/test/appium/views/chat_view.py b/test/appium/views/chat_view.py index 0552866c6f..f1dddc52e2 100644 --- a/test/appium/views/chat_view.py +++ b/test/appium/views/chat_view.py @@ -6,6 +6,7 @@ from tests import common_password from views.base_element import BaseButton, BaseEditBox, BaseText, BaseElement from views.base_view import BaseView, ProgressBar from views.profile_view import ProfilePictureElement, ProfileAddressText +from views.start_new_chat_view import StartNewChatView class ChatMessageInput(BaseEditBox): @@ -20,6 +21,15 @@ class AddToContacts(BaseButton): self.locator = self.Locator.accessibility_id('add-to-contacts-button') +class AddGroupChatMembersButton(BaseButton): + def __init__(self, driver): + super(AddGroupChatMembersButton, self).__init__(driver) + self.locator = self.Locator.xpath_selector("//*[@text='Add members']") + + def navigate(self): + return StartNewChatView(self.driver) + + class UserNameText(BaseText): def __init__(self, driver): super(UserNameText, self).__init__(driver) @@ -88,6 +98,16 @@ class ClearHistoryButton(BaseButton): self.locator = self.Locator.xpath_selector('//*[@text="Clear history"]') +class GroupInfoButton(BaseButton): + + def __init__(self, driver): + super(GroupInfoButton, self).__init__(driver) + self.locator = self.Locator.xpath_selector('//*[@text="Group info"]') + + def navigate(self): + return GroupChatInfoView(self.driver) + + class LeaveChatButton(BaseButton): def __init__(self, driver): @@ -262,6 +282,13 @@ class HistoryTimeMarker(BaseText): self.locator = self.Locator.xpath_selector('//*[@text="%s"]' % marker) +class GroupChatInfoView(BaseView): + def __init__(self, driver): + super(GroupChatInfoView, self).__init__(driver) + + self.add_members = AddGroupChatMembersButton(self.driver) + + class ChatView(BaseView): def __init__(self, driver): super(ChatView, self).__init__(driver) @@ -281,6 +308,7 @@ class ChatView(BaseView): self.members_button = MembersButton(self.driver) self.delete_chat_button = DeleteChatButton(self.driver) self.clear_history_button = ClearHistoryButton(self.driver) + self.group_info = GroupInfoButton(self.driver) self.clear_button = ClearButton(self.driver) self.leave_chat_button = LeaveChatButton(self.driver) self.leave_button = LeaveButton(self.driver) @@ -391,6 +419,16 @@ class ChatView(BaseView): send_transaction_view.find_full_text(amount) self.find_full_text('to ' + recipient['username'], 10) + def add_members_to_group_chat(self, user_names_to_add: list): + self.chat_options.click() + group_info_view = self.group_info.click() + add_members_view = group_info_view.add_members.click() + for user_name in user_names_to_add: + user_contact = add_members_view.get_username_checkbox(user_name) + user_contact.scroll_to_element() + user_contact.click() + add_members_view.add_button.click() + def request_transaction_in_1_1_chat(self, asset, amount): self.commands_button.click() self.request_command.click() diff --git a/test/appium/views/profile_view.py b/test/appium/views/profile_view.py index 9c4402fca2..ac22596fc6 100644 --- a/test/appium/views/profile_view.py +++ b/test/appium/views/profile_view.py @@ -480,6 +480,10 @@ class ProfileView(BaseView): signin_view = SignInView(self.driver) signin_view.sign_in() + def switch_development_mode(self): + self.advanced_button.click() + self.debug_mode_toggle.click() + def add_custom_network(self): self.advanced_button.click() self.debug_mode_toggle.click() diff --git a/test/appium/views/start_new_chat_view.py b/test/appium/views/start_new_chat_view.py index fa07526db8..491a003473 100644 --- a/test/appium/views/start_new_chat_view.py +++ b/test/appium/views/start_new_chat_view.py @@ -49,6 +49,10 @@ class CreateButton(BaseButton): super(CreateButton, self).__init__(driver) self.locator = self.Locator.accessibility_id('create-button') + def navigate(self): + from views.chat_view import ChatView + return ChatView(self.driver) + class EnterUrlEditbox(BaseEditBox): def __init__(self, driver):