@@ -17,12 +17,21 @@
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
20−"""unity shell autopilot tests and emulators - sub level package."""
20+"""unity shell autopilot tests and helpers - sub level package."""
22from functools import wraps
23from functools import wraps
25+import ubuntuuitoolkit
26+from autopilot import logging as autopilot_logging
27+from autopilot import input
23from gi.repository import Notify
28from gi.repository import Notify
25−import logging
30+from unity8 import (
32+ launcher as launcher_helpers
27logger = logging.getLogger(__name__)
36logger = logging.getLogger(__name__)
@@ -82,3 +91,173 @@ def _get_urgency(urgency):
82 'NORMAL': Notify.Urgency.NORMAL,
91 'NORMAL': Notify.Urgency.NORMAL,
83 'CRITICAL': Notify.Urgency.CRITICAL}
92 'CRITICAL': Notify.Urgency.CRITICAL}
84 return _urgency_enums.get(urgency.upper())
93 return _urgency_enums.get(urgency.upper())
96+class QQuickView(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
97+ """An helper class that makes it easy to interact with the shell"""
99+ def get_greeter(self):
100+ return self.select_single(greeter.Greeter)
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)
136+ def open_indicator_page(self, indicator_name):
137+ """Swipe to open the indicator, wait until it's open.
139+ :returns: The indicator page.
141+ widget = self._get_indicator_panel_item(indicator_name)
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)
147+ return self._get_indicator_page(indicator_name)
149+ @autopilot_logging.log_action(logger.info)
150+ def close_indicator_page(self):
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)
160+ def show_dash_swiping(self):
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)
168+ self.get_current_focused_app_id().wait_for('unity8-dash')
170+ def _get_shell(self):
171+ return self.select_single('Shell')
173+ def get_current_focused_app_id(self):
174+ """Return the id of the focused application."""
175+ return self._get_shell().focusedApplicationId
177+ @autopilot_logging.log_action(logger.info)
178+ def show_dash_from_launcher(self):
179+ """Open the dash clicking the dash icon on the launcher."""
180+ launcher = self.open_launcher()
181+ launcher.click_dash_icon()
182+ self.get_current_focused_app_id().wait_for('unity8-dash')
183+ launcher.shown.wait_for(False)
185+ @autopilot_logging.log_action(logger.info)
186+ def open_launcher(self):
187+ launcher = self._get_launcher()
191+ def _get_launcher(self):
192+ return self.select_single(launcher_helpers.Launcher)
194+ def is_launcher_open(self):
195+ return self._get_launcher().shown
197+ @autopilot_logging.log_action(logger.info)
198+ def launch_application(self, application_name):
199+ """Launch an application.
201+ :parameter application_name: The name of the application to launch.
204+ launcher = self.open_launcher()
205+ launcher.click_application_launcher_icon(application_name)
206+ self.get_current_focused_app_id().wait_for(application_name)
207+ launcher.shown.wait_for(False)
209+ def enter_pin_code(self, code):
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(
228+ self._get_pinpad_button(int(num)))
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):
237+ return self._get_shell().orientationAngle
239+ def get_shell_orientation(self):
240+ return self._get_shell().orientation
242+ def get_shell_primary_orientation(self):
243+ return self._get_shell().primaryOrientation
245+ def get_shell_native_orientation(self):
246+ return self._get_shell().nativeOrientation
248+ @autopilot_logging.log_action(logger.info)
249+ def wait_for_notification(self):
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}