Bug 1368526 - Wait for the page to be loaded in a newly opened tab/window. r=ato, a=test-only
authorHenrik Skupin <mail@hskupin.info>
Tue, 30 May 2017 11:25:21 +0200
changeset 396478 09f9827c36d63365507fa3999e66c298eed81808
parent 396477 d47466614ea1ea1a4d9c64ff943a0a3670291529
child 396479 077bea1fbaf2f76c3356c47043e3eaba802062fc
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1368526
milestone54.0
Bug 1368526 - Wait for the page to be loaded in a newly opened tab/window. r=ato, a=test-only 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
@@ -55,17 +55,19 @@ class TestWindowHandles(WindowManagerMix
         new_win = self.open_window(trigger=open_with_link)
         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.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.
@@ -85,17 +87,19 @@ class TestWindowHandles(WindowManagerMix
 
         new_tab = self.open_tab(trigger=open_with_link)
         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.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)
@@ -120,17 +124,19 @@ class TestWindowHandles(WindowManagerMix
         new_tab = self.open_tab(trigger=open_with_link)
         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.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.
@@ -153,17 +159,19 @@ class TestWindowHandles(WindowManagerMix
         self.assertEqual(self.marionette.current_window_handle, self.start_tab)
 
         self.marionette.close()
         self.assertEqual(len(self.marionette.window_handles), len(self.start_tabs))
 
         self.marionette.switch_to_window(new_tab)
         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.