on xenial help sign in
Added app scope helpers for autopilot tests.
commit61477c90776f8e954d9836297fb482188a6b38b8 authorLeo Arias <leo.arias@canonical.com> dateWed 15 Jan 2014, 00:32 (13 years ago) parent7acc541
3 files changed+82−2
qml/Dash/Apps/AppPreview.qml+1 tests/autopilot/unity8/shell/emulators/dash.py+50−2 tests/autopilot/unity8/shell/tests/test_emulators.py+31
qml/Dash/Apps/AppPreview.qml+1
@@ -97,6 +97,7 @@ GenericPreview {
9797 spacing: units.gu(1)
9898
9999 Label {
100+ objectName: "descriptionLabel"
100101 anchors { left: parent.left; right: parent.right }
101102 text: root.previewData.description
102103 fontSize: "medium"
tests/autopilot/unity8/shell/emulators/dash.py+50−2
@@ -138,8 +138,56 @@ class Dash(emulators.UnityEmulatorBase):
138138
139139
140140class GenericScopeView(emulators.UnityEmulatorBase):
141− """Autopilot emulators for generic scopes."""
141+ """Autopilot emulator for generic scopes."""
142142
143143
144144class DashApps(emulators.UnityEmulatorBase):
145− """Autopilot emulators for the applications scope."""
145+ """Autopilot emulator for the applications scope."""
146+
147+ def get_applications(self, category):
148+ """Return the list of applications on a category.
149+
150+ :parameter category: The name of the category.
151+
152+ """
153+ category_element = self._get_category_element(category)
154+ application_tiles = category_element.select_many('Tile')
155+ return [tile.text for tile in application_tiles]
156+
157+ def _get_category_element(self, category):
158+ try:
159+ return self.select_single(
160+ 'Base', objectName='dashCategory{}'.format(category))
161+ except dbus.StateNotFoundError:
162+ raise emulators.UnityEmulatorException(
163+ 'No category found with name {}'.format(category))
164+
165+ @autopilot_logging.log_action(logger.info)
166+ def open_preview(self, category, app_name):
167+ """Open the preview of an application.
168+
169+ :parameter category: The name of the category where the application is.
170+ :app_name: The name of the application.
171+
172+ """
173+ category_element = self._get_category_element(category)
174+ icon = category_element.select_single('Tile', text=app_name)
175+ # FIXME some categories need a long press in order to see the preview. # Some categories no not show previews, like recent apps.
176+ # --elopio - 2014-1-14
177+ self.pointing_device.click_object(icon)
178+ return self.get_root_instance.select_single(AppPreview)
179+
180+
181+class AppPreview(emulators.UnityEmulatorBase):
182+ """Autopilot emulator for the application preview."""
183+
184+ def get_details(self):
185+ """Return the details of the application showed in its preview."""
186+ title = self.select_single('Label', objectName='titleLabel').text
187+ publisher = self.select_single(
188+ 'Label', objectName='subtitleLabel').text
189+ description = self.select_single(
190+ 'Label', objectName='descriptionLabel').text
191+ # TODO return screenshots, icon, rating and reviews.
192+ # --elopio - 2014-1-15
193+ return dict(title=title, publisher=publisher, description=description)
tests/autopilot/unity8/shell/tests/test_emulators.py+31
@@ -118,3 +118,34 @@ class DashEmulatorTestCase(tests.UnityTestCase):
118118 scope = self.dash.open_scope(self._get_scope_name_from_id(scope_id))
119119 self._assert_scope_is_opened(scope, scope_id)
120120 self.assertIsInstance(scope, dash_emulators.DashApps)
121+
122+
123+class DashAppsEmulatorTestCase(tests.UnityTestCase):
124+
125+ scenarios = tests._get_device_emulation_scenarios()
126+
127+ def setUp(self):
128+ super(DashAppsEmulatorTestCase, self).setUp()
129+ unity_proxy = self.launch_unity()
130+ process_helpers.unlock_unity(unity_proxy)
131+ self.dash = self.main_window.get_dash()
132+ self.applications_scope = self.dash.open_scope('applications')
133+
134+ def test_get_applications_with_unexisting_category(self):
135+ exception = self.assertRaises(
136+ emulators.UnityEmulatorException,
137+ self.applications_scope.get_applications,
138+ 'unexisting category')
139+
140+ self.assertEqual(
141+ 'No category found with name unexisting category', str(exception))
142+
143+ def test_get_applications_should_return_list_with_names(self):
144+ # FIXME The installed category comes from the scope click. This is the
145+ # wrong way to test this emulator, because it shouldn't depend on the
146+ # current implementation of the click scope. There can be many other
147+ # scopes using DashApps as a base. In addition to this, we can't
148+ # actually check the values returned, as they depend on the server that
149+ # the click scope uses. What we need is to open a scope with hardcoded
150+ # categories and values.
151+ applications = self.applications_scope.get_applications('installed')