Merge lp:~canonical-platform-qa/webbrowser-app/autopilot-back-forward into lp:webbrowser-app

Proposed by Leo Arias
Status: Merged
Approved by: Olivier Tilloy
Approved revision: 852
Merged at revision: 859
Proposed branch: lp:~canonical-platform-qa/webbrowser-app/autopilot-back-forward
Merge into: lp:webbrowser-app
Prerequisite: lp:~canonical-platform-qa/webbrowser-app/autopilot-address_bar-textfield
Diff against target: 280 lines (+77/-55)
10 files modified
tests/autopilot/webbrowser_app/emulators/browser.py (+38/-5)
tests/autopilot/webbrowser_app/tests/__init__.py (+1/-13)
tests/autopilot/webbrowser_app/tests/test_addressbar_bookmark.py (+1/-1)
tests/autopilot/webbrowser_app/tests/test_backforward.py (+26/-23)
tests/autopilot/webbrowser_app/tests/test_content_pick.py (+1/-1)
tests/autopilot/webbrowser_app/tests/test_errorsheet.py (+5/-7)
tests/autopilot/webbrowser_app/tests/test_fullscreen.py (+1/-1)
tests/autopilot/webbrowser_app/tests/test_geolocation.py (+1/-1)
tests/autopilot/webbrowser_app/tests/test_selection.py (+1/-1)
tests/autopilot/webbrowser_app/tests/test_tabs.py (+2/-2)
To merge this branch: bzr merge lp:~canonical-platform-qa/webbrowser-app/autopilot-back-forward
Reviewer Review Type Date Requested Status
Olivier Tilloy Approve
PS Jenkins bot continuous-integration Needs Fixing
Allan LeSage (community) Approve
Richard Huddie (community) Approve
Review via email: mp+244665@code.launchpad.net

Commit message

Expose on the autopilot helpers the back and forward functionality.

Description of the change

We are automating part of the sanity test suite. In that suite, there is one test that clicks back and then forward on the browser.
In order for those tests to work, we need stable, tested and readable helpers from the browser custom proxy objects.
By calling the methods with a name that reflects clearly what is the user action, as suggested by the page object pattern, we enable this higher level testing of the browser in combination with other projects.

To post a comment you must log in.
Revision history for this message
Richard Huddie (rhuddie) wrote :

This looks good to me.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Allan LeSage (allanlesage) wrote :

Again nothing to add to the POM style adjustments, confirm that the changed tests pass locally--the Jenkins failure appears unrelated and should be pursued with CI as it'll block this landing. . . .

review: Approve
Revision history for this message
Olivier Tilloy (osomon) wrote :

Since you removed the assert_page_eventually_loaded() method, while you’re at it can you also remove the assert_page_eventually_loading() method? I see that it’s not used anywhere any longer.

Revision history for this message
Olivier Tilloy (osomon) wrote :

The changes you made to test_opening_new_page_enables_back_button() and test_navigating_back_enables_forward_button() are not semantically equivalent:

141 - self.assertThat(back_button.enabled, Eventually(Equals(True)))
143 + self.main_window.go_back()
144 + self.assert_home_page_eventually_loaded()

We don’t want to actually go back, we only want to verify that the back button is *eventually* enabled (which the go_back() method doesn’t do). And the is_back_button_enabled() method doesn’t contemplate a possible delay (that would translate into the use of an Eventually() matcher).

review: Needs Fixing
Revision history for this message
Olivier Tilloy (osomon) wrote :

The rest of the changes look good to me.

850. By Leo Arias

Remove unused method.

Revision history for this message
Leo Arias (elopio) wrote :

> Since you removed the assert_page_eventually_loaded() method, while you’re at
> it can you also remove the assert_page_eventually_loading() method? I see that
> it’s not used anywhere any longer.

Done.

851. By Leo Arias

Renamed the back and forward tests. Added waits for the buttons to be enabled.

852. By Leo Arias

Fixed typo.

Revision history for this message
Leo Arias (elopio) wrote :

> The changes you made to test_opening_new_page_enables_back_button() and
> test_navigating_back_enables_forward_button() are not semantically equivalent:
>
> 141 - self.assertThat(back_button.enabled,
> Eventually(Equals(True)))
> 143 + self.main_window.go_back()
> 144 + self.assert_home_page_eventually_loaded()
>
> We don’t want to actually go back, we only want to verify that the back button
> is *eventually* enabled (which the go_back() method doesn’t do). And the
> is_back_button_enabled() method doesn’t contemplate a possible delay (that
> would translate into the use of an Eventually() matcher).

I renamed the tests and added waits in the go methods.
The tests pass here, and I've triggered a new jenkins run to confirm that.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Leo Arias (elopio) wrote :

