20 """unity shell autopilot tests and helpers - sub level package."""
23 from functools
import wraps
25 import ubuntuuitoolkit
26 from autopilot
import logging
as autopilot_logging
27 from autopilot
import input
28 from gi.repository
import Notify
32 launcher
as launcher_helpers
36 logger = logging.getLogger(__name__)
39 def disable_qml_mocking(fn):
40 """Simple decorator that disables the QML mocks from being loaded."""
42 def wrapper(*args, **kwargs):
44 tests_self._qml_mock_enabled =
False
45 return fn(*args, **kwargs)
49 def create_ephemeral_notification(
56 """Create an ephemeral (non-interactive) notification
58 :param summary: Summary text for the notification
59 :param body: Body text to display in the notification
60 :param icon: Path string to the icon to use
61 :param hint_strings: List of tuples containing the 'name' and value
62 for setting the hint strings for the notification
63 :param urgency: Urgency string for the noticiation, either: 'LOW',
69 "Creating ephemeral: summary(%s), body(%s), urgency(%r) "
77 notification = Notify.Notification.new(summary, body, icon)
81 notification.set_hint_string(key, value)
82 logger.info(
"Adding hint to notification: (%s, %s)", key, value)
83 notification.set_urgency(_get_urgency(urgency))
88 def _get_urgency(urgency):
89 """Translates urgency string to enum."""
90 _urgency_enums = {
'LOW': Notify.Urgency.LOW,
91 'NORMAL': Notify.Urgency.NORMAL,
92 'CRITICAL': Notify.Urgency.CRITICAL}
93 return _urgency_enums.get(urgency.upper())
96 class ShellView(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
97 """An helper class that makes it easy to interact with the shell"""
99 def get_greeter(self):
102 def get_login_loader(self):
103 return self.select_single(
"QQuickLoader", objectName=
"loginLoader")
105 def get_login_list(self):
106 return self.select_single(
"LoginList")
108 def get_bottombar(self):
109 return self.select_single(
"Bottombar")
111 def get_pinPadLoader(self):
112 return self.select_single(
114 objectName=
"pinPadLoader"
117 def get_lockscreen(self):
118 return self.select_single(
"Lockscreen")
120 def get_pinentryField(self):
121 return self.select_single(objectName=
"pinentryField")
123 def _get_indicator_panel_item(self, indicator_name):
124 return self.select_single(
126 objectName=indicator_name+
'-panelItem'
129 def _get_indicator_page(self, indicator_name):
130 return self.select_single(
132 objectName=indicator_name+
'-page'
135 @autopilot_logging.log_action(logger.info)
137 """Swipe to open the indicator, wait until it's open.
139 :returns: The indicator page.
142 start_x, start_y = input.get_center_point(widget)
145 self.pointing_device.drag(start_x, start_y, end_x, end_y)
146 self.wait_select_single(
'IndicatorsMenu', fullyOpened=
True)
149 @autopilot_logging.log_action(logger.info)
151 """Swipe to close the opened indicator, wait until it's closed."""
152 indicators_menu = self.wait_select_single(
'IndicatorsMenu')
153 end_x, end_y = input.get_center_point(indicators_menu)
155 start_y = self.height
156 self.pointing_device.drag(start_x, start_y, end_x, end_y)
157 indicators_menu.fullyClosed.wait_for(
True)
159 @autopilot_logging.log_action(logger.info)
161 """Show the dash swiping from the left."""
162 x, y, width, height = self.
_get_shell().globalRect
165 start_y = end_y = y + height // 2
167 self.pointing_device.drag(start_x, start_y, end_x, end_y)
170 def _get_shell(self):
171 return self.select_single(
'Shell')
174 """Return the id of the focused application."""
177 @autopilot_logging.log_action(logger.info)
179 """Open the dash clicking the dash icon on the launcher."""
181 launcher.click_dash_icon()
183 launcher.shown.wait_for(
False)
185 @autopilot_logging.log_action(logger.info)
186 def open_launcher(self):
191 def _get_launcher(self):
192 return self.select_single(launcher_helpers.Launcher)
194 def is_launcher_open(self):
197 @autopilot_logging.log_action(logger.info)
199 """Launch an application.
201 :parameter application_name: The name of the application to launch.
205 launcher.click_application_launcher_icon(application_name)
207 launcher.shown.wait_for(
False)
210 """Enter code 'code' into the single-pin lightdm pincode entry screen.
212 :param code: must be a string of numeric characters.
213 :raises: TypeError if code is not a string.
214 :raises: ValueError if code contains non-numeric characters.
217 if not isinstance(code, str):
219 "'code' parameter must be a string, not %r."
223 if not num.isdigit():
225 "'code' parameter contains non-numeric characters."
227 self.pointing_device.click_object(
230 def _get_pinpad_button(self, button_id):
231 return self.select_single(
233 objectName=
'pinPadButton{}'.format(button_id)
236 def get_shell_orientation_angle(self):
239 def get_shell_orientation(self):
242 def get_shell_primary_orientation(self):
245 def get_shell_native_orientation(self):
248 @autopilot_logging.log_action(logger.info)
250 """Wait for a notification dialog to appear.
252 :return: An object for the notification dialog data.
253 :raise StateNotFoundError: if the timeout expires when the
254 notification has not appeared.
257 notify_list = self.select_single(
'Notifications',
258 objectName=
'notificationList')
259 visible_notification = notify_list.wait_select_single(
'Notification',
261 return {
'summary': visible_notification.summary,
262 'body': visible_notification.body,
263 'iconSource': visible_notification.iconSource}
def open_indicator_page(self, indicator_name)
def get_current_focused_app_id(self)
def wait_for_notification(self)
def show_dash_from_launcher(self)
def _get_indicator_panel_item(self, indicator_name)
def show_dash_swiping(self)
def launch_application(self, application_name)
def _get_indicator_page(self, indicator_name)
def close_indicator_page(self)
def _get_pinpad_button(self, button_id)
def enter_pin_code(self, code)