1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# Copyright 2013, 2014, 2015 Canonical
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
"""Ubuntu Weather app autopilot tests."""
from __future__ import absolute_import
import logging
from autopilot.matchers import Eventually
from testtools.matchers import Equals
from ubuntu_weather_app.tests import UbuntuWeatherAppTestCaseWithData
logger = logging.getLogger(__name__)
class TestSettingsPage(UbuntuWeatherAppTestCaseWithData):
""" Tests for the settings page
setUp opens settings page as all tests start from here """
def setUp(self):
super(TestSettingsPage, self).setUp()
self.main_view = self.app.main_view
# Get the home page and selected pane
self.home_page = self.app.get_home_page()
self.location_pane = self.home_page.get_selected_location_pane()
# Get initial wind and temperature settings
self.day_delegate = self.location_pane.get_day_delegate(0)
self.initial_wind_unit = self.day_delegate.get_wind_unit()
self.initial_temperature_unit = self.day_delegate.get_temperature_unit(
)
# Open and get the settings page
self.location_pane.click_settings_button()
self.settings_page = self.app.get_settings_page()
def _get_units_page(self):
""" helper method to get the units page """
# Click the units page
self.settings_page.click_settings_page_listitem("Units")
return self.settings_page.get_units_page()
def _go_to_settings_page(self):
""" helper method that navigates to the setting page """
# Open the Settings page
self.location_pane.click_settings_button()
# Get the Settings page
self.settings_page = self.app.get_settings_page()
def _get_data_provider_page(self):
""" helper method to get the data provider page """
# Open the Data Provider Page
self.settings_page.click_settings_page_listitem("Data Provider")
# Get the Data Provider Page
return self.settings_page.get_data_provider_page()
def _check_provider(self, service):
"""
checks selected weather data provider from the first location tab
"""
# Go back to Home page
self.data_provider_page.click_back()
self.settings_page.click_back()
# Reget the home page and selected pane as they have changed
self.location_pane = self.home_page.get_selected_location_pane()
self.day_delegate = self.location_pane.get_day_delegate(0)
day_delegate_extra_info = self.day_delegate.get_extra_info()
if service == "openweathermap":
# Check that the 'Chance of Rain' and
# 'UV Index' Labels are not visible
self.assertThat(day_delegate_extra_info.wait_select_single(
"ForecastDetailsDelegate",
objectName="chanceOfRainForecast").visible,
Eventually(Equals(False)))
self.assertThat(day_delegate_extra_info.wait_select_single(
"ForecastDetailsDelegate",
objectName="uvIndexForecast").visible,
Eventually(Equals(False)))
elif service == "weatherchannel":
# Check that the 'Chance of Rain' and 'UV Index' Labels are visible
self.assertThat(day_delegate_extra_info.wait_select_single(
"ForecastDetailsDelegate",
objectName="chanceOfPrecipForecast").visible,
Eventually(Equals(True)))
self.assertThat(day_delegate_extra_info.wait_select_single(
"ForecastDetailsDelegate",
objectName="uvIndexForecast").visible,
Eventually(Equals(True)))
def test_switch_temperature_units(self):
""" tests switching temperature units in Units page """
# Get the units page
units_page = self._get_units_page()
# Check that the initial unit is F
self.assertThat(self.initial_temperature_unit, Equals("F"))
# Change the unit
changed = units_page.change_listitem_unit("temperatureSetting")
# Check that the new value is not the previously selected
self.assertThat(changed, Equals(True))
# Go back to the home page
units_page.click_back()
self.settings_page.click_back()
# Reget the home page and selected pane as they have changed
self.location_pane = self.home_page.get_selected_location_pane()
self.day_delegate = self.location_pane.get_day_delegate(0)
# Check that the unit is different to the starting unit
self.assertThat(self.day_delegate.low.endswith(
self.initial_temperature_unit), Equals(False))
self.assertThat(self.day_delegate.high.endswith(
self.initial_temperature_unit), Equals(False))
def test_switch_wind_speed_units(self):
""" tests switching wind speed unit in Units page """
# Get the units page
units_page = self._get_units_page()
# Check that the initial unit is mph
self.assertThat(self.initial_wind_unit, Equals("mph"))
# Change the unit
changed = units_page.change_listitem_unit("windSetting")
# Check that the new value is not the previously selected
self.assertThat(changed, Equals(True))
# Go back to the home page
units_page.click_back()
self.settings_page.click_back()
# Reget the home page and selected pane as they have changed
self.location_pane = self.home_page.get_selected_location_pane()
self.day_delegate = self.location_pane.get_day_delegate(0)
# Check that the unit is different to the starting unit
self.assertThat(self.day_delegate.get_wind_unit().endswith(
self.initial_wind_unit), Equals(False))
def test_switch_service(self):
""" tests switching data providers in Data provider page """
# Get Data Provider Page
data_provider_page = self._get_data_provider_page()
# Select TWC as the provider
data_provider_page.expand_data_provider_listitem(
"dataProviderSetting")
data_provider_page.click_selected_listitem("dataProviderSetting")
# Check that the initial provider is TWC
self._check_provider("weatherchannel")
# Reget page
self._go_to_settings_page()
data_provider_page = self._get_data_provider_page()
# Attempt to change it to OWM and make sure that it does
self.assertThat(
data_provider_page.change_listitem_data_provider(
"dataProviderSetting"), Equals(True))
# Check provider
self._check_provider("openweathermap")
# Reget page
self._go_to_settings_page()
data_provider_page = self._get_data_provider_page()
# Attempt to change it back to TWC and make sure that it does
self.assertThat(
data_provider_page.change_listitem_data_provider(
"dataProviderSetting"), Equals(True))
# Check provider
self._check_provider("weatherchannel")
|