~nskaggs/ubuntu-clock-app/ap-init-cleanup

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntu_clock_app/tests/test_stopwatch.py

Refactor stopwatch helpers to follow the page object pattern.

Approved by Ubuntu Phone Apps Jenkins Bot, Leo Arias.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from __future__ import absolute_import
22
22
 
23
 
from testtools.matchers import Equals, NotEquals, Is, Not
 
23
import time
 
24
from testtools.matchers import Equals, NotEquals
24
25
from autopilot.matchers import Eventually
25
26
 
26
27
from ubuntu_clock_app.tests import ClockAppTestCase
27
28
 
 
29
 
28
30
class TestStopwatch(ClockAppTestCase):
29
31
    """Tests the stopwatch page features"""
30
32
 
31
 
    """ This is needed to wait for the application to start.
32
 
        In the testfarm, the application may take some time to show up."""
33
33
    def setUp(self):
 
34
        """ This is needed to wait for the application to start.
 
35
 
 
36
        In the testfarm, the application may take some time to show up.
 
37
 
 
38
        """
34
39
        super(TestStopwatch, self).setUp()
35
40
        self.assertThat(
36
41
            self.main_view.visible, Eventually(Equals(True)))
37
42
 
38
 
        # Move to stopwatch tab
39
 
        self.main_view.switch_to_tab("StopwatchTab")
40
 
 
41
 
    def tearDown(self):
42
 
        super(TestStopwatch, self).tearDown()
43
 
 
44
 
    def create_lap(self):
45
 
        """Function to create a stopwatch lap"""
46
 
        lap_button = self.main_view.get_lap_button()
47
 
        self.pointing_device.click_object(lap_button)
48
 
 
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)
53
 
 
54
 
    def test_start_stop_reset_stopwatch(self):
55
 
        """Test to check the proper functioning of the start/stop/reset of stopwatch"""
56
 
 
57
 
        stopwatch_label = self.main_view.get_stopwatch_label()
58
 
        reset_button = self.main_view.get_reset_button()
59
 
 
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")))
64
 
 
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)))
70
 
 
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")))
74
 
 
75
 
    def test_create_lap(self):
76
 
        """Test to check creating a new stopwatch lap"""
77
 
 
78
 
        # Start the stopwatch
79
 
        stopwatch_label = self.main_view.get_stopwatch_label().text
80
 
        self.start_stop_stopwatch()
81
 
 
82
 
        # Ensure that the stopwatch actually ticks
83
 
        self.assertThat(stopwatch_label, Eventually(NotEquals("00:00.0")))
84
 
 
85
 
        # Create a stopwatch lap by pressing the lap button
86
 
        num_of_laps_old = self.main_view.get_num_of_laps()
87
 
        self.create_lap()
88
 
 
 
43
        self.page = self.main_view.open_stopwatch()
 
44
 
 
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')))
 
51
 
 
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()
 
58
        time.sleep(1)
 
59
        self.assertThat(
 
60
            stopwatch_time,
 
61
            Equals(self.page.get_stopwatch_time()))
 
62
 
 
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')))
 
70
 
 
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
90
77
        self.assertThat(
91
 
            self.main_view.get_num_of_laps,
 
78
            self.page.get_num_of_laps,
92
79
            Eventually(Equals(num_of_laps_old + 1)))
93
80
 
94
 
    def test_delete_lap(self):
95
 
        """Test to check deleting a stopwatch lap"""
96
 
 
97
 
        # Start the stopwatch
98
 
        stopwatch_label = self.main_view.get_stopwatch_label().text
99
 
        self.start_stop_stopwatch()
100
 
 
101
 
        # Ensure that the stopwatch actually ticks
102
 
        self.assertThat(stopwatch_label, Eventually(NotEquals("00:00.0")))
103
 
 
104
 
        # Create a stopwatch lap
105
 
        self.create_lap()
106
 
 
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")
110
 
 
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()
115
 
 
 
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
117
88
        self.assertThat(
118
 
            self.main_view.get_num_of_laps,
 
89
            self.page.get_num_of_laps,
119
90
            Eventually(Equals(num_of_laps_old - 1)))