on xenial help sign in
More AP testing
2ecb97bNick Dedekind
tests/autopilot/indicators_client/emulators/common.py+2−2
@@ -10,5 +10,5 @@ from indicators_client.emulators import IndicatorsIntrospectionObject
10class SwitchMenu(IndicatorsIntrospectionObject):
10class SwitchMenu(IndicatorsIntrospectionObject):
11 """A switch menu control."""
11 """A switch menu control."""
12
12
13− def get_checked(self):
13+class Switch(IndicatorsIntrospectionObject):
14− return self.checked
14+ """A switch control."""
tests/autopilot/indicators_client/tests/test_power.py+58−3
@@ -11,8 +11,9 @@ from testtools.matchers import Equals, NotEquals
11from autopilot.matchers import Eventually
11from autopilot.matchers import Eventually
12
12
13from indicators_client.tests import IndicatorsTestCase
13from indicators_client.tests import IndicatorsTestCase
14−from indicators_client.emulators.common import SwitchMenu
15from time import sleep
14from time import sleep
15+import random
16+import math
16
17
17class TestDisplayMenus(IndicatorsTestCase):
18class TestDisplayMenus(IndicatorsTestCase):
18 def setUp(self):
19 def setUp(self):
@@ -32,15 +33,69 @@ class TestDisplayMenus(IndicatorsTestCase):
32 # self.main_window.get_indicators_client().reset()
33 # self.main_window.get_indicators_client().reset()
33 super(TestDisplayMenus, self).tearDown()
34 super(TestDisplayMenus, self).tearDown()
34
35
36+
37+ # START SECTION
38+ # We need to move these to emulators once autopilot supports emulators for
39+ # applications started with AutopilotTestCase.launch_test_application
40+
41+ def switch_auto_brightness(self, auto_brightness):
42+ ab_switch = auto_brightness.select_single("CheckBox");
43+ self.assertThat(ab_switch, NotEquals(None))
44+
45+ self.pointing_device.move_to_object(ab_switch)
46+ self.pointing_device.click()
47+
48+ def set_brightness_to_value(self, brightness_menu, new_value):
49+ brightness_slider = brightness_menu.select_single("Slider");
50+ self.assertThat(brightness_slider, NotEquals(None))
51+
52+ self.pointing_device.move_to_object(brightness_slider)
53+
54+ old_ab_value = brightness_slider.value
55+ pixel_ratio = brightness_slider.width / (brightness_slider.maximumValue - brightness_slider.minimumValue)
56+ print pixel_ratio
57+
58+ while True:
59+
60+ pixels_to_move = int(pixel_ratio * (new_value - old_ab_value) / 15)
61+ if pixels_to_move == 0:
62+ break;
63+ print pixels_to_move
64+
65+ self.pointing_device.drag(self.pointing_device.x, self.pointing_device.y, self.pointing_device.x + pixels_to_move, self.pointing_device.y)
66+
67+ old_ab_value = brightness_slider.value
68+
35 def test_auto_bright_switch(self):
69 def test_auto_bright_switch(self):
36 """Test the auto-bright switch"""
70 """Test the auto-bright switch"""
37
71
38 auto_brightness = self.app.select_single("SwitchMenu", objectName="auto-brightness")
72 auto_brightness = self.app.select_single("SwitchMenu", objectName="auto-brightness")
39 self.assertThat(auto_brightness, NotEquals(None))
73 self.assertThat(auto_brightness, NotEquals(None))
40
74
41− old_value = auto_brightness.checked
75+ old_ab_value = auto_brightness.checked
76+
77+ self.switch_auto_brightness(auto_brightness)
78+
79+ # TODO - should check backend when it's introspectable.
80+ self.assertThat(auto_brightness.checked, Eventually(NotEquals(old_ab_value)))
81+
82+ def test_brightness_slider(self):
83+ """Test the auto-bright switch"""
84+
85+ brightness_menu = self.app.select_single("SliderMenu", objectName="brightness")
86+ self.assertThat(brightness_menu, NotEquals(None))
87+
88+ old_ab_value = brightness_menu.value
89+ # find a new value to do to. At least 1/4 distance away from current value
90+ while True:
91+ desired_value = random.uniform(brightness_menu.minimumValue, brightness_menu.maximumValue)
92+ if (abs(desired_value - old_ab_value) >= (brightness_menu.maximumValue - brightness_menu.minimumValue)/4):
93+ break;
94+
95+ self.set_brightness_to_value(brightness_menu, desired_value)
42
96
43− print auto_brightness.get_checked()
97+ # TODO - should check backend when it's introspectable.
98+ self.assertThat(auto_brightness.value, Eventually(NotEquals(old_ab_value)))
44
99
45
100
46
101