on xenial help sign in
Actually add the added emulators
commit3062d1d8136d17605857ee1590dfdf2ee38d368a authorChristopher Lee <chris.lee@canonical.com> dateTue 16 Jul 2013, 22:54 (13 years ago) parent5436ae3
4 files changed+93−1
tests/autopilot/unity8/shell/emulators/dash.py+21 tests/autopilot/unity8/shell/emulators/hud.py+52 tests/autopilot/unity8/shell/emulators/launcher.py+18 tests/autopilot/unity8/shell/tests/test_hud.py+2−1
tests/autopilot/unity8/shell/emulators/dash.pynew file+21
@@ -0,0 +1,21 @@
1+from unity8.shell.emulators import Unity8EmulatorBase
2+
3+class Dash(Unity8EmulatorBase):
4+
5+ """An emulator that understands the Dash."""
6+
7+ def get_home_applications_grid(self):
8+ return self.select_single("ApplicationsFilterGrid", objectName="dashHomeApplicationsGrid")
9+
10+ def get_application_icon(self, text):
11+ """Returns a 'Tile' icon that has the text 'text' from the application
12+ grid.
13+
14+ Will return None if the icon isn't found.
15+
16+ :param text: String containing the text of the icon to search for.
17+ """
18+ app_grid = self.get_home_applications_grid()
19+ resp_grid = app_grid.select_single('ResponsiveGridView')
20+ return resp_grid.select_single('Tile', text=text)
21+
tests/autopilot/unity8/shell/emulators/hud.pynew file+52
@@ -0,0 +1,52 @@
1+from unity8.shell.emulators import Unity8EmulatorBase
2+from autopilot.input import Touch
3+
4+class Hud(Unity8EmulatorBase):
5+
6+ """An emulator that understands the Hud."""
7+
8+ def show(self):
9+ """Swipes open the Hud."""
10+ # Todo: assumes the hud is ready and able to be swiped open. Need to
11+ # check if it's availble before even attempting.
12+ touch = Touch.create()
13+
14+ window = self.get_root_instance().select_single('QQuickView')
15+ hud_show_button = window.select_single("HudButton")
16+
17+ start_x = int(window.x + (window.width / 2))
18+ end_x = start_x
19+ # start_y = window.y + (window.height - 3)
20+ start_y = window.y + window.height
21+ end_y = int(hud_show_button.y + (hud_show_button.height/2))
22+
23+ touch.press(start_x, start_y)
24+ touch._finger_move(end_x, end_y)
25+ try:
26+ hud_show_button.opacity.wait_for(1.0)
27+ touch.release()
28+ self.shown.wait_for(True)
29+ except AssertionError:
30+ raise
31+ finally:
32+ if touch._touch_finger is not None:
33+ touch.release()
34+
35+ def dismiss(self):
36+ """Closes the open Hud."""
37+ # Ensure that the Hud is actually open
38+ self.shown.wait_for(True)
39+ touch = Touch.create()
40+ x, y = self.get_close_button_coords()
41+ touch.tap(x, y)
42+
43+ # TODO: Should grid_size be passed in or should we have a get_grid_size in
44+ # unity8.__init__ that reads it from the env.
45+ # Yeah I think so as it doesn't seem to make sense when passing it in.
46+ # Plus as above shows, we don't always have it.
47+ def get_close_button_coords(self, grid_size):
48+ """Returns the coordinates of the Huds close button bar."""
49+ rect = self.globalRect
50+ x = int(rect[0] + rect[2] / 2)
51+ y = rect[1] + grid_size
52+ return x, y
tests/autopilot/unity8/shell/emulators/launcher.pynew file+18
@@ -0,0 +1,18 @@
1+from unity8.shell.emulators import Unity8EmulatorBase
2+from autopilot.input import Touch
3+
4+class Launcher(Unity8EmulatorBase):
5+
6+ """An emulator that understands the Launcher."""
7+
8+ def show(self):
9+ """Swipes open the launcher."""
10+ touch = Touch.create()
11+
12+ view = self.get_root_instance().select_single('QQuickView')
13+ start_x = view.x + 1
14+ start_y = view.y + view.height / 2
15+ stop_x = start_x + self.panelWidth + 1
16+ stop_y = start_y
17+ touch.drag(start_x, start_y, stop_x, stop_y)
18+ self.shown.wait_for(True)
tests/autopilot/unity8/shell/tests/test_hud.py+2−1
@@ -177,6 +177,7 @@ class TestHud(Unity8TestCase):
177177 if self.touch._touch_finger is not None:
178178 self.touch.release()
179179
180+ # TODO: perhaps move this to the Hud emulator?
180181 def _get_hud_button_swipe_coords(self, main_view, hud_show_button):
181182 """Returns the coords both start and end x,y for swiping to make the
182183 'hud show' button appear.
@@ -185,6 +186,6 @@ class TestHud(Unity8TestCase):
185186 start_x = int(main_view.x + (main_view.width / 2))
186187 end_x = start_x
187188 start_y = main_view.y + (main_view.height -3)
188− end_y = int(hud_show_button.y)
189+ end_y = int(hud_show_button.y + (hud_show_button.height/2))
189190
190191 return SwipeCoords(start_x, end_x, start_y, end_y)