From c348f22d0fd00df0246132c590faca7590bce71d Mon Sep 17 00:00:00 2001 From: Valentina Novgorodtceva Date: Fri, 16 Feb 2024 13:33:56 +0700 Subject: [PATCH] chore: attempt to fix AttributeError: Attempt to access a property of a null object --- gui/screens/community_settings.py | 37 ++++++++++++++----- .../test_communities_permissions.py | 24 +++++++----- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/gui/screens/community_settings.py b/gui/screens/community_settings.py index 7c9924f..47480d7 100644 --- a/gui/screens/community_settings.py +++ b/gui/screens/community_settings.py @@ -450,20 +450,37 @@ class PermissionsSettingsView(QObject): self._is_allowed_to_edit_tag = QObject(names.isAllowedToEditPermissionView_StatusListItemTag) @allure.step('Get titles of Who holds tags') - def get_who_holds_tags_titles(self) -> typing.List[str]: - who_holds_tags = [str(tag.title) for tag in driver.findAllObjects(self._who_holds_tag.real_name)] - return who_holds_tags + def get_who_holds_tags_titles(self, attempt: int = 2) -> typing.List[str]: + try: + return [str(tag.title) for tag in driver.findAllObjects(self._who_holds_tag.real_name)] + except AttributeError as er: + if attempt: + time.sleep(1) + return self.get_who_holds_tags_titles(attempt - 1) + else: + raise er @allure.step('Get titles of Is Allowed tags') - def get_is_allowed_tags_titles(self) -> typing.List[str]: - is_allowed_tags = [str(tag.title) for tag in driver.findAllObjects(self._is_allowed_tag.real_name)] - return is_allowed_tags + def get_is_allowed_tags_titles(self, attempt: int = 2) -> typing.List[str]: + try: + return [str(tag.title) for tag in driver.findAllObjects(self._is_allowed_tag.real_name)] + except AttributeError as er: + if attempt: + time.sleep(1) + return self.get_is_allowed_tags_titles(attempt - 1) + else: + raise er @allure.step('Get title of inCommunity tag') - def get_in_community_in_channel_tags_titles(self) -> typing.List[str]: - in_community_in_channel_tags = [str(tag.title) for tag in - driver.findAllObjects(self._in_community_in_channel_tag.real_name)] - return in_community_in_channel_tags + def get_in_community_in_channel_tags_titles(self, attempt: int = 2) -> typing.List[str]: + try: + return [str(tag.title) for tag in driver.findAllObjects(self._in_community_in_channel_tag.real_name)] + except AttributeError as er: + if attempt: + time.sleep(1) + return self.get_in_community_in_channel_tags_titles(attempt - 1) + else: + raise er @allure.step('Set state of who holds checkbox') def set_who_holds_checkbox_state(self, state): diff --git a/tests/communities/test_communities_permissions.py b/tests/communities/test_communities_permissions.py index d2c76b0..206de7a 100644 --- a/tests/communities/test_communities_permissions.py +++ b/tests/communities/test_communities_permissions.py @@ -2,6 +2,7 @@ import allure import pytest from allure_commons._allure import step +import configs from gui.components.changes_detected_popup import PermissionsChangesDetectedToastMessage from gui.components.delete_popup import DeletePermissionPopup from gui.components.toast_message import ToastMessage @@ -62,16 +63,21 @@ def test_add_edit_and_remove_permissions(main_screen: MainWindow, params, checkb with step('Created permission is displayed on permission page'): if asset_title is not False: - assert driver.waitFor(lambda: asset_title in permissions_settings.get_who_holds_tags_titles()) + assert driver.waitFor(lambda: asset_title in permissions_settings.get_who_holds_tags_titles(), + configs.timeouts.UI_LOAD_TIMEOUT_MSEC) if second_asset_title is not False: - assert driver.waitFor(lambda: second_asset_title in permissions_settings.get_who_holds_tags_titles()) + assert driver.waitFor(lambda: second_asset_title in permissions_settings.get_who_holds_tags_titles(), + configs.timeouts.UI_LOAD_TIMEOUT_MSEC) if allowed_to_title is not False: - assert driver.waitFor(lambda: allowed_to_title in permissions_settings.get_is_allowed_tags_titles()) + assert driver.waitFor(lambda: allowed_to_title in permissions_settings.get_is_allowed_tags_titles(), + configs.timeouts.UI_LOAD_TIMEOUT_MSEC) if in_channel is False: assert driver.waitFor( - lambda: params['name'] in permissions_settings.get_in_community_in_channel_tags_titles()) + lambda: params['name'] in permissions_settings.get_in_community_in_channel_tags_titles(), + configs.timeouts.UI_LOAD_TIMEOUT_MSEC) if in_channel: - assert driver.waitFor(lambda: in_channel in permissions_settings.get_in_community_in_channel_tags_titles()) + assert driver.waitFor(lambda: in_channel in permissions_settings.get_in_community_in_channel_tags_titles(), + configs.timeouts.UI_LOAD_TIMEOUT_MSEC) with step('Edit permission'): edit_permission_view = permissions_intro_view.open_edit_permission_view() @@ -88,14 +94,14 @@ def test_add_edit_and_remove_permissions(main_screen: MainWindow, params, checkb changes_popup.update_permission() if allowed_to is 'becomeAdmin' and checkbox_state is True: if asset_title is not False: - assert driver.waitFor(lambda: asset_title not in permissions_settings.get_who_holds_tags_titles()) + assert driver.waitFor(lambda: asset_title not in permissions_settings.get_who_holds_tags_titles(), configs.timeouts.UI_LOAD_TIMEOUT_MSEC) if second_asset_title is not False: assert driver.waitFor( - lambda: second_asset_title not in permissions_settings.get_who_holds_tags_titles()) + lambda: second_asset_title not in permissions_settings.get_who_holds_tags_titles(), configs.timeouts.UI_LOAD_TIMEOUT_MSEC) elif checkbox_state is False: - assert driver.waitFor(lambda: 'Become member' in permissions_settings.get_is_allowed_tags_titles()) + assert driver.waitFor(lambda: 'Become member' in permissions_settings.get_is_allowed_tags_titles(), configs.timeouts.UI_LOAD_TIMEOUT_MSEC) else: - assert driver.waitFor(lambda: permissions_intro_view.is_hide_icon_visible) + assert driver.waitFor(lambda: permissions_intro_view.is_hide_icon_visible, configs.timeouts.UI_LOAD_TIMEOUT_MSEC) with step('Check toast message for edited permission'): messages = ToastMessage().get_toast_messages