From 625510d6c96e0216e787aa225d07209673c8f355 Mon Sep 17 00:00:00 2001 From: Yevheniia Berdnyk Date: Thu, 10 Aug 2023 14:36:46 +0300 Subject: [PATCH] e2e: Added test for message with hashtag in communtiy channel --- .../critical/test_public_chat_browsing.py | 75 ++++++++++++++++++- .../tests/medium/test_activity_center.py | 4 +- test/appium/views/base_element.py | 10 +-- test/appium/views/chat_view.py | 21 ++++-- 4 files changed, 94 insertions(+), 16 deletions(-) diff --git a/test/appium/tests/critical/test_public_chat_browsing.py b/test/appium/tests/critical/test_public_chat_browsing.py index aec4afb5e2..fc992f2be8 100644 --- a/test/appium/tests/critical/test_public_chat_browsing.py +++ b/test/appium/tests/critical/test_public_chat_browsing.py @@ -332,7 +332,7 @@ class TestCommunityOneDeviceMerged(MultipleSharedDeviceTestCase): element_templates = { self.community_view.join_button: 'discovery_join_button.png', self.community_view.get_channel_avatar(): 'discovery_general_channel.png', - } + } for element, template in element_templates.items(): if element.is_element_differs_from_template(template): element.save_new_screenshot_of_element('%s_different.png' % element.name) @@ -570,7 +570,7 @@ class TestCommunityMultipleDeviceMerged(MultipleSharedDeviceTestCase): # self.chat_2 = self.home_2.get_chat(self.username_1).click() self.home_2.just_fyi("Send message to contact (need for blocking contact) test") self.chat_2.send_message(self.text_message) - self.chat_2.element_by_text_part('View').click() + self.chat_2.chat_element_by_text(self.community_name).view_community_button.click() self.community_2.join_community() self.channel_2 = self.community_2.get_channel(self.channel_name).click() @@ -1143,3 +1143,74 @@ class TestCommunityMultipleDeviceMerged(MultipleSharedDeviceTestCase): if not community.is_element_disappeared(): self.errors.append('Community is still shown in the list after leave') self.errors.verify_no_errors() + + @marks.xfail(reason="Can't invite user to closed community https://github.com/status-im/status-mobile/issues/16968", + run=False) + @marks.testrail_id(702948) + def test_community_hashtag_links_to_community_channels(self): + for home in self.homes: + home.click_system_back_button_until_element_is_shown() + self.home_2.jump_to_messages_home() + self.home_1.jump_to_communities_home() + + self.home_1.just_fyi("Device 1 creates a closed community") + self.home_1.create_community(community_type="closed") + community_name = "closed community" + self.community_1.send_invite_to_community(community_name, self.username_2) + + self.home_2.just_fyi("Device 2 joins the community") + self.home_2.get_chat(self.username_1).click() + control_message_1_1_chat = "it is just a message text" + self.chat_2.send_message(control_message_1_1_chat) + self.chat_2.chat_element_by_text(community_name).view_community_button.click() + self.community_2.join_community() + + dogs_channel, cats_channel = "dogs", "cats" + cats_message = "Where is a cat?" + + self.home_1.just_fyi("Device 1 sends a message in the cats channel") + self.home_1.get_to_community_channel_from_home(community_name=community_name, channel_name=cats_channel) + self.channel_1.send_message(cats_message) + self.channel_1.click_system_back_button_until_element_is_shown( + element=self.community_1.get_channel(dogs_channel)) + + self.home_1.just_fyi("Device 1 sends a message with hashtag in the dogs channel") + self.community_1.get_channel(dogs_channel).click_until_presence_of_element(self.channel_1.chat_message_input) + message_with_hashtag = "#cats" + self.channel_1.send_message(message_with_hashtag) + + self.home_2.just_fyi("Device 2 clicks on the message with hashtag in the community channel") + self.community_2.get_channel(dogs_channel).click_until_presence_of_element(self.channel_2.chat_message_input) + self.channel_2.chat_element_by_text(message_with_hashtag).message_body.wait_for_visibility_of_element(30) + self.channel_2.chat_element_by_text(message_with_hashtag).message_body.click_inside_element_by_coordinate( + rel_x=0.2, rel_y=0.5) + if not self.channel_2.chat_element_by_text(cats_message).is_element_displayed(30): + self.errors.append("Receiver was not navigated to the cats channel") + + self.home_1.just_fyi("Device 1 clicks on the message with hashtag in the community channel") + self.channel_1.chat_element_by_text(message_with_hashtag).message_body.click_inside_element_by_coordinate( + rel_x=0.2, rel_y=0.5) + if not self.channel_1.chat_element_by_text(cats_message).is_element_displayed(30): + self.errors.append("Sender was not navigated to the cats channel") + + [home.jump_to_messages_home() for home in self.homes] + + self.home_2.just_fyi("Device 2 sends a message with hashtag in 1-1 chat") + self.home_2.get_chat(self.username_1).click() + self.chat_2.send_message(message_with_hashtag) + + self.home_1.just_fyi("Device 1 clicks on the message with hashtag in 1-1 chat") + self.home_1.get_chat(self.username_2).click() + self.chat_1.chat_element_by_text(message_with_hashtag).message_body.wait_for_visibility_of_element(30) + self.chat_1.chat_element_by_text(message_with_hashtag).message_body.click_inside_element_by_coordinate( + rel_x=0.2, rel_y=0.5) + if self.chat_1.chat_element_by_text(control_message_1_1_chat).is_element_disappeared(): + self.errors.append("Receiver was navigated out of 1-1 chat") + + self.home_2.just_fyi("Device 2 clicks on the message with hashtag in 1-1 chat") + self.chat_2.chat_element_by_text(message_with_hashtag).message_body.click_inside_element_by_coordinate( + rel_x=0.2, rel_y=0.5) + if self.chat_2.chat_element_by_text(control_message_1_1_chat).is_element_disappeared(): + self.errors.append("Sender was navigated out of 1-1 chat") + + self.errors.verify_no_errors() diff --git a/test/appium/tests/medium/test_activity_center.py b/test/appium/tests/medium/test_activity_center.py index 5ee10a01e9..a02df9e4d6 100644 --- a/test/appium/tests/medium/test_activity_center.py +++ b/test/appium/tests/medium/test_activity_center.py @@ -172,7 +172,7 @@ class TestActivityMultipleDevicePR(MultipleSharedDeviceTestCase): self.home_1.get_to_community_channel_from_home(self.community_name) self.chat_2 = self.home_2.get_chat(self.username_1).click() - self.chat_2.element_by_text_part('View').click() + self.chat_2.chat_element_by_text(self.community_name).view_community_button.click() self.community_2.join_community() self.channel_2 = self.community_2.get_channel(self.channel_name).click() @@ -327,7 +327,7 @@ class TestActivityMultipleDevicePR(MultipleSharedDeviceTestCase): self.home_2.just_fyi("Request access to community") self.home_2.jump_to_messages_home() self.chat_2 = self.home_2.get_chat(self.username_1).click() - self.chat_2.element_by_text_part('View').wait_and_click(sec=60) + self.chat_2.chat_element_by_text(community_name).view_community_button.wait_and_click(sec=60) self.community_2.join_community() [home.jump_to_communities_home() for home in (self.home_1, self.home_2)] diff --git a/test/appium/views/base_element.py b/test/appium/views/base_element.py index d48ad8a2c4..930ee709e5 100644 --- a/test/appium/views/base_element.py +++ b/test/appium/views/base_element.py @@ -92,6 +92,11 @@ class BaseElement(object): self.driver.info('Tap on found: %s' % self.name) return self.navigate() + def wait_and_click(self, sec=30): + self.driver.info("Wait for element `%s` for max %ss and click when it is available" % (self.name, sec)) + self.wait_for_visibility_of_element(sec) + self.click() + def click_until_presence_of_element(self, desired_element, attempts=4): counter = 0 self.driver.info("Click until `%s` by `%s`: `%s` will be presented" % ( @@ -398,11 +403,6 @@ class Button(BaseElement): def __init__(self, driver, **kwargs): super(Button, self).__init__(driver, **kwargs) - def wait_and_click(self, sec=30): - self.driver.info("Wait for element `%s` for max %ss and click when it is available" % (self.name, sec)) - self.wait_for_visibility_of_element(sec) - self.click() - def click_until_absense_of_element(self, desired_element, attempts=3, timeout=1): counter = 0 self.driver.info("Click until `%s` by `%s`: `%s` is NOT presented" % ( diff --git a/test/appium/views/chat_view.py b/test/appium/views/chat_view.py index b4bd3dc254..98292f0983 100644 --- a/test/appium/views/chat_view.py +++ b/test/appium/views/chat_view.py @@ -118,12 +118,12 @@ class ProfileBlockContactButton(Button): class ChatElementByText(Text): def __init__(self, driver, text): self.message_text = text + self.chat_item_locator = "android.view.ViewGroup[@content-desc='chat-item']" if text in ["image", "sticker", "audio"]: self.message_locator = "//android.view.ViewGroup[@content-desc='%s-message']" % text else: self.message_locator = "//*[starts-with(@text,'%s')]" % text - super().__init__(driver, prefix=self.message_locator, - xpath="/ancestor::android.view.ViewGroup[@content-desc='chat-item']") + super().__init__(driver, prefix=self.message_locator, xpath="/ancestor::%s" % self.chat_item_locator) def find_element(self): for _ in range(2): @@ -176,10 +176,12 @@ class ChatElementByText(Text): return Username(self.driver, self.locator) - def contains_text(self, text, wait_time=5) -> bool: - element = Text(self.driver, prefix=self.locator, - xpath="//android.view.ViewGroup//android.widget.TextView[contains(@text,'%s')]" % text) - return element.is_element_displayed(wait_time) + @property + def message_body(self): + return Text( + self.driver, + xpath="//%s//android.widget.TextView[contains(@text,'%s')]" % (self.chat_item_locator, self.message_text) + ) def wait_for_sent_state(self, wait_time=30): return BaseElement(self.driver, prefix=self.locator, @@ -309,6 +311,10 @@ class ChatElementByText(Text): return PinnedByLabelText(self.driver, self.locator) + @property + def view_community_button(self): + return BaseElement(self.driver, xpath=self.locator + "//*[@text='View']") + class UsernameOptions(Button): def __init__(self, driver, username): @@ -393,7 +399,8 @@ class CommunityView(HomeView): self.join_button = Button(self.driver, accessibility_id="show-request-to-join-screen-button") self.join_community_button = Button(self.driver, accessibility_id="join-community-button") self.follow_button = Button(self.driver, translation_id="follow") - self.community_tags = BaseElement(self.driver, xpath="//*[@content-desc='chat-name-text']/../android.widget.HorizontalScrollView") + self.community_tags = BaseElement( + self.driver, xpath="//*[@content-desc='chat-name-text']/../android.widget.HorizontalScrollView") #### NEW UI # Communities initial page