21
21
from __future__ import absolute_import
23
from testtools.matchers import Equals, NotEquals, Is, Not
24
from testtools.matchers import Equals, NotEquals
24
25
from autopilot.matchers import Eventually
26
27
from ubuntu_clock_app.tests import ClockAppTestCase
28
30
class TestStopwatch(ClockAppTestCase):
29
31
"""Tests the stopwatch page features"""
31
""" This is needed to wait for the application to start.
32
In the testfarm, the application may take some time to show up."""
34
""" This is needed to wait for the application to start.
36
In the testfarm, the application may take some time to show up.
34
39
super(TestStopwatch, self).setUp()
36
41
self.main_view.visible, Eventually(Equals(True)))
38
# Move to stopwatch tab
39
self.main_view.switch_to_tab("StopwatchTab")
42
super(TestStopwatch, self).tearDown()
45
"""Function to create a stopwatch lap"""
46
lap_button = self.main_view.get_lap_button()
47
self.pointing_device.click_object(lap_button)
49
def start_stop_stopwatch(self):
50
"""Function to start/stop the stopwatch"""
51
start_stop_button = self.main_view.get_stopwatch_button()
52
self.pointing_device.click_object(start_stop_button)
54
def test_start_stop_reset_stopwatch(self):
55
"""Test to check the proper functioning of the start/stop/reset of stopwatch"""
57
stopwatch_label = self.main_view.get_stopwatch_label()
58
reset_button = self.main_view.get_reset_button()
60
# Start the stopwatch and check if the stopwatch starts ticking
61
stopwatch_label_before = self.main_view.get_stopwatch_label().text
62
self.start_stop_stopwatch()
63
self.assertThat(stopwatch_label.text, Eventually(NotEquals("00:00.0")))
65
# Stop the stopwatch and check it has indeed stopped
66
self.start_stop_stopwatch()
67
self.assertThat(stopwatch_label_before, NotEquals(self.main_view.get_stopwatch_label().text))
68
stopwatch_label_after = lambda: self.main_view.get_stopwatch_label().text
69
self.assertThat(stopwatch_label_after, Eventually(Equals(self.main_view.get_stopwatch_label().text)))
71
# Press reset and check if the stopwatch has been resetted
72
self.pointing_device.click_object(reset_button)
73
self.assertThat(stopwatch_label.text, Eventually(Equals("00:00.0")))
75
def test_create_lap(self):
76
"""Test to check creating a new stopwatch lap"""
79
stopwatch_label = self.main_view.get_stopwatch_label().text
80
self.start_stop_stopwatch()
82
# Ensure that the stopwatch actually ticks
83
self.assertThat(stopwatch_label, Eventually(NotEquals("00:00.0")))
85
# Create a stopwatch lap by pressing the lap button
86
num_of_laps_old = self.main_view.get_num_of_laps()
43
self.page = self.main_view.open_stopwatch()
45
def test_click_clock_center_must_start_stopwatch(self):
46
"""Test if start button starts the stopwatch"""
47
stopwatch_time = self.page.get_stopwatch_time()
48
self.page.start_stopwatch()
49
# Check the stopwatch started running
50
self.assertThat(stopwatch_time, Eventually(NotEquals('00:00.0')))
52
def test_click_clock_center_with_stopwatch_started_must_stop_it(self):
53
"""Test if stop button stops the stopwatch"""
54
self.page.start_stopwatch()
55
self.page.stop_stopwatch()
56
# Check that the stopwatch has stopped
57
stopwatch_time = self.page.get_stopwatch_time()
61
Equals(self.page.get_stopwatch_time()))
63
def test_restart_button_must_restart_stopwatch_time(self):
64
"""Test if reset button resets the stopwatch time"""
65
self.page.start_stopwatch()
66
stopwatch_time = self.page.get_stopwatch_time()
67
self.page.reset_stopwatch()
68
# Check that the stopwatch has been reset
69
self.assertThat(stopwatch_time, Eventually(Equals('00:00.0')))
71
def test_lap_button_must_create_stopwatch_lap(self):
72
"""Test if lap button creates a stopwatch lap"""
73
self.page.start_stopwatch()
74
num_of_laps_old = self.page.get_num_of_laps()
75
self.page.create_lap()
89
76
# Confirm that the lap is created
91
self.main_view.get_num_of_laps,
78
self.page.get_num_of_laps,
92
79
Eventually(Equals(num_of_laps_old + 1)))
94
def test_delete_lap(self):
95
"""Test to check deleting a stopwatch lap"""
98
stopwatch_label = self.main_view.get_stopwatch_label().text
99
self.start_stop_stopwatch()
101
# Ensure that the stopwatch actually ticks
102
self.assertThat(stopwatch_label, Eventually(NotEquals("00:00.0")))
104
# Create a stopwatch lap
107
num_of_laps_old = self.main_view.get_num_of_laps()
108
if not(self.main_view.wideAspect):
109
self.main_view.drag_page_up("StopwatchPage")
111
# Delete stopwatch lap
112
first_lap = self.main_view.get_first_laps_list_item()
113
first_lap.swipe_to_delete()
114
first_lap.confirm_removal()
81
def test_delete_lap_must_delete_from_stopwatch_lap_list(self):
82
"""Test to delete a lap and check if it has been removed properly"""
83
self.page.start_stopwatch()
84
self.page.create_lap()
85
num_of_laps_old = self.page.get_num_of_laps()
86
self.page.delete_lap(index=0)
116
87
# Check that the stopwatch lap has been deleted
118
self.main_view.get_num_of_laps,
89
self.page.get_num_of_laps,
119
90
Eventually(Equals(num_of_laps_old - 1)))