@@ -22,6 +22,10 @@
22from time import sleep
22from time import sleep
23from functools import wraps
23from functools import wraps
24from gi.repository import Notify
24from gi.repository import Notify
25+import ubuntuuitoolkit
26+from autopilot import introspection
27+from autopilot.introspection import dbus
28+from unity8.shell import emulators
26import logging
30import logging
@@ -105,3 +109,66 @@ def _get_urgency(urgency):
105 'NORMAL': Notify.Urgency.NORMAL,
109 'NORMAL': Notify.Urgency.NORMAL,
106 'CRITICAL': Notify.Urgency.CRITICAL}
110 'CRITICAL': Notify.Urgency.CRITICAL}
107 return _urgency_enums.get(urgency.upper())
111 return _urgency_enums.get(urgency.upper())
113+def wait_for_notification_dialog(self, timeout):
114+ """Wait for a notification dialog to appear.
116+ :param int timeout: Maximum amount of time to wait for the notification,
118+ :return: An autopilot custom proxy object for the notification dialog.
119+ :raise StateNotFoundError: if the timeout expires when the
120+ notification has not appeared.
123+ notify_list = self.main_window.select_single('Notifications',
124+ objectName='notificationList')
125+ visible_notification = None
126+ for i in range(timeout):
127+ notification_list = notify_list.select_many('Notification')
128+ visible_notification = None
129+ for notification1 in notification_list:
130+ if (notification1.visible):
131+ visible_notification = notification1
133+ if (not visible_notification):
134+ if i == timeout - 1:
135+ raise dbus.StateNotFoundError
137+ return visible_notification
139+ return visible_notification
140+ # Strategy to test the helper:
141+ # use the create notification script to verify that the method returns
142+ # when a notification is received.
144+class Notification(emulators.UnityEmulatorBase):
146+ """Custom proxy object for Notification dialogs."""
148+ def validate_dbus_object(cls, path, state):
149+ name = introspection.get_classname_from_path(path)
150+ if name == b'Notification':
154+ def __init__(self, state, path, backend):
155+ super(Notification, self).__init__(state, path, backend)
157+ self._summary = self.summary
158+ self._body = self.body
159+ self._iconSource = self.iconSource
163+ """Return the contents of a notification dialog.
165+ :return: A data object that represents the contents of a notification
169+ return { 'summary': self._summary,
171+ 'iconSource': self._iconSource }
172+ # Strategy to test the helper:
173+ # use the create notification script to get a notification dialog.
174+ # Check that the arguments passed to the script match the fields