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
1=== modified file 'components/AddLocationSheet.qml'
2--- components/AddLocationSheet.qml 2013-07-19 11:39:31 +0000
3+++ components/AddLocationSheet.qml 2013-08-04 02:28:28 +0000
4@@ -111,6 +111,7 @@
5 anchors.fill: parent;
6 model: citiesModel;
7 delegate: ListItem.Standard {
8+ objectName: "searchResult" + index
9 text: i18n.tr(name)+((country) ? ', '+i18n.tr(country): '');
10 progression: true;
11 onClicked: {
12
13=== modified file 'components/LocationManagerSheet.qml'
14--- components/LocationManagerSheet.qml 2013-07-23 21:20:11 +0000
15+++ components/LocationManagerSheet.qml 2013-08-04 02:28:28 +0000
16@@ -105,6 +105,7 @@
17 visible: false
18 text: i18n.tr("London")
19 control: Button {
20+ objectName: "currentLocationItem"
21 id: lookupItemAddButton
22 anchors.verticalCenter: parent.verticalCenter
23 text: i18n.tr("add")
24@@ -144,6 +145,7 @@
25 anchors.fill: parent
26 model: locationModel
27 delegate: ListItem.Standard {
28+ objectName: "existingLocation" + index
29 text: model.name
30 removable: true
31 onItemRemoved: {
32
33=== modified file 'tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py'
34--- tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py 2013-07-19 11:39:31 +0000
35+++ tests/autopilot/ubuntu_weather_app/tests/test_locationmanager.py 2013-08-04 02:28:28 +0000
36@@ -9,12 +9,15 @@
37
38 from __future__ import absolute_import
39
40-from testtools.matchers import Equals
41+from testtools.matchers import Equals, NotEquals
42 from autopilot.matchers import Eventually
43
44 from ubuntu_weather_app.tests import WeatherTestCase, DatabaseMixin, SheetMixin
45 from ubuntu_weather_app.tests.weatherdata import locations_data
46
47+from time import sleep
48+
49+
50 class TestLocationManager(WeatherTestCase, DatabaseMixin, SheetMixin):
51 def setUp(self):
52 self.clean_db()
53@@ -33,6 +36,18 @@
54 addLocPage = self.main_window.get_object("DefaultSheet", "AddLocationSheet")
55 self.assertThat(addLocPage.visible, Eventually(Equals(True)))
56
57+ def select_single_retry(self, object_type, **kwargs):
58+ """Returns the item that is searched for with app.select_single
59+ In case of the item was not found (not created yet) a second attempt is
60+ taken 1 second later."""
61+ item = self.app.select_single(object_type, **kwargs)
62+ tries = 10
63+ while item is None and tries > 0:
64+ sleep(0.2)
65+ item = self.app.select_single(object_type, **kwargs)
66+ tries = tries - 1
67+ return item
68+
69 def test_add_location(self):
70 """Adds a location"""
71 self._open_add_location_page()
72@@ -79,8 +94,7 @@
73
74 # insert city name to search for
75 searchField = self.main_window.get_object("TextField", "SearchField")
76- self.pointing_device.move_to_object(searchField)
77- self.pointing_device.click()
78+ self.pointing_device.click_object(searchField)
79 self.keyboard.type("London")
80 self.assertThat(searchField.text, Eventually(Equals("London")))
81 self.keyboard.press_and_release('Enter')
82@@ -88,19 +102,19 @@
83 # wait for results and click on the first item
84 resultsList = self.main_window.get_object('QQuickListView', 'SearchResultList')
85 self.assertThat(resultsList.visible, Eventually(Equals(True), timeout=30))
86- firstResult = resultsList.get_children()[0].get_children()[0]
87+ firstResult = self.select_single_retry("Standard", objectName="searchResult0")
88 self.assertThat(firstResult.text, Eventually(Equals("London, GB")))
89
90 # clear search field and do another search
91- for x in range(6):
92- self.keyboard.press_and_release('BackSpace')
93+ clear_button = searchField.select_single("AbstractButton")
94+ self.pointing_device.click_object(clear_button)
95 self.assertThat(searchField.text, Eventually(Equals("")))
96+
97+ self.pointing_device.click_object(searchField)
98 self.keyboard.type("Hamburg")
99 self.keyboard.press_and_release('Enter')
100- # move the cursor to gain some time
101- self.pointing_device.move_to_object(resultsList)
102- self.pointing_device.move_to_object(searchField)
103- firstResult = resultsList.get_children()[0].get_children()[0]
104+ self.assertThat(resultsList.visible, Eventually(Equals(True), timeout=30))
105+ firstResult = self.select_single_retry("Standard", objectName="searchResult0")
106 self.assertThat(firstResult.text, Eventually(Equals("Hamburg, DE")))
107
108 def test_cancel_adding_location(self):
109@@ -140,19 +154,32 @@
110
111 def _open_location_manager(self):
112 """Opens the location manager"""
113+ toolbar = self.main_window.get_toolbar()
114 self.main_window.open_toolbar()
115- self.assertThat(self.main_window.get_toolbar().opened, Eventually(Equals(True)))
116+ self.assertThat(toolbar.animating, Eventually(Equals(False)))
117+ self.assertThat(toolbar.state, Eventually(Equals("spread")))
118 self.main_window.click_toolbar_button("EditButton")
119+ location_manager_sheet = self.main_window.get_object(
120+ "ComposerSheet", "LocationManagerSheet")
121+ self.assertThat(location_manager_sheet.opacity, Eventually(Equals(1)))
122
123 def _swipe_location_to_remove(self):
124 """Swipe right to delete the first location"""
125- locationList = self.main_window.get_object('QQuickListView', 'LocationList')
126- locItem = locationList.get_children()[0]
127- loc_x, loc_y, loc_w, loc_h = locItem.globalRect
128- self.pointing_device.move(loc_x + 10, loc_y + loc_h / 2)
129- self.pointing_device.press()
130- self.pointing_device.move(loc_x + loc_w - 10, loc_y + loc_h / 2)
131- self.pointing_device.release()
132+ number_of_locations = self._get_number_of_locations()
133+ firstLocation = self.app.select_single("Standard", objectName="existingLocation0")
134+
135+ x, y, w, h = firstLocation.globalRect
136+ tx = x + (w / 8)
137+ ty = y + (h / 2)
138+
139+ self.pointing_device.drag(tx, ty, w - (w / 8), ty)
140+ self.assertThat(
141+ self._get_number_of_locations(),
142+ Eventually(Equals(number_of_locations-1)))
143+
144+ def _get_number_of_locations(self):
145+ qqlw = self.app.select_single("ComposerSheet").select_single("QQuickListView")
146+ return qqlw.count
147
148 def test_remove_location(self):
149 """Removes location"""
150@@ -173,7 +200,7 @@
151 load_indicator = self.main_window.get_object('ActivityIndicator', 'LoadingSpinner')
152 self.assertThat(load_indicator.running, Eventually(Equals(False)))
153 tabObjects = self.main_window.get_objects('LocationTab','LocationTab')
154- self.assertEqual(tabsSumStart-1, len(tabObjects))
155+ self.assertThat(lambda: tabsSumStart-1, Eventually(Equals(len(tabObjects))))
156
157 def test_cancel_remove_location(self):
158 """Cancels removing of location"""

Subscribers

People subscribed via source and target branches