| 1 |
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
| 2 |
# Copyright 2013-2015 Canonical Ltd. |
| 3 |
# |
| 4 |
# This program is free software: you can redistribute it and/or modify it |
| 5 |
# under the terms of the GNU General Public License version 3, as published |
| 6 |
# by the Free Software Foundation. |
| 7 |
import lomiriuitoolkit.emulators |
| 8 |
|
| 9 |
from autopilot.testcase import AutopilotTestCase |
| 10 |
|
| 11 |
from time import sleep |
| 12 |
|
| 13 |
|
| 14 |
class GalleryAppException(Exception): |
| 15 |
pass |
| 16 |
|
| 17 |
|
| 18 |
class GalleryUtils(AutopilotTestCase): |
| 19 |
"""An emulator class that makes it easy to interact with |
| 20 |
general components of the gallery app.""" |
| 21 |
|
| 22 |
retry_delay = 0.2 |
| 23 |
|
| 24 |
def __init__(self, app): |
| 25 |
self.app = app |
| 26 |
self.pointing_device = lomiriuitoolkit.emulators.get_pointing_device() |
| 27 |
|
| 28 |
def select_many_retry(self, object_type, **kwargs): |
| 29 |
"""Returns the item that is searched for with app.select_many |
| 30 |
In case of no item was not found (not created yet) a second attempt is |
| 31 |
taken 1 second later""" |
| 32 |
items = self.app.select_many(object_type, **kwargs) |
| 33 |
tries = 10 |
| 34 |
while len(items) < 1 and tries > 0: |
| 35 |
sleep(self.retry_delay) |
| 36 |
items = self.app.select_many(object_type, **kwargs) |
| 37 |
tries -= 1 |
| 38 |
return items |
| 39 |
|
| 40 |
def get_qml_view(self): |
| 41 |
"""Get the main QML view""" |
| 42 |
return self.app.select_single("QQuickView") |
| 43 |
|
| 44 |
def get_main_photo_viewer_loader(self): |
| 45 |
"""Returns the loader item for the PhotoViewer.""" |
| 46 |
return self.app.select_single("QQuickLoader", |
| 47 |
objectName="photoViewerLoader") |
| 48 |
|
| 49 |
def get_main_photo_viewer(self): |
| 50 |
"""Returns the MediaListView.""" |
| 51 |
return self.app.wait_select_single("MediaListView", |
| 52 |
objectName="mediaListView") |
| 53 |
|
| 54 |
def get_albums_viewer_loader(self): |
| 55 |
"""Returns the loader item for the AlbumsOverview.""" |
| 56 |
return self.app.select_single("QQuickLoader", |
| 57 |
objectName="albumsCheckerboardLoader") |
| 58 |
|
| 59 |
def get_delete_dialog(self): |
| 60 |
"""Returns the delete dialog in the events view.""" |
| 61 |
return self.app.wait_select_single("DeleteDialog", |
| 62 |
objectName="deleteDialog") |
| 63 |
|
| 64 |
def delete_dialog_shown(self): |
| 65 |
dialog = self.app.select_many( |
| 66 |
"DeleteDialog", |
| 67 |
objectName="deleteDialog") |
| 68 |
return len(dialog) >= 1 |
| 69 |
|
| 70 |
def get_delete_dialog_delete_button(self): |
| 71 |
"""Returns the delete button of the delete popover.""" |
| 72 |
return self.app.wait_select_single("Button", |
| 73 |
objectName="deleteDialogYes", |
| 74 |
visible=True) |
| 75 |
|
| 76 |
def get_delete_dialog_cancel_button(self): |
| 77 |
"""Returns the cancel button of the delete popover.""" |
| 78 |
return self.app.wait_select_single("Button", |
| 79 |
objectName="deleteDialogNo", |
| 80 |
visible=True) |
| 81 |
|
| 82 |
def get_all_albums(self): |
| 83 |
"""Returns all albums in the albums view""" |
| 84 |
albums = self.select_many_retry("CheckerboardDelegate", |
| 85 |
objectName="checkerboardDelegate") |
| 86 |
return albums |
| 87 |
|
| 88 |
def get_first_album(self): |
| 89 |
"""Returns the first album in the albums view.""" |
| 90 |
return self.get_album_at(0) |
| 91 |
|
| 92 |
def get_album_at(self, position): |
| 93 |
"""Returns the albums at this position in the albums view""" |
| 94 |
albums = self.select_many_retry("CheckerboardDelegate", |
| 95 |
objectName="checkerboardDelegate") |
| 96 |
albums = sorted( |
| 97 |
albums, key=lambda album: (album.globalRect.y, album.globalRect.x)) |
| 98 |
return albums[position] |
| 99 |
|
| 100 |
def get_edit_album_button(self): |
| 101 |
"""Returns the edit album button in the album popover""" |
| 102 |
return self.app.select_single("Standard", |
| 103 |
objectName="editAlbumListItem") |
| 104 |
|
| 105 |
def get_cover_menu_item(self, name): |
| 106 |
"""Returns the item of the cover menu with the name *name* |
| 107 |
|
| 108 |
:raises StateNotFoundError: if there is no item with the name *name* |
| 109 |
|
| 110 |
""" |
| 111 |
return self.app.select_single( |
| 112 |
"Standard", |
| 113 |
objectName="albumCoverMenuItem_" + name |
| 114 |
) |
| 115 |
|
| 116 |
def _ensure_delete_dialog_visible(self): |
| 117 |
delete_dialog = self.get_delete_dialog() |
| 118 |
delete_dialog.opacity.wait_for(1) |
| 119 |
|
| 120 |
def _click_dialog_button(self, button): |
| 121 |
self._ensure_delete_dialog_visible() |
| 122 |
self.pointing_device.click_object(button) |
| 123 |
|
| 124 |
def click_delete_dialog_cancel_button(self): |
| 125 |
button = self.get_delete_dialog_cancel_button() |
| 126 |
self._click_dialog_button(button) |
| 127 |
|
| 128 |
def click_delete_dialog_delete_button(self): |
| 129 |
button = self.get_delete_dialog_delete_button() |
| 130 |
self._click_dialog_button(button) |