From 1af622a8dbbea4ac3c2e7d72ec87e2dc8dba89d5 Mon Sep 17 00:00:00 2001 From: Anastasiya Semenkevich Date: Thu, 26 Sep 2024 12:07:38 +0300 Subject: [PATCH] chore: fix community channels and categories locators --- test/e2e/gui/objects_map/communities_names.py | 9 ++++- test/e2e/gui/screens/community.py | 40 ++++++++++--------- test/e2e/gui/screens/messages.py | 2 +- test/e2e/scripts/utils/parsers.py | 13 ++++++ .../test_communities_categories.py | 4 -- .../communities/test_communities_channels.py | 8 ++-- 6 files changed, 48 insertions(+), 28 deletions(-) create mode 100644 test/e2e/scripts/utils/parsers.py diff --git a/test/e2e/gui/objects_map/communities_names.py b/test/e2e/gui/objects_map/communities_names.py index 34b9c7db00..49865fcc7f 100644 --- a/test/e2e/gui/objects_map/communities_names.py +++ b/test/e2e/gui/objects_map/communities_names.py @@ -19,8 +19,13 @@ mainWindow_startChatButton_StatusIconTabButton = {"checkable": True, "container" mainWindow_createChatOrCommunity_Loader = {"container": mainWindow_communityColumnView_CommunityColumnView, "id": "createChatOrCommunity", "type": "Loader", "unnamed": 1, "visible": True} mainWindow_scrollView_StatusScrollView = {"container": mainWindow_communityColumnView_CommunityColumnView, "id": "scrollView", "type": "StatusScrollView", "unnamed": 1, "visible": True} scrollView_Flickable = {"container": mainWindow_scrollView_StatusScrollView, "type": "Flickable", "unnamed": 1, "visible": True} -scrollView_chatListItems_StatusListView = {"container": scrollView_Flickable, "objectName": "chatListItems", "type": "StatusListView", "visible": True} -channel_listItem = {"container": scrollView_chatListItems_StatusListView, "id": "chatListDelegate", "type": "DropArea", "isCategory": False, "visible": True} + +# Channels and categories +communityChatListAndCategories = {"container": scrollView_Flickable, "id": "communityChatListAndCategories", "type": "StatusChatListAndCategories", "unnamed": 1, "visible": True} +channelAndCategoriesListItems = {"container": communityChatListAndCategories, "objectName": "statusChatListAndCategoriesChatList", "type": "StatusChatList"} +chatListItems = {"container": channelAndCategoriesListItems, "objectName": "chatListItems", "type": "StatusListView", "visible": True} +chatListItemDropAreaItem = {"container": chatListItems, "id": "chatListDelegate", "type": "DropArea", "isCategory": False, "visible": True} +categoryListItemDropAreaItem = {"container": chatListItems, "id": "chatListDelegate", "type": "DropArea", "isCategory": True, "visible": True} channel_identicon_StatusSmartIdenticon = {"container": None, "id": "identicon", "type": "StatusSmartIdenticon", "unnamed": 1, "visible": True} channel_name_StatusBaseText = {"container": None, "type": "StatusBaseText", "unnamed": 1, "visible": True} mainWindow_createChannelOrCategoryBtn_StatusBaseText = {"container": mainWindow_communityColumnView_CommunityColumnView, "objectName": "createChannelOrCategoryBtn", "type": "StatusBaseText", "visible": True} diff --git a/test/e2e/gui/screens/community.py b/test/e2e/gui/screens/community.py index 1839f933f7..16f0776116 100644 --- a/test/e2e/gui/screens/community.py +++ b/test/e2e/gui/screens/community.py @@ -155,7 +155,7 @@ class CategoryItem: def __init__(self, obj): self.object = obj - self.category_name: typing.Optional[Image] = None + self._category_name: typing.Optional[Image] = None self._add_category_button: typing.Optional[Button] = None self._more_button: typing.Optional[Button] = None self._arrow_button: typing.Optional[Button] = None @@ -198,14 +198,19 @@ class LeftPanel(QObject): self._members_text_label = TextLabel(communities_names.mainWindow_Members_TruncatedTextWithTooltip) self._general_channel_item = QObject(communities_names.scrollView_general_StatusChatListItem) self._add_channels_button = Button(communities_names.add_channels_StatusButton) - self._channel_list_item = QObject(communities_names.channel_listItem) self._channel_icon_template = QObject(communities_names.channel_identicon_StatusSmartIdenticon) self._channel_or_category_button = Button( communities_names.mainWindow_createChannelOrCategoryBtn_StatusBaseText) self._create_channel_menu_item = Button(communities_names.create_channel_StatusMenuItem) self._create_category_menu_item = Button(communities_names.create_category_StatusMenuItem) self._join_community_button = Button(communities_names.mainWindow_Join_Community_StatusButton) - self._categories_items_list = List(communities_names.scrollView_chatListItems_StatusListView) + + self.communityChatListAndCategories = QObject(communities_names.communityChatListAndCategories) + self.channelAndCategoriesListItems = QObject(communities_names.channelAndCategoriesListItems) + self.chatListItems = QObject(communities_names.chatListItems) + self.chatListItemDropAreaItem = QObject(communities_names.chatListItemDropAreaItem) + self.categoryItemDropAreaItem = QObject(communities_names.categoryListItemDropAreaItem) + self._category_list_item = QObject(communities_names.categoryItem_StatusChatListCategoryItem) self._create_category_button = Button(communities_names.add_categories_StatusFlatButton) self._delete_category_item = QObject(communities_names.delete_Category_StatusMenuItem) @@ -241,7 +246,7 @@ class LeftPanel(QObject): def channels(self) -> typing.List[UserChannel]: time.sleep(0.5) channels_list = [] - for obj in driver.findAllObjects(self._channel_list_item.real_name): + for obj in driver.findAllObjects(self.chatListItemDropAreaItem.real_name): container = driver.objectMap.realName(obj) self._channel_icon_template.real_name['container'] = container channels_list.append(UserChannel( @@ -254,7 +259,7 @@ class LeftPanel(QObject): @property @allure.step('Get categories') def categories_items(self) -> typing.List[CategoryItem]: - return [CategoryItem(item) for item in self._categories_items_list.items] + return [CategoryItem(item) for item in driver.findAllObjects(self.categoryItemDropAreaItem.real_name)] @allure.step('Get arrow button rotation value') def get_arrow_icon_rotation_value(self, category_name) -> int: @@ -289,7 +294,8 @@ class LeftPanel(QObject): @allure.step('Select channel') def select_channel(self, name: str): - for obj in driver.findAllObjects(self._channel_list_item.real_name): + time.sleep(3) + for obj in driver.findAllObjects(self.chatListItemDropAreaItem.real_name): if str(obj.objectName) == name: driver.mouseClick(obj) return obj @@ -302,7 +308,7 @@ class LeftPanel(QObject): @allure.step('Open category context menu') def open_category_context_menu(self): - self._category_list_item.right_click() + self.categoryItemDropAreaItem.right_click() @allure.step('Open create category popup') def open_create_category_popup(self, attempts: int = 2) -> NewCategoryPopup: @@ -324,16 +330,14 @@ class LeftPanel(QObject): @allure.step('Find category') def find_category_in_list( - self, category_name: str, timeout_sec: int = configs.timeouts.MESSAGING_TIMEOUT_SEC): - started_at = time.monotonic() - category = None - while category is None: - categories = self.categories_items - for _category in categories: - if _category.category_name == category_name: - category = _category - assert time.monotonic() - started_at < timeout_sec, f'Category: {category_name} not found in {categories}' - return category + self, category_name: str): + time.sleep(1) + categories = self.categories_items + for _category in categories: + if _category.category_name == category_name: + category = _category + return category + raise LookupError(f'Category: {category_name} not found in {categories}') def click_category(self, category_name: str): driver.mouseClick(self.find_category_in_list(category_name).object) @@ -376,7 +380,7 @@ class LeftPanel(QObject): @allure.step('Get channel or category index in the list') def get_channel_or_category_index(self, name: str) -> int: - for child in walk_children(self._categories_items_list.object): + for child in walk_children(self.chatListItems.object): if child.objectName == name: return child.visualIndex diff --git a/test/e2e/gui/screens/messages.py b/test/e2e/gui/screens/messages.py index dc996d69bd..e759f57c6e 100644 --- a/test/e2e/gui/screens/messages.py +++ b/test/e2e/gui/screens/messages.py @@ -236,7 +236,7 @@ class ChatView(QObject): @allure.step('Get messages') def messages(self, index: int) -> typing.List[Message]: _messages = [] - time.sleep(1) + time.sleep(2) # message_list_item has different indexes if we run multiple instances, so we pass index if index is not None: self._message_list_item.real_name['index'] = index diff --git a/test/e2e/scripts/utils/parsers.py b/test/e2e/scripts/utils/parsers.py new file mode 100644 index 0000000000..01fc26bef3 --- /dev/null +++ b/test/e2e/scripts/utils/parsers.py @@ -0,0 +1,13 @@ +from bs4 import BeautifulSoup + + +def remove_tags(html): + # parse html content + soup = BeautifulSoup(html, "html.parser") + + for data in soup(['style', 'script']): + # Remove tags + data.decompose() + + # return data by retrieving the tag content + return ' '.join(soup.stripped_strings) diff --git a/test/e2e/tests/communities/test_communities_categories.py b/test/e2e/tests/communities/test_communities_categories.py index b17b011ab4..5747903c2b 100644 --- a/test/e2e/tests/communities/test_communities_categories.py +++ b/test/e2e/tests/communities/test_communities_categories.py @@ -12,9 +12,6 @@ from . import marks pytestmark = marks - - - @allure.testcase('https://ethstatus.testrail.net/index.php?/cases/view/703272', 'Member role cannot add category') @allure.testcase('https://ethstatus.testrail.net/index.php?/cases/view/703273', 'Member role cannot edit category') @allure.testcase('https://ethstatus.testrail.net/index.php?/cases/view/703274', 'Member role cannot remove category') @@ -53,7 +50,6 @@ def test_member_role_cannot_add_edit_or_delete_category(main_screen: MainWindow) @pytest.mark.parametrize('category_name, general_checkbox', [pytest.param('Category in general', True)]) def test_clicking_community_category(main_screen: MainWindow, category_name, general_checkbox): - with step('Enable creation of community option'): settings = main_screen.left_panel.open_settings() settings.left_panel.open_advanced_settings().enable_creation_of_communities() diff --git a/test/e2e/tests/communities/test_communities_channels.py b/test/e2e/tests/communities/test_communities_channels.py index 4dc67ae118..136777949c 100644 --- a/test/e2e/tests/communities/test_communities_channels.py +++ b/test/e2e/tests/communities/test_communities_channels.py @@ -12,6 +12,7 @@ from constants import UserAccount from gui.components.context_menu import ContextMenu from gui.main_window import MainWindow from gui.screens.messages import MessagesScreen +from scripts.utils.parsers import remove_tags from . import marks pytestmark = marks @@ -205,14 +206,15 @@ def test_view_and_post_in_non_restricted_channel(multiple_instances, user_data_o main_screen.hide() with step( - f'User {user_one.name}, select non-restricted channel, verify that can view other messages and also can send message'): + f'User {user_one.name}, select non-restricted channel, verify that can view other messages and also ' + f'can send message'): aut_one.attach() main_screen.prepare() community_screen = main_screen.left_panel.select_community('Community with 2 users') community_screen.left_panel.select_channel(channel_name) messages_screen = MessagesScreen() message_object = messages_screen.chat.messages(0)[0] - assert 'Hi' in message_object.text, f"Message text is not found in last message" + assert 'Hi' in str(message_object.text), f"Message text is not found in last message" message_text = "Hi hi" messages_screen.group_chat.send_message_to_group_chat(message_text) main_screen.hide() @@ -221,7 +223,7 @@ def test_view_and_post_in_non_restricted_channel(multiple_instances, user_data_o aut_two.attach() main_screen.prepare() message_object = messages_screen.chat.messages(0)[0] - assert driver.waitFor(lambda: 'Hi hi' in message_object.text, + assert driver.waitFor(lambda: 'Hi hi' in remove_tags(str(message_object.text)), configs.timeouts.UI_LOAD_TIMEOUT_MSEC), f"Message text is not found in last message" community_screen.delete_channel(channel_name)