diff options
| author | Thomi Richards <thomi.richards@canonical.com> | 2012-07-11 12:18:25 +1200 |
|---|---|---|
| committer | Thomi Richards <thomi.richards@canonical.com> | 2012-07-11 12:18:25 +1200 |
| commit | f110e110e4d03360c9995cd7bbf8e51fc336c266 (patch) | |
| tree | 40139f8e9e915c4ddbcaf80d53bede783dbed4af /tests/autopilot | |
| parent | 43038271bfe178100a6da2ac7d64404430cbab3f (diff) | |
A couple of quicklist test changes, and added the new get_icon method to the launcher mode.
(bzr r2487.1.2)
Diffstat (limited to 'tests/autopilot')
| -rw-r--r-- | tests/autopilot/unity/emulators/launcher.py | 36 | ||||
| -rw-r--r-- | tests/autopilot/unity/tests/test_quicklist.py | 11 |
2 files changed, 39 insertions, 8 deletions
diff --git a/tests/autopilot/unity/emulators/launcher.py b/tests/autopilot/unity/emulators/launcher.py index a0742df20..425ca9049 100644 --- a/tests/autopilot/unity/emulators/launcher.py +++ b/tests/autopilot/unity/emulators/launcher.py @@ -428,7 +428,7 @@ class Launcher(UnityIntrospectionObject, KeybindingsHelper): class LauncherModel(UnityIntrospectionObject): - """THe launcher model. Contains all launcher icons as children.""" + """The launcher model. Contains all launcher icons as children.""" def get_bfb_icon(self): icons = BFBLauncherIcon.get_all_instances() @@ -500,6 +500,40 @@ class LauncherModel(UnityIntrospectionObject): """ return self.get_children_by_type(SimpleLauncherIcon, **kwargs) + def get_icon(self, **kwargs): + """Get a launcher icon from the model according to some filters. + + This method accepts keyword argument that are the filters to use when + looking for an icon. For example, to find an icon with a particular + desktop_id, one might do this from within a test: + + >>> self.launcher.model.get_icon(desktop_id="gcalctool.desktop") + + This method returns only one icon. It is the callers responsibility to + ensure that the filter matches only one icon. + + This method will attempt to get the launcher icon using the Eventually + matcher, so the caller can be assured that if this method doesn't find + the icon it really does not exist. + + If no keyword arguments are specified, ValueError will be raised. + + If no icons are matched, None is returned. + + """ + + if not kwargs: + raise ValueError("You must specify at least one keyword argument to ths method.") + + for i in range(10): + icons = self.get_children_by_type(SimpleLauncherIcon, **kwargs) + if len(icons) > 1: + logger.warning("Got more than one icon returned using filters=%r. Returning first one", kwargs) + if icons: + return icons[0] + sleep(1) + return None + def num_launcher_icons(self): """Get the number of icons in the launcher model.""" return len(self.get_launcher_icons()) diff --git a/tests/autopilot/unity/tests/test_quicklist.py b/tests/autopilot/unity/tests/test_quicklist.py index 8db03e056..6ac069cc1 100644 --- a/tests/autopilot/unity/tests/test_quicklist.py +++ b/tests/autopilot/unity/tests/test_quicklist.py @@ -35,11 +35,8 @@ class QuicklistActionTests(UnityTestCase): launcher = self.launcher.get_launcher_for_monitor(0) launcher.click_launcher_icon(launcher_icon, button=3) self.addCleanup(self.keyboard.press_and_release, "Escape") - for i in range(10): - ql = launcher_icon.get_quicklist() - if ql: - return ql - sleep(1) + self.assertThat(launcher_icon.get_quicklist, Eventually(NotEquals(None))) + return launcher_icon.get_quicklist() def test_quicklist_actions(self): """Test that all actions present in the destop file are shown in the quicklist.""" @@ -144,8 +141,8 @@ class QuicklistKeyNavigationTests(UnityTestCase): self.ql_app = self.start_app("Text Editor") - self.ql_launcher_icon = self.launcher.model.get_icon_by_desktop_id( - self.ql_app.desktop_file) + self.ql_launcher_icon = self.launcher.model.get_icon( + desktop_id=self.ql_app.desktop_file) self.assertThat(self.ql_launcher_icon, NotEquals(None)) self.ql_launcher = self.launcher.get_launcher_for_monitor(0) |
