diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2015-08-18 16:38:50 +0200 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2015-08-18 16:38:50 +0200 |
| commit | fe67f4d0b487892cb9168669bfc24715d5bc2b4a (patch) | |
| tree | 4fb4a418275912eb98639a52427a5e6d3af5cc15 /tests/autopilot | |
| parent | 76023b102ffb77a8a4bb721bb6024216803205ac (diff) | |
Autopilot: use some new facilities to move and click over items
(bzr r3987.1.4)
Diffstat (limited to 'tests/autopilot')
| -rw-r--r-- | tests/autopilot/unity/emulators/dash.py | 48 | ||||
| -rw-r--r-- | tests/autopilot/unity/emulators/launcher.py | 6 | ||||
| -rw-r--r-- | tests/autopilot/unity/emulators/panel.py | 38 | ||||
| -rw-r--r-- | tests/autopilot/unity/emulators/quicklist.py | 7 | ||||
| -rw-r--r-- | tests/autopilot/unity/tests/launcher/test_visual.py | 4 | ||||
| -rw-r--r-- | tests/autopilot/unity/tests/test_dash.py | 197 | ||||
| -rw-r--r-- | tests/autopilot/unity/tests/test_panel.py | 11 |
7 files changed, 53 insertions, 258 deletions
diff --git a/tests/autopilot/unity/emulators/dash.py b/tests/autopilot/unity/emulators/dash.py index 484baaec4..12b7a452c 100644 --- a/tests/autopilot/unity/emulators/dash.py +++ b/tests/autopilot/unity/emulators/dash.py @@ -274,26 +274,16 @@ class Result(UnityIntrospectionObject): """A single result in the dash.""" def activate(self, double_click=True): - tx = self.x + (self.width / 2) - ty = self.y + (self.height / 2) m = Mouse.create() - m.move(tx, ty) - m.click(1) + m.click_object(self, button=1) if double_click: - m.click(1) + m.click_object(self, button=1) def preview(self, button=1): - tx = self.x + (self.width / 2) - ty = self.y + (self.height / 2) - m = Mouse.create() - m.move(tx, ty) - m.click(button) + Mouse.create().click_object(self, button) def preview_key(self): - tx = self.x + (self.width / 2) - ty = self.y + (self.height / 2) - m = Mouse.create() - m.move(tx, ty) + Mouse.create().move_to_object(self) k = Keyboard.create() k.press_and_release('Menu') @@ -358,21 +348,13 @@ class FilterExpanderLabel(UnityIntrospectionObject): def ensure_expanded(self): """Expand the filter expander label, if it's not already""" if not self.expanded: - tx = self.x + self.width / 2 - ty = self.y + self.height / 2 - m = Mouse.create() - m.move(tx, ty) - m.click() + Mouse.create().click_object(self) self.expanded.wait_for(True) def ensure_collapsed(self): """Collapse the filter expander label, if it's not already""" if self.expanded: - tx = self.x + self.width / 2 - ty = self.y + self.height / 2 - m = Mouse.create() - m.move(tx, ty) - m.click() + Mouse.create().click_object(self) self.expanded.wait_for(False) @@ -401,11 +383,7 @@ class Preview(UnityIntrospectionObject): """Executes an action given by the id.""" action = self.get_action_by_id(action_id) if action: - tx = action.x + (action.width / 2) - ty = action.y + (action.height / 2) - m = Mouse.create() - m.move(tx, ty) - m.click() + Mouse.create().click_object(action) @property def cover_art(self): @@ -484,12 +462,8 @@ class PreviewContainer(UnityIntrospectionObject): def navigate_left(self, count=1): """Navigate preview left""" - navigator = self.get_left_navigator() - - tx = navigator.button_x + (navigator.button_width / 2) - ty = navigator.button_y + (navigator.button_height / 2) m = Mouse.create() - m.move(tx, ty) + m.move_to_object(self.get_left_navigator()) old_preview_initiate_count = self.preview_initiate_count @@ -501,12 +475,8 @@ class PreviewContainer(UnityIntrospectionObject): def navigate_right(self, count=1): """Navigate preview right""" - navigator = self.get_right_navigator() - - tx = navigator.button_x + (navigator.button_width / 2) - ty = navigator.button_y + (navigator.button_height / 2) m = Mouse.create() - m.move(tx, ty) + m.move_to_object(self.get_right_navigator()) old_preview_initiate_count = self.preview_initiate_count diff --git a/tests/autopilot/unity/emulators/launcher.py b/tests/autopilot/unity/emulators/launcher.py index 5deb2fa18..03415bbeb 100644 --- a/tests/autopilot/unity/emulators/launcher.py +++ b/tests/autopilot/unity/emulators/launcher.py @@ -118,12 +118,8 @@ class Launcher(UnityIntrospectionObject, KeybindingsHelper): def move_mouse_over_launcher(self): """Move the mouse over this launcher.""" move_mouse_to_screen(self.monitor) - (x, y, w, h) = self.geometry - target_x = x + w / 2 - target_y = y + h / 2 - logger.debug("Moving mouse to center of launcher.") - self._mouse.move(target_x, target_y) + self._mouse.move_to_object(self) def move_mouse_to_icon(self, icon, autoscroll_offset=0): """Move the mouse to a specific icon.""" diff --git a/tests/autopilot/unity/emulators/panel.py b/tests/autopilot/unity/emulators/panel.py index 28f80d710..9fc32d100 100644 --- a/tests/autopilot/unity/emulators/panel.py +++ b/tests/autopilot/unity/emulators/panel.py @@ -107,30 +107,18 @@ class UnityPanel(UnityIntrospectionObject, KeybindingsHelper): def move_mouse_over_grab_area(self): """Move the mouse over the grab area for this panel.""" - (x, y, w, h) = self.grab_area.geometry - target_x = x + w / 2 - target_y = y + h / 2 - logger.debug("Moving mouse to center of grab area.") - self._mouse.move(target_x, target_y) + self._mouse.move_to_object(self.grab_area) def move_mouse_over_window_buttons(self): """Move the mouse over the center of the window buttons area for this panel.""" - (x, y, w, h) = self.window_buttons.geometry - target_x = x + w / 2 - target_y = y + h / 2 - logger.debug("Moving mouse to center of the window buttons.") - self._mouse.move(target_x, target_y) + self._mouse.move_to_object(self.window_buttons) def move_mouse_over_indicators(self): """Move the mouse over the center of the indicators area for this panel.""" - (x, y, w, h) = self.indicators.geometry - target_x = x + w / 2 - target_y = y + h / 2 - logger.debug("Moving mouse to center of the indicators area.") - self._mouse.move(target_x, target_y) + self._mouse.move_to_object(self.indicators) def get_indicator_entries(self, visible_only=True, include_hidden_menus=False): """Returns a list of entries for this panel including both menus and indicators""" @@ -268,15 +256,12 @@ class WindowButton(UnityIntrospectionObject): self._mouse = Mouse.create() def mouse_move_to(self): - target_x = self.x + self.width / 2 - target_y = self.y + self.height / 2 - self._mouse.move(target_x, target_y, rate=20, time_between_events=0.005) + self._mouse.move_to_object(self) def mouse_click(self): - self.mouse_move_to() - sleep(.2) - self._mouse.click(press_duration=.1) - sleep(.01) + if self.sensitive: + self._mouse.click_object(self) + sleep(.01) @property def geometry(self): @@ -331,15 +316,10 @@ class IndicatorEntry(UnityIntrospectionObject): self._mouse = Mouse.create() def mouse_move_to(self): - target_x = self.x + self.width / 2 - target_y = self.y + self.height / 2 - self._mouse.move(target_x, target_y, rate=20, time_between_events=0.005) + self._mouse.move_to_object(self) def mouse_click(self, button=1): - self.mouse_move_to() - sleep(.2) - assert(self.visible) - self._mouse.click(press_duration=.1) + self._mouse.click_object(self, button=button) sleep(.01) @property diff --git a/tests/autopilot/unity/emulators/quicklist.py b/tests/autopilot/unity/emulators/quicklist.py index a3e522600..e3aa994df 100644 --- a/tests/autopilot/unity/emulators/quicklist.py +++ b/tests/autopilot/unity/emulators/quicklist.py @@ -85,14 +85,11 @@ class QuicklistMenuItem(UnityIntrospectionObject): def mouse_move_to(self): assert(self.visible) logger.debug("Moving mouse over quicklist item %r", self) - target_x = self.x + self.width / 2 - target_y = self.y + self.height / 2 - self._mouse.move(target_x, target_y, rate=20, time_between_events=0.005) + self._mouse.move_to_object(self) def mouse_click(self, button=1): logger.debug("Clicking on quicklist item %r", self) - self.mouse_move_to() - self._mouse.click() + self._mouse.click_object(self) class QuicklistMenuItemLabel(QuicklistMenuItem): diff --git a/tests/autopilot/unity/tests/launcher/test_visual.py b/tests/autopilot/unity/tests/launcher/test_visual.py index f7dc8b5b5..c44e9237d 100644 --- a/tests/autopilot/unity/tests/launcher/test_visual.py +++ b/tests/autopilot/unity/tests/launcher/test_visual.py @@ -71,14 +71,12 @@ class LauncherVisualTests(LauncherTestCase): def test_mouse_over_with_dash_open_desaturates_icons(self): """Moving mouse over launcher with dash open must saturate icons.""" - launcher_instance = self.get_launcher() self.unity.dash.ensure_visible() current_monitor = self.unity.dash.monitor self.addCleanup(self.unity.dash.ensure_hidden) sleep(.5) - x,y,w,h = launcher_instance.geometry - self.mouse.move(x + w/2, y + h/2) + self.mouse.move_to_object(self.get_launcher()) sleep(.5) for icon in self.unity.launcher.model.get_launcher_icons(): self.assertFalse(icon.monitors_desaturated[current_monitor]) diff --git a/tests/autopilot/unity/tests/test_dash.py b/tests/autopilot/unity/tests/test_dash.py index 27dc0a391..b2befa799 100644 --- a/tests/autopilot/unity/tests/test_dash.py +++ b/tests/autopilot/unity/tests/test_dash.py @@ -545,10 +545,7 @@ class DashClipboardTests(DashTestCase): self.unity.dash.ensure_visible() - self.mouse.move(self.unity.dash.searchbar.x + self.unity.dash.searchbar.width / 2, - self.unity.dash.searchbar.y + self.unity.dash.searchbar.height / 2) - - self.mouse.click(button=2) + self.mouse.click_object(self.unity.dash.searchbar, button=2) self.assertThat(self.unity.dash.search_string, Eventually(Equals('ThirdButtonPaste'))) @@ -724,10 +721,7 @@ class DashScopeBarTests(DashTestCase): the rectangle outside of the icon. """ app_icon = self.scopebar.get_icon_by_name(u'applications.scope') - - self.mouse.move(app_icon.x + (app_icon.width / 2), - app_icon.y + (app_icon.height / 2)) - self.mouse.click() + self.mouse.click_object(app_icon) self.assertThat(self.scopebar.active_scope, Eventually(Equals('applications.scope'))) @@ -1118,10 +1112,7 @@ class PreviewNavigateTests(DashTestCase): cover_art = self.get_current_preview().cover_art[0] # click the cover-art (this will set focus) - tx = cover_art.x + (cover_art.width / 2) - ty = cover_art.y + (cover_art.height / 2) - self.mouse.move(tx, ty) - self.mouse.click() + self.click_object(cover_art) self.keyboard.press_and_release("Escape") @@ -1137,13 +1128,21 @@ class PreviewNavigateTests(DashTestCase): class PreviewClickCancelTests(DashTestCase): """Tests that the preview closes when left, middle, and right clicking in the preview""" + scenarios = [('Left button', {'clicked_button': 1}), + ('Middle button', {'clicked_button': 2}), + ('Right button', {'clicked_button': 3})] + def setUp(self): super(PreviewClickCancelTests, self).setUp() gettext.install("unity-scope-applications") - scope = self.unity.dash.reveal_application_scope() + scope = self.unity.dash.reveal_application_scope(clear_search=False) self.addCleanup(self.unity.dash.ensure_hidden) # Only testing an application preview for this test. - self.keyboard.type("Software Updater") + + search_string = "Software Updater" + if self.unity.dash.search_string != search_string: + self.unity.dash.clear_search() + self.keyboard.type(search_string) # wait for "Installed" category category = self.wait_for_category(scope, _("Installed")) @@ -1158,183 +1157,43 @@ class PreviewClickCancelTests(DashTestCase): self.preview_container = self.unity.dash.view.get_preview_container() - def test_left_click_on_preview_icon_cancel_preview(self): - """Left click on preview icon must close preview.""" + def test_click_on_preview_icon_cancel_preview(self): + """Clicking with any button on preview icon must close preview.""" icon = self.get_current_preview().icon[0] self.assertThat(icon, NotEquals(None)) - tx = icon.x + icon.width - ty = icon.y + (icon.height / 2) - self.mouse.move(tx, ty) - self.mouse.click(button=1) - + self.mouse.click_object(icon, button=self.clicked_button) self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) - def test_middle_click_on_preview_icon_cancel_preview(self): - """Middle click on preview icon must close preview.""" - icon = self.get_current_preview().icon[0] - self.assertThat(icon, NotEquals(None)) - - tx = icon.x + icon.width - ty = icon.y + (icon.height / 2) - self.mouse.move(tx, ty) - self.mouse.click(button=2) - - self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) - - def test_right_click_on_preview_icon_cancel_preview(self): - """Right click on preview icon must close preview.""" - icon = self.get_current_preview().icon[0] - self.assertThat(icon, NotEquals(None)) - - tx = icon.x + icon.width - ty = icon.y + (icon.height / 2) - self.mouse.move(tx, ty) - self.mouse.click(button=3) - - self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) - - def test_left_click_on_preview_image_cancel_preview(self): - """Left click on preview image must cancel the preview.""" - cover_art = self.get_current_preview().cover_art[0] - self.assertThat(cover_art, NotEquals(None)) - - tx = cover_art.x + (cover_art.width / 2) - ty = cover_art.y + (cover_art.height / 2) - self.mouse.move(tx, ty) - self.mouse.click(button=1) - - self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) - - def test_middle_click_on_preview_image_cancel_preview(self): - """Middle click on preview image must cancel the preview.""" - cover_art = self.get_current_preview().cover_art[0] - self.assertThat(cover_art, NotEquals(None)) - - tx = cover_art.x + (cover_art.width / 2) - ty = cover_art.y + (cover_art.height / 2) - self.mouse.move(tx, ty) - self.mouse.click(button=2) - - self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) - - def test_right_click_on_preview_image_cancel_preview(self): - """Right click on preview image must cancel the preview.""" + def test_click_on_preview_image_cancel_preview(self): + """Clicking with any button on preview image must cancel the preview.""" cover_art = self.get_current_preview().cover_art[0] self.assertThat(cover_art, NotEquals(None)) - tx = cover_art.x + (cover_art.width / 2) - ty = cover_art.y + (cover_art.height / 2) - self.mouse.move(tx, ty) - self.mouse.click(button=3) - + self.mouse.click_object(cover_art, button=self.clicked_button) self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) - def test_left_click_on_preview_text_cancel_preview(self): - """Left click on some preview text must cancel the preview.""" + def test_click_on_preview_text_cancel_preview(self): + """Clicking with any button on some preview text must cancel the preview.""" text = self.get_current_preview().text_boxes[0] self.assertThat(text, NotEquals(None)) - - tx = text.x + (text.width / 2) - ty = text.y + (text.height / 2) - self.mouse.move(tx, ty) - self.mouse.click(button=1) + self.mouse.click_object(text, button=self.clicked_button) self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) - def test_middle_click_on_preview_text_cancel_preview(self): - """Middle click on some preview text must cancel the preview.""" - text = self.get_current_preview().text_boxes[0] - self.assertThat(text, NotEquals(None)) - - tx = text.x + (text.width / 2) - ty = text.y + (text.height / 2) - self.mouse.move(tx, ty) - self.mouse.click(button=2) - - self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) - - def test_right_click_on_preview_text_cancel_preview(self): - """Right click on some preview text must cancel the preview.""" - text = self.get_current_preview().text_boxes[0] - self.assertThat(text, NotEquals(None)) - - tx = text.x + (text.width / 2) - ty = text.y + (text.height / 2) - self.mouse.move(tx, ty) - self.mouse.click(button=3) - - self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) - - def test_left_click_on_preview_ratings_widget_cancel_preview(self): - """Left click on the ratings widget must cancel the preview.""" - ratings_widget = self.get_current_preview().ratings_widget[0] - self.assertThat(ratings_widget, NotEquals(None)) - - tx = ratings_widget.x + (ratings_widget.width / 2) - ty = ratings_widget.y + (ratings_widget.height / 2) - self.mouse.move(tx, ty) - self.mouse.click(button=1) - - self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) - - def test_middle_click_on_preview_ratings_widget_cancel_preview(self): - """Middle click on the ratings widget must cancel the preview.""" - ratings_widget = self.get_current_preview().ratings_widget[0] - self.assertThat(ratings_widget, NotEquals(None)) - - tx = ratings_widget.x + (ratings_widget.width / 2) - ty = ratings_widget.y + (ratings_widget.height / 2) - self.mouse.move(tx, ty) - self.mouse.click(button=2) - - self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) - - def test_right_click_on_preview_ratings_widget_cancel_preview(self): - """Right click on the ratings widget must cancel the preview.""" + def test_click_on_preview_ratings_widget_cancel_preview(self): + """Clicking with any button on the ratings widget must cancel the preview.""" ratings_widget = self.get_current_preview().ratings_widget[0] self.assertThat(ratings_widget, NotEquals(None)) - - tx = ratings_widget.x + (ratings_widget.width / 2) - ty = ratings_widget.y + (ratings_widget.height / 2) - self.mouse.move(tx, ty) - self.mouse.click(button=3) - - self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) - - def test_left_click_on_preview_info_hint_cancel_preview(self): - """Left click on the info hint must cancel the preview.""" - info_hint = self.get_current_preview().info_hint_widget[0] - self.assertThat(info_hint, NotEquals(None)) - - tx = info_hint.x + (info_hint.width / 2) - ty = info_hint.y + (info_hint.height / 8) - self.mouse.move(tx, ty) - self.mouse.click(button=1) + self.mouse.click_object(ratings_widget, button=self.clicked_button) self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) - def test_middle_click_on_preview_info_hint_cancel_preview(self): - """Middle click on the info hint must cancel the preview.""" + def test_click_on_preview_info_hint_cancel_preview(self): + """Clicking with any button on the info hint must cancel the preview.""" info_hint = self.get_current_preview().info_hint_widget[0] self.assertThat(info_hint, NotEquals(None)) - - tx = info_hint.x + (info_hint.width / 2) - ty = info_hint.y + (info_hint.height / 8) - self.mouse.move(tx, ty) - self.mouse.click(button=2) - - self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) - - def test_right_click_on_preview_info_hint_cancel_preview(self): - """Right click on the info hint must cancel the preview.""" - info_hint = self.get_current_preview().info_hint_widget[0] - self.assertThat(info_hint, NotEquals(None)) - - tx = info_hint.x + (info_hint.width / 2) - ty = info_hint.y + (info_hint.height / 8) - self.mouse.move(tx, ty) - self.mouse.click(button=3) + self.mouse.click_object(info_hint, button=self.clicked_button) self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) diff --git a/tests/autopilot/unity/tests/test_panel.py b/tests/autopilot/unity/tests/test_panel.py index 77da6a5b3..2b789396b 100644 --- a/tests/autopilot/unity/tests/test_panel.py +++ b/tests/autopilot/unity/tests/test_panel.py @@ -431,7 +431,6 @@ class PanelWindowButtonsTests(PanelTestsBase): self.addCleanup(self.unity.hud.ensure_hidden) self.panel.window_buttons.maximize.mouse_click() - self.assertThat(self.unity.hud.visible, Eventually(Equals(True))) def test_hud_maximize_button_does_not_change_dash_form_factor(self): @@ -1185,9 +1184,7 @@ class PanelGrabAreaTests(PanelTestsBase): self.assertProperty(text_win, is_focused=False) self.assertProperty(calc_win, is_focused=True) - self.move_mouse_over_grab_area() - self.mouse.click() - + self.mouse.click_object(self.grab_area, button=1) self.assertProperty(text_win, is_focused=True) def test_lower_the_maximized_window_works(self): @@ -1198,8 +1195,7 @@ class PanelGrabAreaTests(PanelTestsBase): self.assertProperty(text_win, is_focused=True) self.assertProperty(calc_win, is_focused=False) - self.move_mouse_over_grab_area() - self.mouse.click(2) + self.mouse.click_object(self.grab_area, button=2) self.assertProperty(calc_win, is_focused=True) @@ -1209,8 +1205,7 @@ class PanelGrabAreaTests(PanelTestsBase): self.addCleanup(self.unity.hud.ensure_hidden) self.keyboard.type("Hello") - self.move_mouse_over_grab_area() - self.mouse.click() + self.mouse.click_object(self.grab_area) self.keyboard.type("World") self.assertThat(self.unity.hud.search_string, Eventually(Equals("HelloWorld"))) |
