~vthompson/ubuntu-weather-app/fix-1452499

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntu_weather_app/__init__.py

* Create autopilot test which adds a location via searching
* Create autopilot test which adds a location via cached results
* Fix for racy search bar causing incorrect search query when typed quickly. Fixes: https://bugs.launchpad.net/bugs/1452497.

Approved by Victor Thompson, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
import logging
11
11
from ubuntuuitoolkit import MainView, UbuntuUIToolkitCustomProxyObjectBase
12
12
 
13
 
 
14
13
logger = logging.getLogger(__name__)
15
14
 
16
15
 
51
50
 
52
51
class Page(UbuntuUIToolkitCustomProxyObjectBase):
53
52
    """Autopilot helper for Pages."""
54
 
    def __init__(self, *args):
55
 
        super(Page, self).__init__(*args)
 
53
    def __init__(self, *args, **kwargs):
 
54
        super(Page, self).__init__(*args, **kwargs)
 
55
 
 
56
        # Use only objectName due to bug 1350532 as it is MainView12
 
57
        self.main_view = self.get_root_instance().select_single(
 
58
            objectName="weather")
 
59
 
 
60
    def click_back(self):
 
61
        return self.main_view.get_header().click_back_button()
56
62
 
57
63
 
58
64
class PageWithBottomEdge(Page):
59
 
    """Autopilot helper for PageWithBottomEdge."""
60
 
    def __init__(self, *args):
61
 
        super(PageWithBottomEdge, self).__init__(*args)
 
65
    """
 
66
    An emulator class that makes it easy to interact with the bottom edge
 
67
    swipe page
 
68
    """
 
69
    def __init__(self, *args, **kwargs):
 
70
        super(PageWithBottomEdge, self).__init__(*args, **kwargs)
62
71
 
63
72
    def reveal_bottom_edge_page(self):
64
73
        """Bring the bottom edge page to the screen"""
65
 
 
66
74
        self.bottomEdgePageLoaded.wait_for(True)
67
75
 
68
76
        try:
73
81
            start_y = (action_item.globalRect.y +
74
82
                       (action_item.height * 0.5))
75
83
            stop_y = start_y - (self.height * 0.7)
76
 
 
77
84
            self.pointing_device.drag(start_x, start_y,
78
85
                                      start_x, stop_y, rate=2)
79
86
            self.isReady.wait_for(True)
84
91
 
85
92
class AddLocationPage(Page):
86
93
    """Autopilot helper for AddLocationPage."""
87
 
    def __init__(self, *args):
88
 
        super(AddLocationPage, self).__init__(*args)
 
94
    def __init__(self, *args, **kwargs):
 
95
        super(AddLocationPage, self).__init__(*args, **kwargs)
 
96
 
 
97
    @click_object
 
98
    def click_location(self, index):
 
99
        return self.select_single("UCListItem",
 
100
                                  objectName="addLocation" + str(index))
 
101
 
 
102
    def click_search_action(self):
 
103
        self.main_view.get_header().click_action_button("search")
 
104
 
 
105
    def get_search_field(self):
 
106
        header = self.main_view.get_header()
 
107
 
 
108
        return header.select_single("TextField", objectName="searchField")
 
109
 
 
110
    def search(self, value):
 
111
        self.click_search_action()
 
112
 
 
113
        search_field = self.get_search_field()
 
114
        search_field.write(value)
 
115
 
 
116
        # Wait for model to finish loading
 
117
        self.searching.wait_for(False)
89
118
 
90
119
 
91
120
class HomePage(PageWithBottomEdge):
92
121
    """Autopilot helper for HomePage."""
93
 
    def __init__(self, *args):
94
 
        super(HomePage, self).__init__(*args)
 
122
    def __init__(self, *args, **kwargs):
 
123
        super(HomePage, self).__init__(*args, **kwargs)
95
124
 
96
125
    def get_location_count(self):
97
126
        return self.wait_select_single(
103
132
    def __init__(self, *args, **kwargs):
104
133
        super(LocationsPage, self).__init__(*args, **kwargs)
105
134
 
 
135
    def click_add_location_action(self):
 
136
        self.main_view.get_header().click_action_button("addLocation")
 
137
 
 
138
    def get_location(self, index):
 
139
        return self.select_single(WeatherListItem,
 
140
                                  objectName="location" + str(index))
 
141
 
106
142
 
107
143
class MainView(MainView):
108
144
    """Autopilot custom proxy object for the MainView."""
111
147
    def __init__(self, *args):
112
148
        super(MainView, self).__init__(*args)
113
149
        self.visible.wait_for(True)
 
150
 
 
151
 
 
152
class WeatherListItem(UbuntuUIToolkitCustomProxyObjectBase):
 
153
    def get_name(self):
 
154
        return self.select_single("Label", objectName="name").text