Merge lp:~om26er/ubuntu-weather-app/fix_autopilot_tests_touch into lp:ubuntu-weather-app/obsolete.trunk

Proposed by Omer Akram on 2013-08-02
Status: Merged
Approved by: Martin Borho on 2013-08-04
Approved revision: 87
Merged at revision: 83
Proposed branch: lp:~om26er/ubuntu-weather-app/fix_autopilot_tests_touch
Merge into: lp:ubuntu-weather-app/obsolete.trunk
Diff against target: 158 lines (+49/-19)
3 files modified
components/AddLocationSheet.qml (+1/-0)
components/LocationManagerSheet.qml (+2/-0)
tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py (+46/-19)
To merge this branch: bzr merge lp:~om26er/ubuntu-weather-app/fix_autopilot_tests_touch
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve on 2013-08-05
Martin Borho 2013-08-02 Approve on 2013-08-04
Review via email: mp+178397@code.launchpad.net

Commit message

Fix failing autopilot tests on touch

Description of the change

Fix failing autopilot tests on touch

To post a comment you must log in.
Martin Borho (martin-borho) wrote :

Hi Omer,

there's no "index" for "currentLocationItem" + index, you should just call it "currentLocationItem". (LocationManagerSheet, L108)

Otherwise it's just fine, thanks a lot!

Now the only thing left is that "ubuntu_weather_app.tests.test_locationmanager.TestLocationManager.test_search_city" won't work on the device, since the "BackSpace" key is unknown. I've found a (litlle bit reckless) solution for that: Line 95 in http://bazaar.launchpad.net/~martin-borho/ubuntu-weather-app/device_tests_and_emulator/revision/83/tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py#

Perhaps you can incorporate that in a less hackish way, if you know one? Otherwise I could do that later on, no problem!

Thanks anyways!

Martin

review: Needs Fixing
Martin Borho (martin-borho) wrote :

Forget about test-search_city, you had already fixed that, too!

Sorry... had misread a traceback.

84. By Omer Akram on 2013-08-04

fix as suggested

Omer Akram (om26er) wrote :

> Hi Omer,
>
> there's no "index" for "currentLocationItem" + index, you should just call it
> "currentLocationItem". (LocationManagerSheet, L108)
>
Done. Thanks.

85. By Omer Akram on 2013-08-04

introduce helper select_single_retry() to make tests more reliable for the cases where object appear after query from the web

86. By Omer Akram on 2013-08-04

fix

87. By Omer Akram on 2013-08-04

forgot import

Martin Borho (martin-borho) wrote :

Cool thing, a retry handler! Thanks!

