import time import typing import allure from allure_commons._allure import step import configs import driver from constants import UserChannel from driver.objects_access import walk_children from gui.components.community.community_category_popup import NewCategoryPopup from gui.components.community.community_channel_popups import EditChannelPopup, NewChannelPopup from gui.components.community.welcome_community import WelcomeCommunityPopup from gui.components.delete_popup import DeletePopup, DeleteCategoryPopup from gui.elements.button import Button from gui.elements.list import List from gui.elements.object import QObject from gui.elements.text_label import TextLabel from gui.screens.community_settings import CommunitySettingsScreen from scripts.tools import image from scripts.tools.image import Image class CommunityScreen(QObject): def __init__(self): super().__init__('mainWindow_communityLoader_Loader') self.left_panel = LeftPanel() self.tool_bar = ToolBar() self.chat = Chat() self.right_panel = Members() @allure.step('Create channel') def create_channel(self, name: str, description: str, emoji: str = None): self.left_panel.open_create_channel_popup().create(name, description, emoji) @allure.step('Create channel') def edit_channel(self, channel, name: str, description: str, emoji: str = None): self.left_panel.select_channel(channel) self.tool_bar.open_edit_channel_popup().edit(name, description, emoji) @allure.step('Delete channel') def delete_channel(self, name: str): self.left_panel.select_channel(name) self.tool_bar.open_delete_channel_popup().delete() @allure.step('Verify channel') def verify_channel( self, name: str, description: str, emoji, color: str): with step('Channel is correct in channels list'): channel = self.left_panel.get_channel_parameters(name) assert channel.name == name assert channel.selected with step('Channel is correct in community toolbar'): assert self.tool_bar.channel_name == name assert self.tool_bar.channel_description == description if emoji is not None: assert self.tool_bar.channel_emoji == emoji assert self.tool_bar.channel_color == color with step('Verify channel in chat'): assert self.chat.channel_name == name if emoji is not None: assert self.chat.channel_emoji == emoji assert self.chat.channel_color == color @allure.step('Create category') def create_category(self, name: str, general_checkbox: bool): self.left_panel.open_create_category_popup().create(name, general_checkbox) @allure.step('Delete category from the list') def delete_category(self): self.left_panel.open_more_options() self.left_panel.open_delete_category_popup().delete() @allure.step('Verify category in the list') def verify_category(self, category_name: str): category = self.left_panel.find_category_in_list(category_name) assert category.category_name == category_name class ToolBar(QObject): def __init__(self): super().__init__('mainWindow_statusToolBar_StatusToolBar') self._more_options_button = Button('statusToolBar_chatToolbarMoreOptionsButton') self._options_list = List('o_StatusListView') self._edit_channel_context_item = QObject('edit_Channel_StatusMenuItem') self._channel_icon = QObject('statusToolBar_statusSmartIdenticonLetter_StatusLetterIdenticon') self._channel_name = TextLabel('statusToolBar_statusChatInfoButtonNameText_TruncatedTextWithTooltip') self._channel_description = TextLabel('statusToolBar_TruncatedTextWithTooltip') self._delete_channel_context_item = QObject('delete_Channel_StatusMenuItem') self._channel_header = QObject('statusToolBar_chatInfoBtnInHeader_StatusChatInfoButton') @property @allure.step('Get channel emoji') def channel_emoji(self): return self._channel_header.object.asset.emoji @property @allure.step('Get channel color') def channel_color(self) -> str: return str(self._channel_header.object.asset.color.name).lower() @property @allure.step('Get channel name') def channel_name(self) -> str: return self._channel_name.text @property @allure.step('Get channel description') def channel_description(self) -> str: return self._channel_description.text @allure.step('Open edit channel popup') def open_edit_channel_popup(self): self._more_options_button.click() self._edit_channel_context_item.click() return EditChannelPopup().wait_until_appears() @allure.step('Open delete channel popup') def open_delete_channel_popup(self): self._more_options_button.click() self._delete_channel_context_item.click() return DeletePopup().wait_until_appears() class CategoryItem: def __init__(self, obj): self.object = obj 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 self.init_ui() def __repr__(self): return self.category_name def init_ui(self): for child in walk_children(self.object): if str(getattr(child, 'id', '')) == 'statusChatListCategoryItem': self.category_name = str(child.text) elif str(getattr(child, 'id', '')) == 'addButton': self._add_channel_button = Button(name='', real_name=driver.objectMap.realName(child)) elif str(getattr(child, 'id', '')) == 'menuButton': self._more_button = Button(name='', real_name=driver.objectMap.realName(child)) elif str(getattr(child, 'id', '')) == 'toggleButton': self._arrow_button = Button(name='', real_name=driver.objectMap.realName(child)) @allure.step('Click arrow button') def click_arrow_button(self): self._arrow_button.click() class LeftPanel(QObject): def __init__(self): super().__init__('mainWindow_communityColumnView_CommunityColumnView') self._community_info_button = Button('mainWindow_communityHeaderButton_StatusChatInfoButton') self._community_logo = QObject('mainWindow_identicon_StatusSmartIdenticon') self._name_text_label = TextLabel('mainWindow_statusChatInfoButtonNameText_TruncatedTextWithTooltip') self._members_text_label = TextLabel('mainWindow_Members_TruncatedTextWithTooltip') self._channel_list_item = QObject('channel_listItem') self._channel_icon_template = QObject('channel_identicon_StatusSmartIdenticon') self._channel_or_category_button = Button('mainWindow_createChannelOrCategoryBtn_StatusBaseText') self._create_channel_menu_item = Button('create_channel_StatusMenuItem') self._create_category_menu_item = Button('create_category_StatusMenuItem') self._join_community_button = Button('mainWindow_Join_Community_StatusButton') self._categories_items_list = List('scrollView_chatListItems_StatusListView') self._category_list_item = QObject('categoryItem_StatusChatListCategoryItem') self._create_category_button = Button('add_categories_StatusFlatButton') self._delete_category_item = QObject('delete_Category_StatusMenuItem') self._add_channel_inside_category_item = QObject('scrollView_addButton_StatusChatListCategoryItemButton') self._more_button = Button('scrollView_menuButton_StatusChatListCategoryItemButton') self._arrow_button = Button('scrollView_toggleButton_StatusChatListCategoryItemButton') @property @allure.step('Get community logo') def logo(self) -> Image: return self._community_logo.image @property @allure.step('Get community name') def name(self) -> str: return self._name_text_label.text @property @allure.step('Get community members label') def members(self) -> str: return self._members_text_label.text @property @allure.step('Get Join button visible attribute') def is_join_community_visible(self) -> bool: return self._join_community_button.is_visible @property @allure.step('Get channels') def channels(self) -> typing.List[UserChannel]: channels_list = [] for obj in driver.findAllObjects(self._channel_list_item.real_name): container = driver.objectMap.realName(obj) self._channel_icon_template.real_name['container'] = container channels_list.append(UserChannel( str(obj.objectName), obj.item.selected )) return channels_list @property @allure.step('Get categories') def categories_items(self) -> typing.List[CategoryItem]: return [CategoryItem(item) for item in self._categories_items_list.items] @allure.step('Get channel params') def get_channel_parameters(self, name) -> UserChannel: for channal in self.channels: if channal.name == name: return channal raise LookupError(f'Channel not found in {self.channels}') @allure.step('Open community settings') def open_community_settings(self): self._community_info_button.click() return CommunitySettingsScreen().wait_until_appears() @allure.step('Open create channel popup') def open_create_channel_popup(self) -> NewChannelPopup: self._channel_or_category_button.click() self._create_channel_menu_item.click() return NewChannelPopup().wait_until_appears() @allure.step('Select channel') def select_channel(self, name: str): for obj in driver.findAllObjects(self._channel_list_item.real_name): if str(obj.objectName) == name: driver.mouseClick(obj) return raise LookupError('Channel not found') @allure.step('Open create category popup') def open_create_category_popup(self) -> NewCategoryPopup: self._channel_or_category_button.click() self._create_category_menu_item.click() return NewCategoryPopup().wait_until_appears() @allure.step('Open join community popup') def open_welcome_community_popup(self): self._join_community_button.click() return WelcomeCommunityPopup().wait_until_appears() @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 @allure.step('Open more options') def open_more_options(self): self._arrow_button.click() self._more_button.click() @allure.step('Open delete category popup') def open_delete_category_popup(self) -> DeleteCategoryPopup: self._delete_category_item.click() return DeleteCategoryPopup().wait_until_appears() @allure.step('Open new channel popup inside category') def open_new_channel_popup_in_category(self) -> NewChannelPopup: self._arrow_button.click() self._add_channel_inside_category_item.click() return NewChannelPopup().wait_until_appears() class Chat(QObject): def __init__(self): super().__init__('mainWindow_ChatColumnView') self._channel_icon = QObject('chatMessageViewDelegate_channelIdentifierSmartIdenticon_StatusSmartIdenticon') self._channel_name_label = TextLabel('chatMessageViewDelegate_channelIdentifierNameText_StyledText') self._channel_welcome_label = TextLabel('chatMessageViewDelegate_Welcome') self._channel_identifier_view = QObject('chatMessageViewDelegate_ChannelIdentifierView') @property @allure.step('Get channel emoji') def channel_emoji(self): return self._channel_identifier_view.object.chatEmoji @property @allure.step('Get channel color') def channel_color(self) -> str: return str(self._channel_identifier_view.object.chatColor).lower() @property @allure.step('Get channel name') def channel_name(self) -> str: return self._channel_name_label.text @property @allure.step('Get channel welcome note') def channel_welcome_note(self) -> str: return self._channel_welcome_label.text class Members(QObject): def __init__(self): super().__init__('mainWindow_UserListPanel') self._member_item = QObject('userListPanel_StatusMemberListItem') @property @allure.step('Get all members') def members(self) -> typing.List[str]: return [str(member.statusListItemTitle.text) for member in driver.findAllObjects(self._member_item.real_name)]