~canonical-platform-qa/ubuntu-system-tests/change-protected-modules-to-public

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/helpers/unity8/shell_view.py

  • Committer: Tarmac
  • Author(s): Heber Parrucci
  • Date: 2016-11-18 17:36:00 UTC
  • mfrom: (474.1.17 uitoolkit-1)
  • Revision ID: tarmac-20161118173600-9nxirh8eff8uco1d
Removing dependency with ubuntuuitoolkit in ust.

Approved by Richard Huddie, Santiago Baldassin, platform-qa-bot, Sergio Cazzolato.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
19
#
20
20
 
21
 
from unity8.shell.emulators import main_window
 
21
import logging
 
22
from autopilot import logging as autopilot_logging
 
23
from unity8 import UnityException
22
24
 
23
25
from ubuntu_system_tests.helpers.autopilot import validate_dbus_object
24
26
from ubuntu_system_tests.helpers.indicators.message import NotificationsIndicatorItem  # NOQA
25
27
from ubuntu_system_tests.helpers.notifications.utils import Notifications
26
28
from ubuntu_system_tests.helpers.unity8 import UNITY8_PATH_ROOT
27
 
 
28
 
 
29
 
class ShellView(main_window.ShellView):
 
29
from ubuntu_system_tests.helpers.ubuntuuitoolkit._custom_proxy_objects._common import UbuntuUIToolkitCustomProxyObjectBase  # NOQA
 
30
logger = logging.getLogger(__name__)
 
31
 
 
32
 
 
33
class ShellView(UbuntuUIToolkitCustomProxyObjectBase):
30
34
    """Class to extend Unity8 main window ShellView."""
31
35
 
32
36
    @classmethod
112
116
        return indicator_page.fullyOpened
113
117
 
114
118
    def close_indicator_page(self):
115
 
        """
116
 
        Override the method to only try to close the indicator panel if its
117
 
        not already.
118
 
        """
 
119
        """Swipe to close the opened indicator, wait until it's closed."""
119
120
        if self._is_indicator_panel_opened():
120
 
            super().close_indicator_page()
 
121
            indicators_menu = self.wait_select_single('IndicatorsMenu')
 
122
            end_x, end_y = input.get_center_point(indicators_menu)
 
123
            start_x = end_x
 
124
            start_y = self.height
 
125
            self.pointing_device.drag(start_x, start_y, end_x, end_y)
 
126
            indicators_menu.fullyClosed.wait_for(True)
121
127
 
122
128
    def is_indicator_item_hidden(self, indicator_name):
123
129
        """
127
133
        item = self.select_single('IndicatorItem',
128
134
                                  objectName=indicator_name + '-panelItem')
129
135
        return item.hidden
 
136
 
 
137
    def get_greeter(self):
 
138
        return self.select_single('Greeter')
 
139
 
 
140
    def get_login_loader(self):
 
141
        return self.select_single("QQuickLoader", objectName="loginLoader")
 
142
 
 
143
    def get_login_list(self):
 
144
        return self.select_single("LoginList")
 
145
 
 
146
    def get_bottombar(self):
 
147
        return self.select_single("Bottombar")
 
148
 
 
149
    def get_pinPadLoader(self):
 
150
        return self.select_single(
 
151
            "QQuickLoader",
 
152
            objectName="pinPadLoader"
 
153
        )
 
154
 
 
155
    def get_lockscreen(self):
 
156
        return self.select_single("Lockscreen")
 
157
 
 
158
    def get_pinentryField(self):
 
159
        return self.select_single(objectName="pinentryField")
 
160
 
 
161
    def _get_indicator_panel_item(self, indicator_name):
 
162
        return self.select_single(
 
163
            'IndicatorItem',
 
164
            objectName=indicator_name + '-panelItem'
 
165
        )
 
166
 
 
167
    def _get_indicator_page(self, indicator_name):
 
168
        return self.select_single(
 
169
            'IndicatorPage',
 
170
            objectName=indicator_name + '-page'
 
171
        )
 
172
 
 
173
    @autopilot_logging.log_action(logger.info)
 
174
    def open_indicator_page(self, indicator_name):
 
175
        """Swipe to open the indicator, wait until it's open.
 
176
 
 
177
        :returns: The indicator page.
 
