--- 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.