~nskaggs/ubuntu-calendar-app/debug-ap-tests

124.1.1 by nskaggs
standardize layout, add click testing support, prep for yearview and dayview tests
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2013 Canonical
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
7
8
"""Calendar app autopilot emulators."""
9
158.2.2 by Leo Arias
Update the tests to handle the dbus.StateNotFoundError.
10
from autopilot.introspection import dbus
124.1.1 by nskaggs
standardize layout, add click testing support, prep for yearview and dayview tests
11
from ubuntuuitoolkit import emulators as toolkit_emulators
12
13
14
class MainView(toolkit_emulators.MainView):
15
16
    """
17
    An emulator class that makes it easy to interact with the calendar-app.
18
    """
19
20
    def get_event_view(self):
172.1.2 by nskaggs
mass transition to wait_select to see if that fixes timing issues
21
        return self.wait_select_single("EventView")
124.1.1 by nskaggs
standardize layout, add click testing support, prep for yearview and dayview tests
22
23
    def get_month_view(self):
172.1.2 by nskaggs
mass transition to wait_select to see if that fixes timing issues
24
        return self.wait_select_single("MonthView")
124.1.1 by nskaggs
standardize layout, add click testing support, prep for yearview and dayview tests
25
26
    def get_year_view(self):
172.1.2 by nskaggs
mass transition to wait_select to see if that fixes timing issues
27
        return self.wait_select_single("YearView")
124.1.1 by nskaggs
standardize layout, add click testing support, prep for yearview and dayview tests
28
29
    def get_day_view(self):
172.1.2 by nskaggs
mass transition to wait_select to see if that fixes timing issues
30
        return self.wait_select_single("DayView")
124.1.1 by nskaggs
standardize layout, add click testing support, prep for yearview and dayview tests
31
162.1.1 by Andrea Cerisara
Added autopilot tests for the weekly view.
32
    def get_week_view(self):
172.1.2 by nskaggs
mass transition to wait_select to see if that fixes timing issues
33
        return self.wait_select_single("WeekView")
162.1.1 by Andrea Cerisara
Added autopilot tests for the weekly view.
34
124.1.1 by nskaggs
standardize layout, add click testing support, prep for yearview and dayview tests
35
    def get_label_with_text(self, text, root=None):
36
        if root is None:
37
            root = self
38
        labels = root.select_many("Label", text=text)
39
        if (len(labels) > 0):
40
            return labels[0]
41
        else:
42
            return None
43
44
    def get_new_event(self):
158.2.2 by Leo Arias
Update the tests to handle the dbus.StateNotFoundError.
45
        try:
172.1.4 by nskaggs
correct wait_wait error
46
            return self.wait_select_single("NewEvent")
158.2.2 by Leo Arias
Update the tests to handle the dbus.StateNotFoundError.
47
        except dbus.StateNotFoundError:
48
            return None
124.1.1 by nskaggs
standardize layout, add click testing support, prep for yearview and dayview tests
49
50
    def get_new_event_name_input_box(self):
51
        new_event = self.get_new_event()
172.1.2 by nskaggs
mass transition to wait_select to see if that fixes timing issues
52
        return new_event.wait_select_single("NewEventEntryField",
172.1.3 by nskaggs
fix pep8
53
                                            objectName="newEventName")
124.1.1 by nskaggs
standardize layout, add click testing support, prep for yearview and dayview tests
54
55
    def get_event_start_time_field(self):
56
        new_event = self.get_new_event()
172.1.2 by nskaggs
mass transition to wait_select to see if that fixes timing issues
57
        return new_event.wait_select_single("NewEventEntryField",
172.1.3 by nskaggs
fix pep8
58
                                            objectName="startTimeInput")
124.1.1 by nskaggs
standardize layout, add click testing support, prep for yearview and dayview tests
59
60
    def get_event_end_time_field(self):
61
        new_event = self.get_new_event()
172.1.2 by nskaggs
mass transition to wait_select to see if that fixes timing issues
62
        return new_event.wait_select_single("NewEventEntryField",
172.1.3 by nskaggs
fix pep8
63
                                            objectName="endTimeInput")
124.1.1 by nskaggs
standardize layout, add click testing support, prep for yearview and dayview tests
64
65
    def get_event_location_field(self):
66
        new_event = self.get_new_event()
172.1.2 by nskaggs
mass transition to wait_select to see if that fixes timing issues
67
        return new_event.wait_select_single("NewEventEntryField",
172.1.3 by nskaggs
fix pep8
68
                                            objectName="eventLocationInput")
124.1.1 by nskaggs
standardize layout, add click testing support, prep for yearview and dayview tests
69
70
    def get_event_people_field(self):
71
        new_event = self.get_new_event()
172.1.2 by nskaggs
mass transition to wait_select to see if that fixes timing issues
72
        return new_event.wait_select_single("NewEventEntryField",
172.1.3 by nskaggs
fix pep8
73
                                            objectName="eventPeopleInput")
124.1.1 by nskaggs
standardize layout, add click testing support, prep for yearview and dayview tests
74
75
    def get_time_picker(self):
158.2.2 by Leo Arias
Update the tests to handle the dbus.StateNotFoundError.
76
        try:
172.1.4 by nskaggs
correct wait_wait error
77
            return self.wait_select_single("TimePicker")
158.2.2 by Leo Arias
Update the tests to handle the dbus.StateNotFoundError.
78
        except dbus.StateNotFoundError:
79
            return None
143.1.1 by Andrea Cerisara
WIP, added tests for year view
80
194 by nskaggs
further tweaks for swiping
81
    def swipe_view(self, direction, view, x_pad=0.15):
143.1.2 by Andrea Cerisara
Added more tests for year view, refactoring.
82
        """Swipe the given view to left or right.
83
84
        Args:
85
            direction: if 1 it swipes from right to left, if -1 from
86
                left right.
87
88
        """
89
194 by nskaggs
further tweaks for swiping
90
        start = ((-direction * x_pad) % 1) / 1.5
91
        stop = (direction * x_pad) % 1 / 1.5
143.1.2 by Andrea Cerisara
Added more tests for year view, refactoring.
92
93
        y_line = view.globalRect[1] + view.globalRect[3] / 2
94
        x_start = view.globalRect[0] + view.globalRect[2] * start
95
        x_stop = view.globalRect[0] + view.globalRect[2] * stop
96
97
        self.pointing_device.drag(x_start, y_line, x_stop, y_line)
162.1.1 by Andrea Cerisara
Added autopilot tests for the weekly view.
98
99
    def get_year(self, component):
172.1.2 by nskaggs
mass transition to wait_select to see if that fixes timing issues
100
        return int(component.wait_select_single(
162.1.1 by Andrea Cerisara
Added autopilot tests for the weekly view.
101
            "Label", objectName="yearLabel").text)
102
103
    def get_month_name(self, component):
172.1.2 by nskaggs
mass transition to wait_select to see if that fixes timing issues
104
        return component.wait_select_single(
162.1.1 by Andrea Cerisara
Added autopilot tests for the weekly view.
105
            "Label", objectName="monthLabel").text