review: Approve
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'components/AddLocationSheet.qml'
--- components/AddLocationSheet.qml 2013-07-19 11:39:31 +0000
+++ components/AddLocationSheet.qml 2013-08-04 02:28:28 +0000
@@ -111,6 +111,7 @@
111 anchors.fill: parent;111 anchors.fill: parent;
112 model: citiesModel;112 model: citiesModel;
113 delegate: ListItem.Standard {113 delegate: ListItem.Standard {
114 objectName: "searchResult" + index
114 text: i18n.tr(name)+((country) ? ', '+i18n.tr(country): '');115 text: i18n.tr(name)+((country) ? ', '+i18n.tr(country): '');
115 progression: true;116 progression: true;
116 onClicked: {117 onClicked: {
117118
=== modified file 'components/LocationManagerSheet.qml'
--- components/LocationManagerSheet.qml 2013-07-23 21:20:11 +0000
+++ components/LocationManagerSheet.qml 2013-08-04 02:28:28 +0000
@@ -105,6 +105,7 @@
105 visible: false105 visible: false
106 text: i18n.tr("London")106 text: i18n.tr("London")
107 control: Button {107 control: Button {
108 objectName: "currentLocationItem"
108 id: lookupItemAddButton109 id: lookupItemAddButton
109 anchors.verticalCenter: parent.verticalCenter110 anchors.verticalCenter: parent.verticalCenter
110 text: i18n.tr("add")111 text: i18n.tr("add")
@@ -144,6 +145,7 @@
144 anchors.fill: parent145 anchors.fill: parent
145 model: locationModel146 model: locationModel
146 delegate: ListItem.Standard {147 delegate: ListItem.Standard {
148 objectName: "existingLocation" + index
147 text: model.name149 text: model.name
148 removable: true150 removable: true
149 onItemRemoved: {151 onItemRemoved: {
150152
=== modified file 'tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py'
--- tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py 2013-07-19 11:39:31 +0000
+++ tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py 2013-08-04 02:28:28 +0000
@@ -9,12 +9,15 @@
99
10from __future__ import absolute_import10from __future__ import absolute_import
1111
12from testtools.matchers import Equals12from testtools.matchers import Equals, NotEquals
13from autopilot.matchers import Eventually13from autopilot.matchers import Eventually
1414
15from ubuntu_weather_app.tests import WeatherTestCase, DatabaseMixin, SheetMixin15from ubuntu_weather_app.tests import WeatherTestCase, DatabaseMixin, SheetMixin
16from ubuntu_weather_app.tests.weatherdata import locations_data16from ubuntu_weather_app.tests.weatherdata import locations_data
1717
18from time import sleep
19
20
18class TestLocationManager(WeatherTestCase, DatabaseMixin, SheetMixin):21class TestLocationManager(WeatherTestCase, DatabaseMixin, SheetMixin):
19 def setUp(self):22 def setUp(self):
20 self.clean_db()23 self.clean_db()
@@ -33,6 +36,18 @@
33 addLocPage = self.main_window.get_object("DefaultSheet", "AddLocationSheet")36 addLocPage = self.main_window.get_object("DefaultSheet", "AddLocationSheet")
34 self.assertThat(addLocPage.visible, Eventually(Equals(True)))37 self.assertThat(addLocPage.visible, Eventually(Equals(True)))
3538
39 def select_single_retry(self, object_type, **kwargs):
40 """Returns the item that is searched for with app.select_single
41 In case of the item was not found (not created yet) a second attempt is
42 taken 1 second later."""
43 item = self.app.select_single(object_type, **kwargs)
44 tries = 10
45 while item is None and tries > 0:
46 sleep(0.2)
47 item = self.app.select_single(object_type, **kwargs)
48 tries = tries - 1
49 return item
50
36 def test_add_location(self):51 def test_add_location(self):
37 """Adds a location"""52 """Adds a location"""
38 self._open_add_location_page()53 self._open_add_location_page()
@@ -79,8 +94,7 @@
7994
80 # insert city name to search for95 # insert city name to search for
81 searchField = self.main_window.get_object("TextField", "SearchField")96 searchField = self.main_window.get_object("TextField", "SearchField")
82 self.pointing_device.move_to_object(searchField)97 self.pointing_device.click_object(searchField)
83 self.pointing_device.click()
84 self.keyboard.type("London")98 self.keyboard.type("London")
85 self.assertThat(searchField.text, Eventually(Equals("London")))99 self.assertThat(searchField.text, Eventually(Equals("London")))
86 self.keyboard.press_and_release('Enter')100 self.keyboard.press_and_release('Enter')
@@ -88,19 +102,19 @@
88 # wait for results and click on the first item102 # wait for results and click on the first item
89 resultsList = self.main_window.get_object('QQuickListView', 'SearchResultList')103 resultsList = self.main_window.get_object('QQuickListView', 'SearchResultList')
90 self.assertThat(resultsList.visible, Eventually(Equals(True), timeout=30))104 self.assertThat(resultsList.visible, Eventually(Equals(True), timeout=30))
91 firstResult = resultsList.get_children()[0].get_children()[0]105 firstResult = self.select_single_retry("Standard", objectName="searchResult0")
92 self.assertThat(firstResult.text, Eventually(Equals("London, GB")))106 self.assertThat(firstResult.text, Eventually(Equals("London, GB")))
93107
94 # clear search field and do another search108 # clear search field and do another search
95 for x in range(6):109 clear_button = searchField.select_single("AbstractButton")
96 self.keyboard.press_and_release('BackSpace')110 self.pointing_device.click_object(clear_button)
97 self.assertThat(searchField.text, Eventually(Equals("")))111 self.assertThat(searchField.text, Eventually(Equals("")))
112
113 self.pointing_device.click_object(searchField)
98 self.keyboard.type("Hamburg")114 self.keyboard.type("Hamburg")
99 self.keyboard.press_and_release('Enter')115 self.keyboard.press_and_release('Enter')
100 # move the cursor to gain some time116 self.assertThat(resultsList.visible, Eventually(Equals(True), timeout=30))
101 self.pointing_device.move_to_object(resultsList)117 firstResult = self.select_single_retry("Standard", objectName="searchResult0")
102 self.pointing_device.move_to_object(searchField)
103 firstResult = resultsList.get_children()[0].get_children()[0]
104 self.assertThat(firstResult.text, Eventually(Equals("Hamburg, DE")))118 self.assertThat(firstResult.text, Eventually(Equals("Hamburg, DE")))
105119
106 def test_cancel_adding_location(self):120 def test_cancel_adding_location(self):
@@ -140,19 +154,32 @@
140154
141 def _open_location_manager(self):155 def _open_location_manager(self):
142 """Opens the location manager"""156 """Opens the location manager"""
157 toolbar = self.main_window.get_toolbar()
143 self.main_window.open_toolbar()158 self.main_window.open_toolbar()
144 self.assertThat(self.main_window.get_toolbar().opened, Eventually(Equals(True)))159 self.assertThat(toolbar.animating, Eventually(Equals(False)))
160 self.assertThat(toolbar.state, Eventually(Equals("spread")))
145 self.main_window.click_toolbar_button("EditButton")161 self.main_window.click_toolbar_button("EditButton")
162 location_manager_sheet = self.main_window.get_object(
163 "ComposerSheet", "LocationManagerSheet")
164 self.assertThat(location_manager_sheet.opacity, Eventually(Equals(1)))
146165
147 def _swipe_location_to_remove(self):166 def _swipe_location_to_remove(self):
148 """Swipe right to delete the first location"""167 """Swipe right to delete the first location"""
149 locationList = self.main_window.get_object('QQuickListView', 'LocationList')168 number_of_locations = self._get_number_of_locations()
150 locItem = locationList.get_children()[0]169 firstLocation = self.app.select_single("Standard", objectName="existingLocation0")
151 loc_x, loc_y, loc_w, loc_h = locItem.globalRect170
152 self.pointing_device.move(loc_x + 10, loc_y + loc_h / 2)171 x, y, w, h = firstLocation.globalRect
153 self.pointing_device.press()172 tx = x + (w / 8)
154 self.pointing_device.move(loc_x + loc_w - 10, loc_y + loc_h / 2)173 ty = y + (h / 2)
155 self.pointing_device.release()174
175 self.pointing_device.drag(tx, ty, w - (w / 8), ty)
176 self.assertThat(
177 self._get_number_of_locations(),
178 Eventually(Equals(number_of_locations-1)))
179
180 def _get_number_of_locations(self):
181 qqlw = self.app.select_single("ComposerSheet").select_single("QQuickListView")
182 return qqlw.count
156183
157 def test_remove_location(self):184 def test_remove_location(self):
158 """Removes location"""185 """Removes location"""
@@ -173,7 +200,7 @@
173 load_indicator = self.main_window.get_object('ActivityIndicator', 'LoadingSpinner')200 load_indicator = self.main_window.get_object('ActivityIndicator', 'LoadingSpinner')
174 self.assertThat(load_indicator.running, Eventually(Equals(False)))201 self.assertThat(load_indicator.running, Eventually(Equals(False)))
175 tabObjects = self.main_window.get_objects('LocationTab','LocationTab')202 tabObjects = self.main_window.get_objects('LocationTab','LocationTab')
176 self.assertEqual(tabsSumStart-1, len(tabObjects))203 self.assertThat(lambda: tabsSumStart-1, Eventually(Equals(len(tabObjects))))
177204
178 def test_cancel_remove_location(self):205 def test_cancel_remove_location(self):
179 """Cancels removing of location"""206 """Cancels removing of location"""

Subscribers

People subscribed via source and target branches