on xenial help sign in
Latest fixes for tests
a8a0901Andrea Cimitan
tests/autopilot/unity8/shell/emulators/hud.py+19−8
@@ -22,35 +22,34 @@ from collections import namedtuple
22from unity8 import get_grid_size
22from unity8 import get_grid_size
23from unity8.shell.emulators import UnityEmulatorBase
23from unity8.shell.emulators import UnityEmulatorBase
24from autopilot.input import Touch
24from autopilot.input import Touch
25−
25+from time import sleep
26
26
27SwipeCoords = namedtuple('SwipeCoords', 'start_x end_x start_y end_y')
27SwipeCoords = namedtuple('SwipeCoords', 'start_x end_x start_y end_y')
28
28
29−
30class Hud(UnityEmulatorBase):
29class Hud(UnityEmulatorBase):
31
30
32 """An emulator that understands the Hud."""
31 """An emulator that understands the Hud."""
33
32
34 def show(self):
33 def show(self):
35 """Swipes open the Hud."""
34 """Swipes open the Hud."""
36− touch = Touch.create()
35+ self.touch = Touch.create()
37
36
38 window = self.get_root_instance().select_single('QQuickView')
37 window = self.get_root_instance().select_single('QQuickView')
39 hud_show_button = window.select_single("HudButton")
38 hud_show_button = window.select_single("HudButton")
40
39
41 swipe_coords = self.get_button_swipe_coords(window, hud_show_button)
40 swipe_coords = self.get_button_swipe_coords(window, hud_show_button)
42
41
43− touch.press(swipe_coords.start_x, swipe_coords.start_y)
42+ self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
44− touch._finger_move(swipe_coords.end_x, swipe_coords.end_y)
43+ self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.end_y)
45 try:
44 try:
46 hud_show_button.opacity.wait_for(1.0)
45 hud_show_button.opacity.wait_for(1.0)
47− touch.release()
46+ self.touch.release()
48 self.shown.wait_for(True)
47 self.shown.wait_for(True)
49 except AssertionError:
48 except AssertionError:
50 raise
49 raise
51 finally:
50 finally:
52− if touch._touch_finger is not None:
51+ if self.touch._touch_finger is not None:
53− touch.release()
52+ self.touch.release()
54
53
55 def dismiss(self):
54 def dismiss(self):
56 """Closes the open Hud."""
55 """Closes the open Hud."""
@@ -78,3 +77,15 @@ class Hud(UnityEmulatorBase):
78 end_y = main_view.y + int(hud_show_button.y + (hud_show_button.height/2))
77 end_y = main_view.y + int(hud_show_button.y + (hud_show_button.height/2))
79
78
80 return SwipeCoords(start_x, end_x, start_y, end_y)
79 return SwipeCoords(start_x, end_x, start_y, end_y)
80+
81+ def _drag(self, x1, y1, x2, y2):
82+ cur_x = x1
83+ cur_y = y1
84+ dx = 1.0 * (x2 - x1) / 100
85+ dy = 1.0 * (y2 - y1) / 100
86+ for i in range(0, 100):
87+ self.touch._finger_move(int(cur_x), int(cur_y))
88+ sleep(0.002)
89+ cur_x += dx
90+ cur_y += dy
91+ self.touch._finger_move(int(x2), int(y2))