| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
import logging |
| 9 |
import re |
| 10 |
|
| 11 |
from testtools.matchers import GreaterThan, LessThan, Equals, Is |
| 12 |
from autopilot.matchers import Eventually |
| 13 |
|
| 14 |
from autopilot.introspection.dbus import StateNotFoundError |
| 15 |
from autopilot import logging as autopilot_logging |
| 16 |
|
| 17 |
from lomiri_gallery_app.emulators.gallery_utils import( |
| 18 |
GalleryUtils, |
| 19 |
GalleryAppException, |
| 20 |
) |
| 21 |
|
| 22 |
logger = logging.getLogger(__name__) |
| 23 |
|
| 24 |
|
| 25 |
class AlbumView(GalleryUtils): |
| 26 |
"""An emulator class that makes it easy to interact with the gallery app""" |
| 27 |
|
| 28 |
def __init__(self, app): |
| 29 |
super(AlbumView, self).__init__(self) |
| 30 |
self.app = app |
| 31 |
|
| 32 |
def get_animated_album_view(self): |
| 33 |
"""Returns the album view""" |
| 34 |
return self.app.wait_select_single("AlbumViewerAnimated", |
| 35 |
objectName="albumViewerAnimated") |
| 36 |
|
| 37 |
def get_album_view(self): |
| 38 |
"""Returns the album view""" |
| 39 |
return self.app.wait_select_single("AlbumViewer", |
| 40 |
objectName="albumViewer") |
| 41 |
|
| 42 |
def get_first_photo(self): |
| 43 |
"""Returns the first photo in a newly opened album""" |
| 44 |
return self.app.select_many( |
| 45 |
"FramePortrait", visible=True, isLoaded=True)[0] |
| 46 |
|
| 47 |
def get_album_photo_view(self): |
| 48 |
"""Returns the photo view of the album viewer""" |
| 49 |
return self.app.select_single("PopupPhotoViewer") |
| 50 |
|
| 51 |
def get_spread_view(self): |
| 52 |
"""Returns the inner spread view to access the pages""" |
| 53 |
view = self.get_album_view() |
| 54 |
return view.select_single( |
| 55 |
"AlbumSpreadViewer", |
| 56 |
objectName="spreadViewer" |
| 57 |
) |
| 58 |
|
| 59 |
def number_of_photos(self): |
| 60 |
"""Returns the numer of visible photos""" |
| 61 |
return len(self.app.select_many("FramePortrait", |
| 62 |
visible=True, isLoaded=True)) |
| 63 |
|
| 64 |
def media_selector_loader(self): |
| 65 |
"""Returns the loader for the media selector""" |
| 66 |
return self.app.select_single("QQuickLoader", |
| 67 |
objectName="albumMediaSelectorLoader") |
| 68 |
|
| 69 |
def get_plus_icon_empty_album(self): |
| 70 |
"""Returns the plus icon visible in empty albums""" |
| 71 |
return self.app.select_single("QQuickImage", |
| 72 |
objectName="albumCoverAddPhotosImage", |
| 73 |
visible=True) |
| 74 |
|
| 75 |
def ensure_animated_fully_closed(self): |
| 76 |
"""Ensure the animated album view is fully closed""" |
| 77 |
animated_viewer = self.get_animated_album_view() |
| 78 |
animated_viewer.isOpen.wait_for(False) |
| 79 |
animated_viewer.animationRunning.wait_for(False) |
| 80 |
|
| 81 |
def ensure_album_view_fully_closed(self): |
| 82 |
"""Ensure the album view is fully closed""" |
| 83 |
view = self.get_album_view() |
| 84 |
view.visible.wait_for(False) |
| 85 |
|
| 86 |
def ensure_media_selector_is_fully_closed(self): |
| 87 |
"""Ensure media selector is fully closed""" |
| 88 |
loader = self.media_selector_loader() |
| 89 |
loader.status.wait_for(0) |
| 90 |
|
| 91 |
def _swipe_setup(self, page_number, direction): |
| 92 |
self.album = self.get_album_view() |
| 93 |
self.spread = self.get_spread_view() |
| 94 |
self.album.animationRunning.wait_for(False) |
| 95 |
|
| 96 |
x, y, w, h = self.spread.globalRect |
| 97 |
mid_y = y + h // 2 |
| 98 |
mid_x = x + w // 2 |
| 99 |
|
| 100 |
if 'left' == direction: |
| 101 |
matcher = LessThan |
| 102 |
self.pointing_device.drag( |
| 103 |
mid_x, mid_y, |
| 104 |
x + w, mid_y, |
| 105 |
rate=1 |
| 106 |
) |
| 107 |
|
| 108 |
elif 'right' == direction: |
| 109 |
matcher = GreaterThan |
| 110 |
self.pointing_device.drag( |
| 111 |
mid_x, mid_y, |
| 112 |
x, mid_y, |
| 113 |
rate=1 |
| 114 |
) |
| 115 |
else: |
| 116 |
raise GalleryAppException( |
| 117 |
'Direction can be "right" or "left" ' |
| 118 |
'you choose "{}"'.format(direction)) |
| 119 |
|
| 120 |
self.album.animationRunning.wait_for(False) |
| 121 |
self.spread.viewingPage.wait_for(matcher(page_number)) |
| 122 |
|
| 123 |
def swipe_page_left(self, page_number): |
| 124 |
'''Swipe page to the left |
| 125 |
|
| 126 |
:param page_number: The starting page number you are swiping from |
| 127 |
''' |
| 128 |
self._swipe_setup(page_number, 'left') |
| 129 |
|
| 130 |
def swipe_page_right(self, page_number): |
| 131 |
'''Swipe page to the right |
| 132 |
|
| 133 |
:param page_number: The starting page number you are swiping from |
| 134 |
''' |
| 135 |
self._swipe_setup(page_number, 'right') |
| 136 |
|
| 137 |
def _get_remove_from_album_dialog(self): |
| 138 |
"""Returns the photo viewer remove from album dialog.""" |
| 139 |
return self.app.wait_select_single( |
| 140 |
"Dialog", |
| 141 |
objectName="removePhotoFromAlbumDialog") |
| 142 |
|
| 143 |
def _remove_from_album_dialog_shown(self): |
| 144 |
dialog = self.app.select_many("Dialog", |
| 145 |
objectName="removePhotoFromAlbumDialog") |
| 146 |
return len(dialog) >= 1 |
| 147 |
|
| 148 |
def _get_remove_from_album_popover_remove_item(self): |
| 149 |
"""Returns remove button of the remove from album popover.""" |
| 150 |
return self.app.wait_select_single("Button", |
| 151 |
objectName="removeFromAlbumButton", |
| 152 |
visible=True) |
| 153 |
|
| 154 |
def _get_remove_from_album_popover_delete_item(self): |
| 155 |
"""Returns delete button of the remove from album popover.""" |
| 156 |
return self.app.wait_select_single( |
| 157 |
"Button", |
| 158 |
objectName="removeFromAlbumAndDeleteButton", |
| 159 |
visible=True) |
| 160 |
|
| 161 |
def _get_remove_from_album_popover_cancel_item(self): |
| 162 |
"""Returns cancel button of the remove from album popover.""" |
| 163 |
return self.app.wait_select_single( |
| 164 |
"Button", |
| 165 |
objectName="removeFromAlbumCancelButton", |
| 166 |
visible=True) |
| 167 |
|
| 168 |
def _ensure_remove_from_album_dialog_is_open(self): |
| 169 |
"""Ensure that the remove from album dialog is fully opened.""" |
| 170 |
self.assertThat(self._remove_from_album_dialog_shown, |
| 171 |
Eventually(Is(True))) |
| 172 |
remove_dialog = self._get_remove_from_album_dialog() |
| 173 |
self.assertThat(remove_dialog.visible, Eventually(Equals(True))) |
| 174 |
self.assertThat(remove_dialog.opacity, Eventually(Equals(1))) |
| 175 |
|
| 176 |
def _ensure_remove_from_album_dialog_is_close(self): |
| 177 |
"""Ensure that the remove from album dialog is fully closed.""" |
| 178 |
self.assertThat(self._remove_from_album_dialog_shown, |
| 179 |
Eventually(Is(False))) |
| 180 |
|
| 181 |
@autopilot_logging.log_action(logger.info) |
| 182 |
def click_remove_from_album_remove_button(self): |
| 183 |
"""Click on the remove from album button of the remove dialog.""" |
| 184 |
self._ensure_remove_from_album_dialog_is_open() |
| 185 |
|
| 186 |
remove_item = self._get_remove_from_album_popover_remove_item() |
| 187 |
self.pointing_device.click_object(remove_item) |
| 188 |
|
| 189 |
self._ensure_remove_from_album_dialog_is_close() |
| 190 |
|
| 191 |
@autopilot_logging.log_action(logger.info) |
| 192 |
def click_remove_from_album_delete_button(self): |
| 193 |
"""Click on the remove and delete of the remove dialog.""" |
| 194 |
self._ensure_remove_from_album_dialog_is_open() |
| 195 |
|
| 196 |
delete_item = self._get_remove_from_album_popover_delete_item() |
| 197 |
self.pointing_device.click_object(delete_item) |
| 198 |
|
| 199 |
self._ensure_remove_from_album_dialog_is_close() |
| 200 |
|
| 201 |
@autopilot_logging.log_action(logger.info) |
| 202 |
def click_remove_from_album_cancel_button(self): |
| 203 |
"""Click on the cancel of the remove dialog.""" |
| 204 |
self._ensure_remove_from_album_dialog_is_open() |
| 205 |
|
| 206 |
cancel_item = self._get_remove_from_album_popover_cancel_item() |
| 207 |
self.pointing_device.click_object(cancel_item) |
| 208 |
|
| 209 |
self._ensure_remove_from_album_dialog_is_close() |
| 210 |
|
| 211 |
@autopilot_logging.log_action(logger.info) |
| 212 |
def click_first_photo(self): |
| 213 |
"""Click on the first photo of the album and return the path of it.""" |
| 214 |
photo = self.get_first_photo() |
| 215 |
images = photo.select_many('QQuickImage') |
| 216 |
path = '' |
| 217 |
for i in images: |
| 218 |
if str(i.source).startswith('image://thumbnailer/file://'): |
| 219 |
path = re.sub('^image://thumbnailer/file://', '', |
| 220 |
i.source).split('?')[0] |
| 221 |
self.pointing_device.click_object(photo) |
| 222 |
return path |
| 223 |
|
| 224 |
def _get_header(self): |
| 225 |
return self.app.select_single('PageHeader', |
| 226 |
objectName='albumViewerHeader') |
| 227 |
|
| 228 |
def _open_overflow(self): |
| 229 |
overflow_button = self._get_header().select_single( |
| 230 |
objectName='overflow_action_button') |
| 231 |
self.pointing_device.click_object(overflow_button) |
| 232 |
return self.get_root_instance().wait_select_single( |
| 233 |
objectName='actions_overflow_panel', |
| 234 |
visible=True) |
| 235 |
|
| 236 |
def click_action_button(self, action_object_name): |
| 237 |
header = self._get_header() |
| 238 |
header.visible.wait_for(True) |
| 239 |
|
| 240 |
try: |
| 241 |
object_name = action_object_name + "_button" |
| 242 |
button = header.select_single(objectName=object_name) |
| 243 |
self.pointing_device.click_object(button) |
| 244 |
except StateNotFoundError: |
| 245 |
object_name = action_object_name + "_button" |
| 246 |
popover = self._open_overflow() |
| 247 |
button = popover.select_single(objectName=object_name) |
| 248 |
self.pointing_device.click_object(button) |