diff --git a/test/appium/tests/atomic/chats/test_group_chat.py b/test/appium/tests/atomic/chats/test_group_chat.py index 76b1aa40f7..5b836221da 100644 --- a/test/appium/tests/atomic/chats/test_group_chat.py +++ b/test/appium/tests/atomic/chats/test_group_chat.py @@ -3,14 +3,17 @@ from tests.base_test_case import MultipleDeviceTestCase from tests.users import chat_users from views.sign_in_view import SignInView -def return_left_chat_system_message(default_username): - return "*%s* left the group" % default_username +def return_left_chat_system_message(username): + return "*%s* left the group" % username def return_created_chat_system_message(username, chat_name): return "*%s* created the group *%s*" % (username, chat_name) -def return_joined_chat_system_message(default_username): - return "*%s* has joined the group" % default_username +def return_joined_chat_system_message(username): + return "*%s* has joined the group" % username + +def return_made_admin_system_message(username): + return "*%s* has been made admin" % username 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) @@ -18,16 +21,19 @@ def create_users(driver_1, driver_2, username_1=None, username_2=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 get_default_username(device_home): +def get_username(device_home, default=True): device_profile_view = device_home.profile_button.click() - device_default_username = device_profile_view.default_username_text.text + if default: + username = device_profile_view.default_username_text.text + else: + username = device_profile_view.username_set_by_user_text.text device_home.home_button.click() - return device_default_username + return username def create_new_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_default_username = get_default_username(device_2_home) + device_2_default_username = get_username(device_2_home) # device 1: add device 2 as contact device_1_chat = device_1_home.add_contact(device_2_public_key) @@ -96,7 +102,7 @@ class TestGroupChatMultipleDevice(MultipleDeviceTestCase): 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_default_username = get_default_username(device_2_home) + device_2_default_username = get_username(device_2_home) device_1_chat, device_2_chat = create_and_join_group_chat(device_1_home, device_2_home, chat_name) # device 2: delete group chat @@ -156,7 +162,7 @@ class TestGroupChatMultipleDevice(MultipleDeviceTestCase): # device 2: get public key and default username device_2_public_key = device_2_home.get_public_key() - device_2_default_username = get_default_username(device_2_home) + device_2_default_username = get_username(device_2_home) # device 1: add contacts device_1_home.add_contact(chat_member['public_key']) @@ -196,7 +202,7 @@ class TestGroupChatMultipleDevice(MultipleDeviceTestCase): self.errors.append("Group chat '%s' is shown, but the chat has been deleted" % chat_name) # device 1: check system message about leaving a group chat - device_2_default_username = get_default_username(device_2_home) + device_2_default_username = get_username(device_2_home) user2_left_chat_system_message = return_left_chat_system_message(device_2_default_username) if not device_1_chat.chat_element_by_text(user2_left_chat_system_message).is_element_displayed(): self.errors.append("Message with text '%s' was not received" % user2_left_chat_system_message) @@ -207,4 +213,71 @@ class TestGroupChatMultipleDevice(MultipleDeviceTestCase): # device 2: check that chat doesn't reappear if device_2_home.element_by_text(chat_name).is_element_displayed(): self.errors.append("Group chat '%s' is shown, but the chat has been deleted" % chat_name) - self.verify_no_errors() \ No newline at end of file + self.verify_no_errors() + + @marks.testrail_id(4001) + @marks.high + def test_remove_member_from_group_chat(self): + self.create_drivers(2) + message_for_device_2 = 'This message should not be visible for device 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_2_default_username = get_username(device_2_home) + device_2_custom_username = get_username(device_2_home, False) + + # device 1: get options for device 2 in group chat and remove him + options = device_1_chat.get_user_options(device_2_default_username) + options.remove_user_button.click() + + # device 2: check that removed user can see that he is removed + user2_left_chat_system_message_for_user_2 = return_left_chat_system_message(device_2_custom_username) + + if not device_2_chat.chat_element_by_text(user2_left_chat_system_message_for_user_2).is_element_displayed(): + self.errors.append("Message with test '%s' was not received" % user2_left_chat_system_message_for_user_2) + + # device 2: check there is no message input so user can't send new message in group chat + if device_2_chat.chat_message_input.is_element_displayed(): + self.errors.append("Message input is still available for removed user") + + # device 1: send some message to group chat + device_1_chat.send_message(message_for_device_2) + + # device 2: check that message is not received + if device_2_chat.chat_element_by_text(message_for_device_2).is_element_displayed(): + self.errors.append("Message with text '%s' was received" % message_for_device_2) + + self.verify_no_errors() + + @marks.testrail_id(5694) + @marks.high + def test_make_admin_member_of_group_chat(self): + self.create_drivers(2) + chat_member = chat_users['A'] + + device_1_home, device_2_home = create_users(self.drivers[0], self.drivers[1]) + chat_name = device_1_home.get_public_chat_name() + device_2_default_username = get_username(device_2_home) + device_2_custom_username = get_username(device_2_home, False) + + # device 2: add contacts + device_2_home.add_contact(chat_member['public_key']) + device_2_home.get_back_to_home_view() + + # create and join group chat + device_1_chat, device_2_chat = create_and_join_group_chat(device_1_home, device_2_home, chat_name) + + # device 1: get options for device 2 in group chat and make him admin + options = device_1_chat.get_user_options(device_2_default_username) + options.make_admin_button.click() + + # device 2: check presence of system message + user2_made_admin_system_message_for_user_2 = return_made_admin_system_message(device_2_custom_username) + if not device_2_chat.chat_element_by_text(user2_made_admin_system_message_for_user_2).is_element_displayed(): + self.errors.append("Message with test '%s' was not received" % user2_made_admin_system_message_for_user_2) + + # device 2: check that as admin can add new members to group chat + device_2_chat.add_members_to_group_chat([chat_member['username']]) + + self.verify_no_errors() \ No newline at end of file diff --git a/test/appium/views/chat_view.py b/test/appium/views/chat_view.py index 4fdb69ec6f..558ebb0292 100644 --- a/test/appium/views/chat_view.py +++ b/test/appium/views/chat_view.py @@ -210,6 +210,15 @@ class DeclineChatButton(BaseButton): super(DeclineChatButton, self).__init__(driver) self.locator = self.Locator.text_part_selector('Decline invitation') +class RemoveFromChatButton(BaseButton): + def __init__(self, driver): + super(RemoveFromChatButton, self).__init__(driver) + self.locator = self.Locator.xpath_selector('//*[@text="Remove from chat"]') + +class MakeAdminButton(BaseButton): + def __init__(self, driver): + super(MakeAdminButton, self).__init__(driver) + self.locator = self.Locator.xpath_selector('//*[@text="Make admin"]') class ChatElementByText(BaseText): def __init__(self, driver, text): @@ -292,13 +301,19 @@ class HistoryTimeMarker(BaseText): super().__init__(driver) self.locator = self.Locator.xpath_selector('//*[@text="%s"]' % marker) +class UsernameOptions(BaseButton): + def __init__(self, driver, username): + super(UsernameOptions, self).__init__(driver) + self.locator = self.Locator.xpath_selector("//*[@text='%s']/..//*[@content-desc='options']" % username) class GroupChatInfoView(BaseView): def __init__(self, driver): super(GroupChatInfoView, self).__init__(driver) - self.add_members = AddGroupChatMembersButton(self.driver) + def get_username_options(self, username: str): + return UsernameOptions(self.driver, username) + class ChatView(BaseView): def __init__(self, driver): @@ -325,6 +340,8 @@ class ChatView(BaseView): self.leave_button = LeaveButton(self.driver) self.join_chat_button = JoinChatButton(self.driver) self.decline_invitation_button = DeclineChatButton(self.driver) + self.remove_user_button = RemoveFromChatButton(self.driver) + self.make_admin_button = MakeAdminButton(self.driver) self.chat_settings = ChatSettings(self.driver) self.view_profile_button = ViewProfileButton(self.driver) @@ -442,6 +459,12 @@ class ChatView(BaseView): user_contact.click() add_members_view.add_button.click() + def get_user_options(self, username: str): + self.chat_options.click() + group_info_view = self.group_info.click() + group_info_view.get_username_options(username).click() + return self + def request_transaction_in_1_1_chat(self, asset, amount): self.commands_button.click() self.request_command.click()