Skip to content
This repository was archived by the owner on Aug 13, 2024. It is now read-only.

Commit a15f4b9

Browse files
committed
chore: replaced a method for toast message verification
1 parent 71aa23c commit a15f4b9

19 files changed

+81
-92
lines changed

gui/components/toast_message.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import typing
2+
13
import allure
24

3-
import driver
5+
from driver.objects_access import walk_children
46
from gui.elements.object import QObject
57
from gui.objects_map import names
68

@@ -11,14 +13,12 @@ def __init__(self):
1113
super(ToastMessage, self).__init__(names.ephemeral_Notification_List)
1214
self._toast_message = QObject(names.ephemeralNotificationList_StatusToastMessage)
1315

14-
@property
1516
@allure.step('Get toast messages')
16-
def get_toast_messages(self):
17+
def get_toast_messages(self) -> typing.List[str]:
1718
messages = []
18-
for obj in driver.findAllObjects(self._toast_message.real_name):
19-
messages.append(str(obj.primaryText))
19+
for child in walk_children(self.object):
20+
if getattr(child, 'id', '') == 'title':
21+
messages.append(str(child.text))
2022
if len(messages) == 0:
21-
raise LookupError(
22-
'Toast messages were not found')
23-
else:
24-
return messages
23+
raise LookupError('Toast message not found')
24+
return messages

gui/main_window.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import os
32
import time
43
import typing
54

@@ -215,11 +214,11 @@ def create_community(self, name, description, intro, outro, logo, banner) -> Com
215214
return app_screen
216215

217216
@allure.step('Wait for notification and get text')
218-
def wait_for_notification(self, timeout_msec: int = configs.timeouts.UI_LOAD_TIMEOUT_SEC) -> str:
217+
def wait_for_notification(self, timeout_msec: int = configs.timeouts.UI_LOAD_TIMEOUT_SEC) -> list[str]:
219218
started_at = time.monotonic()
220219
while True:
221220
try:
222-
return ToastMessage().get_toast_messages
221+
return ToastMessage().get_toast_messages()
223222
except LookupError as err:
224223
LOG.info(err)
225224
assert time.monotonic() - started_at < timeout_msec, str(err)

gui/screens/settings_wallet.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from gui.components.wallet.testnet_mode_popup import TestnetModePopup
1515

