24 from autopilot
import logging
as autopilot_logging
25 from autopilot.introspection
import dbus
26 from testtools.matchers
import MatchesAny, Equals
27 from ubuntuuitoolkit
import emulators
as toolkit_emulators
30 logger = logging.getLogger(__name__)
34 """An emulator that understands the Dash."""
39 'QQuickListView', objectName=
'dashContentList')
41 def get_applications_grid(self):
42 get_grid = self.
get_scope(
'clickscope').wait_select_single(
43 'CardFilterGrid', objectName=
'local')
47 """Returns a 'Tile' icon that has the text 'text' from the application
50 :param text: String containing the text of the icon to search for.
54 resp_grid = app_grid.wait_select_single(
'ResponsiveGridView')
55 return resp_grid.select_single(
'Tile', text=text)
57 def get_scope(self, scope_name='clickscope'):
58 return self.dash_content_list.select_single(
59 'QQuickLoader', scopeId=scope_name)
61 @autopilot_logging.log_action(logger.info)
65 :parameter scope_id: The id of the scope.
70 if scope_loader.isCurrent:
71 logger.info(
'The scope is already open.')
76 def _get_scope_loader(self, scope_id):
78 return self.dash_content_list.select_single(
79 'QQuickLoader', scopeId=scope_id)
80 except dbus.StateNotFoundError:
82 'No scope found with id {0}'.format(scope_id))
84 def _get_scope_from_loader(self, loader):
85 return loader.get_children()[0]
87 def _open_scope_scrolling(self, scope_loader):
90 while not scope_loader.isCurrent:
92 self.dash_content_list.moving.wait_for(
False)
95 scope.isCurrent.wait_for(
True)
98 def _get_scroll_direction(self, scope_loader):
99 current_scope_loader = self.dash_content_list.select_single(
100 'QQuickLoader', isCurrent=
True)
101 if scope_loader.globalRect.x < current_scope_loader.globalRect.x:
103 elif scope_loader.globalRect.x > current_scope_loader.globalRect.x:
108 @autopilot_logging.log_action(logger.info)
109 def _scroll_to_left_scope(self):
110 original_index = self.dash_content_list.currentIndex
111 dashContent = self.select_single(objectName=
"dashContent")
112 start_x = dashContent.width / 3
113 stop_x = dashContent.width / 3 * 2
114 start_y = stop_y = dashContent.globalRect.y + 1
115 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
116 self.dash_content_list.currentIndex.wait_for(original_index - 1)
118 @autopilot_logging.log_action(logger.info)
119 def _scroll_to_right_scope(self):
120 original_index = self.dash_content_list.currentIndex
121 dashContent = self.select_single(objectName=
"dashContent")
122 start_x = dashContent.width / 3 * 2
123 stop_x = dashContent.width / 3
124 start_y = stop_y = dashContent.globalRect.y + 1
125 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
126 self.dash_content_list.currentIndex.wait_for(original_index + 1)
128 def enter_search_query(self, query):
130 self.pointing_device.move(current_header.globalRect.x +
131 current_header.width - current_header.height / 2,
132 current_header.globalRect.y +
133 current_header.height / 2)
134 self.pointing_device.click()
135 headerContainer = current_header.select_single(objectName=
"headerContainer")
136 headerContainer.contentY.wait_for(0)
138 search_text_field.write(query)
139 current_header.select_single(objectName=
"searchIndicator").running.wait_for(
False)
141 def _get_search_text_field(self):
143 return page_header.select_single(objectName=
'searchTextField')
145 def _get_current_page_header(self):
146 dashContentList = self.select_single(objectName=
"dashContentList")
147 all_headers = dashContentList.select_many(
"QQuickLoader")
148 for i
in all_headers:
150 return i.select_single(objectName=
"scopePageHeader")
155 """Autopilot emulator for generic scopes."""
157 @autopilot_logging.log_action(logger.info)
159 """Open the preview of an application.
161 :parameter category: The name of the category where the application is.
162 :app_name: The name of the application.
163 :return: The opened preview.
167 icon = category_element.select_single(
'AbstractButton', title=app_name)
171 self.pointing_device.click_object(icon)
172 preview_list = self.wait_select_single(
173 'PreviewListView', objectName=
'previewListView')
174 preview_list.x.wait_for(0)
175 return preview_list.select_single(
176 Preview, objectName=
'preview{}'.format(preview_list.currentIndex))
178 def _get_category_element(self, category):
180 return self.wait_select_single(
181 'Base', objectName=
'dashCategory{}'.format(category))
182 except dbus.StateNotFoundError:
184 'No category found with name {}'.format(category))
188 """Autopilot emulator for the applications scope."""
191 """Return the list of applications on a category.
193 :parameter category: The name of the category.
197 application_cards = category_element.select_many(
'AbstractButton')
200 application_cards = sorted(
202 key=
lambda card: (card.globalRect.y, card.globalRect.x))
205 for card
in application_cards:
206 if card.objectName !=
'cardToolCard':
207 result.append(card.title)
212 """Autopilot custom proxy object for generic previews."""
def _scroll_to_right_scope
def get_applications_grid
def _scroll_to_left_scope
def _get_category_element
def _get_scroll_direction
def _get_current_page_header
def _open_scope_scrolling
def _get_search_text_field
def _get_scope_from_loader