178
        """
 
179
        widget = self._get_indicator_panel_item(indicator_name)
 
180
        start_x, start_y = input.get_center_point(widget)
 
181
        end_x = start_x
 
182
        end_y = self.height
 
183
        self.pointing_device.drag(start_x, start_y, end_x, end_y)
 
184
        self.wait_select_single('IndicatorsMenu', fullyOpened=True)
 
185
        return self._get_indicator_page(indicator_name)
 
186
 
 
187
    @autopilot_logging.log_action(logger.info)
 
188
    def show_dash_swiping(self):
 
189
        """Show the dash swiping from the left."""
 
190
        x, y, width, height = self._get_shell().globalRect
 
191
        start_x = x
 
192
        end_x = x + width
 
193
        start_y = end_y = y + height // 2
 
194
 
 
195
        self.pointing_device.drag(start_x, start_y, end_x, end_y)
 
196
        self.get_current_focused_app_id().wait_for('unity8-dash')
 
197
 
 
198
    def _get_shell(self):
 
199
        return self.select_single('Shell')
 
200
 
 
201
    def get_current_focused_app_id(self):
 
202
        """Return the id of the focused application."""
 
203
        return self._get_shell().focusedApplicationId
 
204
 
 
205
    @autopilot_logging.log_action(logger.info)
 
206
    def show_dash_from_launcher(self):
 
207
        """Open the dash clicking the dash icon on the launcher."""
 
208
        launcher = self.open_launcher()
 
209
        launcher.click_dash_icon()
 
210
        self.get_current_focused_app_id().wait_for('unity8-dash')
 
211
        launcher.shown.wait_for(False)
 
212
 
 
213
    @autopilot_logging.log_action(logger.info)
 
214
    def open_launcher(self):
 
215
        launcher = self._get_launcher()
 
216
        launcher.show()
 
217
        return launcher
 
218
 
 
219
    def _get_launcher(self):
 
220
        return self.select_single(Launcher)
 
221
 
 
222
    def is_launcher_open(self):
 
223
        return self._get_launcher().shown
 
224
 
 
225
    @autopilot_logging.log_action(logger.info)
 
226
    def launch_application(self, application_name):
 
227
        """Launch an application.
 
228
 
 
229
        :parameter application_name: The name of the application to launch.
 
230
 
 
231
        """
 
232
        launcher = self.open_launcher()
 
233
        launcher.click_application_launcher_icon(application_name)
 
234
        self.get_current_focused_app_id().wait_for(application_name)
 
235
        launcher.shown.wait_for(False)
 
236
 
 
237
    def enter_pin_code(self, code):
 
238
        """Enter code 'code' into the single-pin lightdm pincode entry screen.
 
239
 
 
240
        :param code: must be a string of numeric characters.
 
241
        :raises: TypeError if code is not a string.
 
242
        :raises: ValueError if code contains non-numeric characters.
 
243
 
 
244
        """
 
245
        if not isinstance(code, str):
 
246
            raise TypeError(
 
247
                "'code' parameter must be a string, not %r."
 
248
                % type(code)
 
249
            )
 
250
        for num in code:
 
251
            if not num.isdigit():
 
252
                raise ValueError(
 
253
                    "'code' parameter contains non-numeric characters."
 
254
                )
 
255
            self.pointing_device.click_object(
 
256
                self._get_pinpad_button(int(num)))
 
257
 
 
258
    def _get_pinpad_button(self, button_id):
 
259
        return self.select_single(
 
260
            'PinPadButton',
 
261
            objectName='pinPadButton{}'.format(button_id)
 
262
        )
 
263
 
 
264
    def get_shell_orientation_angle(self):
 
265
        return self._get_shell().orientationAngle
 
266
 
 
267
    def get_shell_orientation(self):
 
268
        return self._get_shell().orientation
 
269
 
 
270
    def get_shell_primary_orientation(self):
 
271
        return self._get_shell().primaryOrientation
 
272
 
 
273
    def get_shell_native_orientation(self):
 
274
        return self._get_shell().nativeOrientation
 
275
 
 
276
    @autopilot_logging.log_action(logger.info)
 
277
    def wait_for_notification(self):
 
278
        """Wait for a notification dialog to appear.
 
279
 
 
280
        :return: An object for the notification dialog data.
 
281
        :raise StateNotFoundError: if the timeout expires when the
 
282
        notification has not appeared.
 
283
 
 
284
        """
 
285
        notify_list = self.select_single('Notifications',
 
286
                                         objectName='notificationList')
 
287
        visible_notification = notify_list.wait_select_single('Notification',
 
288
                                                              visible=True)
 
289
        return {'summary': visible_notification.summary,
 
290
                'body': visible_notification.body,
 
291
                'iconSource': visible_notification.iconSource}
 
292
 
 
293
 
 
294
class Launcher(UbuntuUIToolkitCustomProxyObjectBase):
 
295
 
 
296
    """A helper that understands the Launcher."""
 
297
 
 
298
    def show(self):
 
299
        """Show the launcher swiping it to the right."""
 
300
        if not self.shown:
 
301
            self._swipe_to_show_launcher()
 
302
            self.shown.wait_for(True)
 
303
        else:
 
304
            logger.debug('The launcher is already opened.')
 
305
 
 
306
    def _swipe_to_show_launcher(self):
 
307
        view = self.get_root_instance().select_single('ShellView')
 
308
        start_y = stop_y = view.y + view.height // 2
 
309
 
 
310
        start_x = view.x + 1
 
311
        stop_x = start_x + self.panelWidth - 1
 
312
 
 
313
        self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
 
314
 
 
315
    def click_dash_icon(self):
 
316
        if self.shown:
 
317
            dash_icon = self.select_single(
 
318
                'QQuickImage', objectName='dashItem')
 
319
            self.pointing_device.click_object(dash_icon)
 
320
        else:
 
321
            raise UnityException('The launcher is closed.')
 
322
 
 
323
    def click_application_launcher_icon(self, application_name):
 
324
        launcher_delegate = self.select_single(
 
325
            'LauncherDelegate', appId=application_name)
 
326
        self.pointing_device.click_object(launcher_delegate)