1616
from gui.components.wallet.wallet_account_popups import AccountPopup, EditAccountFromSettingsPopup
17-
from gui.components.toast_message import ToastMessage
1817
from gui.elements.button import Button
1918
from gui.elements.check_box import CheckBox
2019
from gui.elements.object import QObject
@@ -313,22 +312,6 @@ def click_revert_to_default_and_go_to_networks_main_screen(self, attempts: int =
313312
else:
314313
raise f"Networks screen was not opened"
315314

316-
@allure.step('Check toast message')
317-
def check_toast_message(self, network_tab):
318-
match network_tab:
319-
case WalletNetworkSettings.EDIT_NETWORK_LIVE_TAB.value:
320-
assert len(ToastMessage().get_toast_messages) == 1, \
321-
f"Multiple toast messages appeared"
322-
message = ToastMessage().get_toast_messages[0]
323-
assert message == WalletNetworkSettings.REVERT_TO_DEFAULT_LIVE_MAINNET_TOAST_MESSAGE.value, \
324-
f"Toast message is incorrect, current message is {message}"
325-
case WalletNetworkSettings.EDIT_NETWORK_TEST_TAB.value:
326-
assert len(ToastMessage().get_toast_messages) == 1, \
327-
f"Multiple toast messages appeared"
328-
message = ToastMessage().get_toast_messages[0]
329-
assert message == WalletNetworkSettings.REVERT_TO_DEFAULT_TEST_MAINNET_TOAST_MESSAGE.value, \
330-
f"Toast message is incorrect, current message is {message}"
331-
332315
@allure.step('Verify elements for the edit network view')
333316
def check_available_elements_on_edit_view(self, network_tab):
334317
match network_tab:

tests/communities/test_communities_permissions.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import configs
66
from gui.components.changes_detected_popup import PermissionsChangesDetectedToastMessage
77
from gui.components.delete_popup import DeletePermissionPopup
8-
from gui.components.toast_message import ToastMessage
98
from gui.screens.community_settings import PermissionsIntroView
109
from . import marks
1110

@@ -54,13 +53,13 @@ def test_add_edit_and_remove_permissions(main_screen: MainWindow, params, checkb
5453
permissions_settings.set_in(in_channel)
5554
permissions_settings.create_permission()
5655

57-
# TODO: https://github.com/status-im/desktop-qa-automation/issues/547
58-
# with step('Check toast message for permission creation'):
59-
# assert len(ToastMessage().get_toast_messages) == 1, \
60-
# f"Multiple toast messages appeared"
61-
# message = ToastMessage().get_toast_messages[0]
62-
# assert message == ToastMessages.CREATE_PERMISSION_TOAST.value, \
63-
# f"Toast message is incorrect, current message is {message}"
56+
with step('Check toast message for permission creation'):
57+
toast_messages = main_screen.wait_for_notification()
58+
assert len(toast_messages) == 1, \
59+
f"Multiple toast messages appeared"
60+
message = toast_messages[0]
61+
assert message == ToastMessages.CREATE_PERMISSION_TOAST.value, \
62+
f"Toast message is incorrect, current message is {message}"
6463

6564
with step('Created permission is displayed on permission page'):
6665
if asset_title is not False:
@@ -108,11 +107,10 @@ def test_add_edit_and_remove_permissions(main_screen: MainWindow, params, checkb
108107
assert driver.waitFor(lambda: permissions_intro_view.is_hide_icon_visible,
109108
configs.timeouts.UI_LOAD_TIMEOUT_MSEC)
110109

111-
# TODO: https://github.com/status-im/desktop-qa-automation/issues/547
112-
# with step('Check toast message for edited permission'):
113-
# messages = ToastMessage().get_toast_messages
114-
# assert ToastMessages.UPDATE_PERMISSION_TOAST.value in messages, \
115-
# f"Toast message is incorrect, current message is {message}"
110+
with step('Check toast message for edited permission'):
111+
messages = main_screen.wait_for_notification()
112+
assert ToastMessages.UPDATE_PERMISSION_TOAST.value in messages, \
113+
f"Toast message is incorrect, current message is {message}"
116114

117115
with step('Delete permission'):
118116
permissions_intro_view.click_delete_permission()
@@ -121,8 +119,7 @@ def test_add_edit_and_remove_permissions(main_screen: MainWindow, params, checkb
121119
with step('Verify that permission was deleted'):
122120
assert driver.waitFor(lambda: PermissionsIntroView().is_visible)
123121

124-
# TODO: https://github.com/status-im/desktop-qa-automation/issues/547
125-
# with step('Check toast message for deleted permission'):
126-
# messages = ToastMessage().get_toast_messages
127-
# assert ToastMessages.DELETE_PERMISSION_TOAST.value in messages, \
128-
# f"Toast message is incorrect, current message is {message}"
122+
with step('Check toast message for deleted permission'):
123+
messages = main_screen.wait_for_notification()
124+
assert ToastMessages.DELETE_PERMISSION_TOAST.value in messages, \
125+
f"Toast message is incorrect, current message is {message}"

tests/settings/settings_messaging/test_messaging_settings_accept_request.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import constants
88
from constants import UserAccount
99
from constants.messaging import Messaging
10-
from gui.components.toast_message import ToastMessage
1110
from gui.main_window import MainWindow
1211

1312
pytestmark = marks
@@ -67,13 +66,13 @@ def test_messaging_settings_accepting_request(multiple_instance, user_data_one,
6766
assert user_one.name == contacts_settings.contact_items[0].contact
6867
assert len(contacts_settings.contact_items) == 1
6968

70-
# TODO: https://github.com/status-im/desktop-qa-automation/issues/547
71-
# with step('Verify toast message about new contact request received'):
72-
# assert len(ToastMessage().get_toast_messages) == 1, \
73-
# f"Multiple toast messages appeared"
74-
# message = ToastMessage().get_toast_messages[0]
75-
# assert message == Messaging.NEW_CONTACT_REQUEST.value, \
76-
# f"Toast message is incorrect, current message is {message}"
69+
with step('Verify toast message about new contact request received'):
70+
toast_messages = main_window.wait_for_notification()
71+
assert len(toast_messages) == 1, \
72+
f"Multiple toast messages appeared"
73+
message = toast_messages[0]
74+
assert message == Messaging.NEW_CONTACT_REQUEST.value, \
75+
f"Toast message is incorrect, current message is {message}"
7776

7877
with step(f'User {user_two.name}, accept contact request from {user_one.name}'):
7978
contacts_settings.accept_contact_request(user_one.name)

tests/settings/settings_wallet/test_wallet_settings_acct_interactions_delete_account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_delete_generated_account_from_wallet_settings(
6464
delete_confirmation_popup.remove_account_with_confirmation()
6565

6666
with step('Verify toast message notification when removing account'):
67-
messages = ToastMessage().get_toast_messages
67+
messages = main_screen.wait_for_notification()
6868
assert f'"{account_name}" successfully removed' in messages, \
6969
f"Toast message about account removal is not correct or not present. Current list of messages: {messages}"
7070

tests/settings/settings_wallet/test_wallet_settings_add_account.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def test_add_new_account_from_wallet_settings(
3838
add_account_popup.wait_until_hidden()
3939

4040
with step('Verify toast message notification when adding account'):
41-
assert len(ToastMessage().get_toast_messages) == 1, \
41+
assert len(main_screen.wait_for_notification()) == 1, \
4242
f"Multiple toast messages appeared"
43-
message = ToastMessage().get_toast_messages[0]
43+
message = main_screen.wait_for_notification()[0]
4444
assert message == f'"{account_name}" successfully added'
4545

4646
with step('Verify that the account is correctly displayed in accounts list on main wallet screen'):

tests/settings/settings_wallet/test_wallet_settings_networks_edit_network.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,18 @@ def test_settings_networks_edit_restore_defaults(main_screen: MainWindow, networ
6161
edit_network_form.click_revert_to_default_and_go_to_networks_main_screen()
6262

6363
with step('Verify toast message appears for reverting to defaults'):
64-
edit_network_form.check_toast_message(network_tab)
64+
if network_tab == WalletNetworkSettings.EDIT_NETWORK_LIVE_TAB.value:
65+
assert len(main_screen.wait_for_notification()) == 1, \
66+
f"Multiple toast messages appeared"
67+
message = main_screen.wait_for_notification()[0]
68+
assert message == WalletNetworkSettings.REVERT_TO_DEFAULT_LIVE_MAINNET_TOAST_MESSAGE.value, \
69+
f"Toast message is incorrect, current message is {message}"
70+
elif network_tab == WalletNetworkSettings.EDIT_NETWORK_TEST_TAB.value:
71+
assert len(main_screen.wait_for_notification()) == 1, \
72+
f"Multiple toast messages appeared"
73+
message = main_screen.wait_for_notification()[0]
74+
assert message == WalletNetworkSettings.REVERT_TO_DEFAULT_TEST_MAINNET_TOAST_MESSAGE.value, \
75+
f"Toast message is incorrect, current message is {message}"
6576

6677
with step('Open Ethereum Mainnet network item to edit'):
6778
edit_network_form = networks.click_network_item_to_open_edit_view(

tests/settings/settings_wallet/test_wallet_settings_networks_testnet_mode.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def test_switch_testnet_mode(main_screen: MainWindow):
3030
networks.switch_testnet_mode_toggle().turn_on_testnet_mode_in_testnet_modal()
3131

3232
with step('Verify that Testnet mode turned on'):
33-
assert len(ToastMessage().get_toast_messages) == 1, \
33+
assert len(main_screen.wait_for_notification()) == 1, \
3434
f"Multiple toast messages appeared"
35-
message = ToastMessage().get_toast_messages[0]
35+
message = main_screen.wait_for_notification()[0]
3636
assert message == WalletNetworkSettings.TESTNET_ENABLED_TOAST_MESSAGE.value, \
3737
f"Toast message is incorrect, current message is {message}"
3838
if not configs.system.TEST_MODE:
@@ -52,8 +52,8 @@ def test_switch_testnet_mode(main_screen: MainWindow):
5252
networks.switch_testnet_mode_toggle().turn_off_testnet_mode_in_testnet_modal()
5353

5454
with step('Verify that Testnet mode turned off'):
55-
assert len(ToastMessage().get_toast_messages) == 2
56-
message = ToastMessage().get_toast_messages[1]
55+
assert len(main_screen.wait_for_notification()) == 2
56+
message = main_screen.wait_for_notification()[1]
5757
assert message == WalletNetworkSettings.TESTNET_DISABLED_TOAST_MESSAGE.value, \
5858
f"Toast message is incorrect, current message is {message}"
5959
if not configs.system.TEST_MODE:
@@ -105,9 +105,9 @@ def test_switch_testnet_off_by_toggle_and_cancel_in_confirmation(main_screen: Ma
105105
testnet_modal.turn_on_testnet_mode_in_testnet_modal()
106106

107107
with step('Verify testnet mode is enabled'):
108-
assert len(ToastMessage().get_toast_messages) == 1, \
108+
assert len(main_screen.wait_for_notification()) == 1, \
109109
f"Multiple toast messages appeared"
110-
message = ToastMessage().get_toast_messages[0]
110+
message = main_screen.wait_for_notification()[0]
111111
assert message == WalletNetworkSettings.TESTNET_ENABLED_TOAST_MESSAGE.value, \
112112
f"Toast message is incorrect, current message is {message}"
113113
if not configs.system.TEST_MODE:

tests/settings/settings_wallet/test_wallet_settings_saved_addresses_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_wallet_settings_add_saved_address(main_screen: MainWindow, address: str
4242
configs.timeouts.UI_LOAD_TIMEOUT_MSEC), f'Address: {name} not found'
4343

4444
with step('Verify toast message when adding saved address'):
45-
messages = ToastMessage().get_toast_messages
45+
messages = main_screen.wait_for_notification()
4646
assert f'{name} successfully added to your saved addresses' in messages, \
4747
f"Toast message about adding saved address is not correct or not present. \
4848
Current list of messages: {messages}"

0 commit comments

Comments
 (0)