The failures are on settle. All the tests are passing.

Revision history for this message
Olivier Tilloy (osomon) wrote :

Looks good to me now, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/webbrowser_app/emulators/browser.py'
2--- tests/autopilot/webbrowser_app/emulators/browser.py 2014-12-18 15:53:25 +0000
3+++ tests/autopilot/webbrowser_app/emulators/browser.py 2014-12-18 15:53:25 +0000
4@@ -47,15 +47,28 @@
5 self.chrome = self._get_chrome()
6 self.address_bar = self.chrome.address_bar
7
8+ def _get_chrome(self):
9+ return self.select_single(Chrome)
10+
11 def go_to_url(self, url):
12 self.address_bar.go_to_url(url)
13
14+ def wait_until_page_loaded(self, url):
15+ webview = self.get_current_webview()
16+ webview.url.wait_for(url)
17+ # loadProgress == 100 ensures that a page has actually loaded
18+ webview.loadProgress.wait_for(100, timeout=20)
19+ webview.loading.wait_for(False)
20+
21+ def go_back(self):
22+ self.chrome.go_back()
23+
24+ def go_forward(self):
25+ self.chrome.go_forward()
26+
27 def get_window(self):
28 return self.get_parent()
29
30- def _get_chrome(self):
31- return self.select_single(Chrome)
32-
33 def get_current_webview(self):
34 return self.select_single("WebViewImpl", current=True)
35
36@@ -102,12 +115,32 @@
37 def _get_address_bar(self):
38 return self.select_single(AddressBar)
39
40- def get_back_button(self):
41+ @autopilot.logging.log_action(logger.info)
42+ def go_back(self):
43+ back_button = self._get_back_button()
44+ back_button.enabled.wait_for(True)
45+ self.pointing_device.click_object(back_button)
46+
47+ def _get_back_button(self):
48 return self.select_single("ChromeButton", objectName="backButton")
49
50- def get_forward_button(self):
51+ def is_back_button_enabled(self):
52+ back_button = self._get_back_button()
53+ return back_button.enabled
54+
55+ @autopilot.logging.log_action(logger.info)
56+ def go_forward(self):
57+ forward_button = self._get_forward_button()
58+ forward_button.enabled.wait_for(True)
59+ self.pointing_device.click_object(forward_button)
60+
61+ def _get_forward_button(self):
62 return self.select_single("ChromeButton", objectName="forwardButton")
63
64+ def is_forward_button_enabled(self):
65+ forward_button = self._get_forward_button()
66+ return forward_button.enabled
67+
68 def get_drawer_button(self):
69 return self.select_single("ChromeButton", objectName="drawerButton")
70
71
72=== modified file 'tests/autopilot/webbrowser_app/tests/__init__.py'
73--- tests/autopilot/webbrowser_app/tests/__init__.py 2014-12-18 15:53:25 +0000
74+++ tests/autopilot/webbrowser_app/tests/__init__.py 2014-12-18 15:53:25 +0000
75@@ -87,18 +87,6 @@
76 def main_window(self):
77 return self.app.main_window
78
79- def assert_page_eventually_loading(self):
80- webview = self.main_window.get_current_webview()
81- self.assertThat(webview.loading, Eventually(Equals(True)))
82-
83- def assert_page_eventually_loaded(self, url):
84- webview = self.main_window.get_current_webview()
85- self.assertThat(webview.url, Eventually(Equals(url)))
86- # loadProgress == 100 ensures that a page has actually loaded
87- self.assertThat(webview.loadProgress,
88- Eventually(Equals(100), timeout=20))
89- self.assertThat(webview.loading, Eventually(Equals(False)))
90-
91 def open_tabs_view(self):
92 chrome = self.main_window.chrome
93 drawer_button = chrome.get_drawer_button()
94@@ -157,4 +145,4 @@
95 self.assert_home_page_eventually_loaded()
96
97 def assert_home_page_eventually_loaded(self):
98- self.assert_page_eventually_loaded(self.url)
99+ self.main_window.wait_until_page_loaded(self.url)
100
101=== modified file 'tests/autopilot/webbrowser_app/tests/test_addressbar_bookmark.py'
102--- tests/autopilot/webbrowser_app/tests/test_addressbar_bookmark.py 2014-12-18 15:53:25 +0000
103+++ tests/autopilot/webbrowser_app/tests/test_addressbar_bookmark.py 2014-12-18 15:53:25 +0000
104@@ -37,7 +37,7 @@
105 self.open_new_tab()
106 url = self.base_url + "/test2"
107 self.main_window.go_to_url(url)
108- self.assert_page_eventually_loaded(url)
109+ self.main_window.wait_until_page_loaded(url)
110 self.assertThat(chrome.bookmarked, Eventually(Equals(False)))
111
112 self.open_tabs_view()
113
114=== modified file 'tests/autopilot/webbrowser_app/tests/test_backforward.py'
115--- tests/autopilot/webbrowser_app/tests/test_backforward.py 2014-12-18 15:53:25 +0000
116+++ tests/autopilot/webbrowser_app/tests/test_backforward.py 2014-12-18 15:53:25 +0000
117@@ -15,7 +15,6 @@
118 # along with this program. If not, see <http://www.gnu.org/licenses/>.
119
120 from testtools.matchers import Equals
121-from autopilot.matchers import Eventually
122
123 from webbrowser_app.tests import StartOpenRemotePageTestCaseBase
124
125@@ -24,26 +23,30 @@
126
127 """Tests the back and forward functionality."""
128
129+ def setUp(self):
130+ super().setUp()
131+ self.chrome = self.main_window.chrome
132+
133 def test_homepage_no_history(self):
134- chrome = self.main_window.chrome
135- self.assertThat(chrome.get_back_button().enabled, Equals(False))
136- self.assertThat(chrome.get_forward_button().enabled, Equals(False))
137-
138- def test_opening_new_page_enables_back_button(self):
139- back_button = self.main_window.chrome.get_back_button()
140- self.assertThat(back_button.enabled, Equals(False))
141- url = self.base_url + "/test2"
142- self.main_window.go_to_url(url)
143- self.assert_page_eventually_loaded(url)
144- self.assertThat(back_button.enabled, Eventually(Equals(True)))
145-
146- def test_navigating_back_enables_forward_button(self):
147- url = self.base_url + "/test2"
148- self.main_window.go_to_url(url)
149- self.assert_page_eventually_loaded(url)
150- chrome = self.main_window.chrome
151- forward_button = chrome.get_forward_button()
152- self.assertThat(forward_button.enabled, Equals(False))
153- self.pointing_device.click_object(chrome.get_back_button())
154- self.assert_home_page_eventually_loaded()
155- self.assertThat(forward_button.enabled, Eventually(Equals(True)))
156+ self.assertThat(self.chrome.is_back_button_enabled(), Equals(False))
157+ self.assertThat(self.chrome.is_forward_button_enabled(), Equals(False))
158+
159+ def test_go_back_after_opening_a_new_page(self):
160+ """Test that the back button must open the previous page."""
161+ self.assertThat(self.chrome.is_back_button_enabled(), Equals(False))
162+ url = self.base_url + "/test2"
163+ self.main_window.go_to_url(url)
164+ self.main_window.wait_until_page_loaded(url)
165+ self.main_window.go_back()
166+ self.assert_home_page_eventually_loaded()
167+
168+ def test_go_forward_after_going_back(self):
169+ """Test that the forward button must open the previous page."""
170+ url = self.base_url + "/test2"
171+ self.main_window.go_to_url(url)
172+ self.main_window.wait_until_page_loaded(url)
173+ self.assertThat(self.chrome.is_forward_button_enabled(), Equals(False))
174+ self.main_window.go_back()
175+ self.assert_home_page_eventually_loaded()
176+ self.main_window.go_forward()
177+ self.main_window.wait_until_page_loaded(url)
178
179=== modified file 'tests/autopilot/webbrowser_app/tests/test_content_pick.py'
180--- tests/autopilot/webbrowser_app/tests/test_content_pick.py 2014-12-18 15:53:25 +0000
181+++ tests/autopilot/webbrowser_app/tests/test_content_pick.py 2014-12-18 15:53:25 +0000
182@@ -30,7 +30,7 @@
183 def test_picker_dialog_shows_up(self):
184 url = self.base_url + "/uploadform"
185 self.main_window.go_to_url(url)
186- self.assert_page_eventually_loaded(url)
187+ self.main_window.wait_until_page_loaded(url)
188 webview = self.main_window.get_current_webview()
189 self.pointing_device.click_object(webview)
190 dialog = self.main_window.get_content_picker_dialog()
191
192=== modified file 'tests/autopilot/webbrowser_app/tests/test_errorsheet.py'
193--- tests/autopilot/webbrowser_app/tests/test_errorsheet.py 2014-12-18 15:53:25 +0000
194+++ tests/autopilot/webbrowser_app/tests/test_errorsheet.py 2014-12-18 15:53:25 +0000
195@@ -43,19 +43,17 @@
196 error = self.main_window.get_error_sheet()
197 self.main_window.go_to_url(INVALID_URL)
198 self.assertThat(error.visible, Eventually(Equals(True)))
199- chrome = self.main_window.chrome
200- self.pointing_device.click_object(chrome.get_back_button())
201+ self.main_window.go_back()
202 self.assertThat(error.visible, Eventually(Equals(False)))
203
204 def test_navigating_forward_discards_error_message(self):
205 error = self.main_window.get_error_sheet()
206 self.main_window.go_to_url(INVALID_URL)
207- self.assert_page_eventually_loaded(INVALID_URL)
208+ self.main_window.wait_until_page_loaded(INVALID_URL)
209 url = self.base_url + "/test2"
210 self.main_window.go_to_url(url)
211- self.assert_page_eventually_loaded(url)
212- chrome = self.main_window.chrome
213- self.pointing_device.click_object(chrome.get_back_button())
214+ self.main_window.wait_until_page_loaded(url)
215+ self.main_window.go_back()
216 self.assertThat(error.visible, Eventually(Equals(True)))
217- self.pointing_device.click_object(chrome.get_forward_button())
218+ self.main_window.go_forward()
219 self.assertThat(error.visible, Eventually(Equals(False)))
220
221=== modified file 'tests/autopilot/webbrowser_app/tests/test_fullscreen.py'
222--- tests/autopilot/webbrowser_app/tests/test_fullscreen.py 2014-12-18 15:53:25 +0000
223+++ tests/autopilot/webbrowser_app/tests/test_fullscreen.py 2014-12-18 15:53:25 +0000
224@@ -41,7 +41,7 @@
225 self.assert_eventually_windowed()
226 url = self.base_url + "/fullscreen"
227 self.main_window.go_to_url(url)
228- self.assert_page_eventually_loaded(url)
229+ self.main_window.wait_until_page_loaded(url)
230 self.assert_eventually_windowed()
231 webview = self.main_window.get_current_webview()
232 self.pointing_device.click_object(webview)
233
234=== modified file 'tests/autopilot/webbrowser_app/tests/test_geolocation.py'
235--- tests/autopilot/webbrowser_app/tests/test_geolocation.py 2014-12-18 15:53:25 +0000
236+++ tests/autopilot/webbrowser_app/tests/test_geolocation.py 2014-12-18 15:53:25 +0000
237@@ -23,7 +23,7 @@
238 super(TestGeolocation, self).setUp()
239 url = self.base_url + "/geolocation"
240 self.main_window.go_to_url(url)
241- self.assert_page_eventually_loaded(url)
242+ self.main_window.wait_until_page_loaded(url)
243 self.dialog = self.main_window.get_geolocation_dialog()
244
245 def tearDown(self):
246
247=== modified file 'tests/autopilot/webbrowser_app/tests/test_selection.py'
248--- tests/autopilot/webbrowser_app/tests/test_selection.py 2014-12-18 15:53:25 +0000
249+++ tests/autopilot/webbrowser_app/tests/test_selection.py 2014-12-18 15:53:25 +0000
250@@ -28,7 +28,7 @@
251 super(TestSelection, self).setUp()
252 url = self.base_url + "/selection"
253 self.main_window.go_to_url(url)
254- self.assert_page_eventually_loaded(url)
255+ self.main_window.wait_until_page_loaded(url)
256 webview = self.main_window.get_current_webview()
257 self.pointing_device.move_to_object(webview)
258 if model() == 'Desktop':
259
260=== modified file 'tests/autopilot/webbrowser_app/tests/test_tabs.py'
261--- tests/autopilot/webbrowser_app/tests/test_tabs.py 2014-12-18 15:53:25 +0000
262+++ tests/autopilot/webbrowser_app/tests/test_tabs.py 2014-12-18 15:53:25 +0000
263@@ -129,7 +129,7 @@
264 def test_open_target_blank_in_new_tab(self):
265 url = self.base_url + "/blanktargetlink"
266 self.main_window.go_to_url(url)
267- self.assert_page_eventually_loaded(url)
268+ self.main_window.wait_until_page_loaded(url)
269 webview = self.main_window.get_current_webview()
270 self.pointing_device.click_object(webview)
271 self.check_current_tab(self.base_url + "/test2")
272@@ -138,7 +138,7 @@
273 def test_open_iframe_target_blank_in_new_tab(self):
274 url = self.base_url + "/fulliframewithblanktargetlink"
275 self.main_window.go_to_url(url)
276- self.assert_page_eventually_loaded(url)
277+ self.main_window.wait_until_page_loaded(url)
278 webview = self.main_window.get_current_webview()
279 self.pointing_device.click_object(webview)
280 self.check_current_tab(self.base_url + "/test2")

Subscribers

People subscribed via source and target branches

to status/vote changes: