Bug 1290806 - Fix TestSwitchWindow.test_windows by waiting for the newly opened window.
MozReview-Commit-ID: 750cIdl27CZ
--- a/testing/marionette/harness/marionette/tests/unit/test_window_management.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_window_management.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 time
from marionette import MarionetteTestCase
-from marionette_driver.by import By
+from marionette_driver import By, Wait
class TestSwitchWindow(MarionetteTestCase):
def open_new_window(self):
self.marionette.set_context("chrome")
self.marionette.set_script_timeout(5000)
self.marionette.execute_async_script("""
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
@@ -36,17 +36,19 @@ if (win != null)
def test_windows(self):
orig_win = self.marionette.current_window_handle
orig_available = self.marionette.window_handles
self.open_new_window()
#assert we're still in the original window
self.assertEqual(self.marionette.current_window_handle, orig_win)
now_available = self.marionette.window_handles
#assert we can find the new window
- self.assertEqual(len(now_available), len(orig_available) + 1)
+ Wait(self.marionette).until(
+ lambda _: len(now_available) == len(orig_available) + 1,
+ message="The new window has not been opened.")
#assert that our window is there
self.assertTrue(orig_win in now_available)
new_win = None
for win in now_available:
if win != orig_win:
new_win = orig_win
#switch to another window
self.marionette.switch_to_window(new_win)