Bug 1368526 - Wait for the page to be loaded in a newly opened tab/window. draft
authorHenrik Skupin <mail@hskupin.info>
Tue, 30 May 2017 11:25:21 +0200
changeset 586485 cd0763f2be5710244b2e60c816b49283c5dddfbc
parent 586049 34ac1a5d6576d6775491c8a882710a1520551da6
child 631008 c41459a6ba622df67fc4e7c7485df5b5c403fdb0
push id61426
push userbmo:hskupin@gmail.com
push dateTue, 30 May 2017 14:39:39 +0000
bugs1368526
milestone55.0a1
Bug 1368526 - Wait for the page to be loaded in a newly opened tab/window. If a web page gets opened in a new tab or window, there is no way for the navigate command to check the current page load status. Instead we have to wait until the correct URL is getting reported. MozReview-Commit-ID: JQhPXRgh5Ae
testing/marionette/harness/marionette_harness/tests/unit/test_window_handles_chrome.py
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_handles_chrome.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_handles_chrome.py
@@ -1,15 +1,15 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import types
 
-from marionette_driver import By, errors
+from marionette_driver import By, errors, Wait
 
 from marionette_harness import MarionetteTestCase, WindowManagerMixin
 
 
 class TestWindowHandles(WindowManagerMixin, MarionetteTestCase):
 
     def setUp(self):
         super(TestWindowHandles, self).setUp()
@@ -74,17 +74,19 @@ class TestWindowHandles(WindowManagerMix
         self.assertEqual(len(self.marionette.chrome_window_handles), len(self.start_windows) + 1)
         self.assertEqual(self.marionette.current_chrome_window_handle, self.start_window)
 
         # Check that the new tab has the correct page loaded
         self.marionette.switch_to_window(new_win)
         self.assert_window_handles()
         self.assertEqual(self.marionette.current_chrome_window_handle, new_win)
         with self.marionette.using_context("content"):
-            self.assertEqual(self.marionette.get_url(), self.empty_page)
+            Wait(self.marionette, timeout=self.marionette.timeout.page_load).until(
+                lambda mn: mn.get_url() == self.empty_page,
+                message="{} did not load after opening a new tab".format(self.empty_page))
 
         # Ensure navigate works in our current window
         other_page = self.marionette.absolute_url("test.html")
         with self.marionette.using_context("content"):
             self.marionette.navigate(other_page)
             self.assertEqual(self.marionette.get_url(), other_page)
 
         # Close the opened window and carry on in our original tab.
@@ -108,17 +110,19 @@ class TestWindowHandles(WindowManagerMix
         self.assert_window_handles()
         self.assertEqual(len(self.marionette.window_handles), len(self.start_tabs) + 1)
         self.assertEqual(self.marionette.current_window_handle, self.start_tab)
 
         self.marionette.switch_to_window(new_tab)
         self.assert_window_handles()
         self.assertEqual(self.marionette.current_window_handle, new_tab)
         with self.marionette.using_context("content"):
-            self.assertEqual(self.marionette.get_url(), self.empty_page)
+            Wait(self.marionette, timeout=self.marionette.timeout.page_load).until(
+                lambda mn: mn.get_url() == self.empty_page,
+                message="{} did not load after opening a new tab".format(self.empty_page))
 
         # Ensure navigate works in our current tab
         other_page = self.marionette.absolute_url("test.html")
         with self.marionette.using_context("content"):
             self.marionette.navigate(other_page)
             self.assertEqual(self.marionette.get_url(), other_page)
 
         self.marionette.switch_to_window(self.start_tab)
@@ -147,17 +151,19 @@ class TestWindowHandles(WindowManagerMix
         self.assertEqual(len(self.marionette.window_handles), len(self.start_tabs) + 1)
         self.assertEqual(self.marionette.current_window_handle, self.start_tab)
 
         # Check that the new tab has the correct page loaded
         self.marionette.switch_to_window(new_tab)
         self.assert_window_handles()
         self.assertEqual(self.marionette.current_window_handle, new_tab)
         with self.marionette.using_context("content"):
-            self.assertEqual(self.marionette.get_url(), self.empty_page)
+            Wait(self.marionette, timeout=self.marionette.timeout.page_load).until(
+                lambda mn: mn.get_url() == self.empty_page,
+                message="{} did not load after opening a new tab".format(self.empty_page))
 
         # Ensure navigate works in our current window
         other_page = self.marionette.absolute_url("test.html")
         with self.marionette.using_context("content"):
             self.marionette.navigate(other_page)
             self.assertEqual(self.marionette.get_url(), other_page)
 
         # Close the opened window and carry on in our original tab.
@@ -185,17 +191,19 @@ class TestWindowHandles(WindowManagerMix
         self.marionette.close()
         self.assert_window_handles()
         self.assertEqual(len(self.marionette.window_handles), len(self.start_tabs))
 
         self.marionette.switch_to_window(new_tab)
         self.assert_window_handles()
         self.assertEqual(self.marionette.current_window_handle, new_tab)
         with self.marionette.using_context("content"):
-            self.assertEqual(self.marionette.get_url(), self.empty_page)
+            Wait(self.marionette, timeout=self.marionette.timeout.page_load).until(
+                lambda mn: mn.get_url() == self.empty_page,
+                message="{} did not load after opening a new tab".format(self.empty_page))
 
     def test_window_handles_no_switch(self):
         """Regression test for bug 1294456.
         This test is testing the case where Marionette attempts to send a
         command to a window handle when the browser has opened and selected
         a new tab. Before bug 1294456 landed, the Marionette driver was getting
         confused about which window handle the client cared about, and assumed
         it was the window handle for the newly opened and selected tab.