Bug 1290806 - Fix TestSwitchWindow.test_windows by waiting for the newly opened window. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 08 Sep 2016 18:00:36 +0200
changeset 413649 f6e205227b895de095c1c3e41560f8b011749eff
parent 413053 f5d043ce6d36a3c461cbd829d4a4a38394b7c436
child 531257 93b6a98955f1804ee8dfe0e1291af4899abe074e
push id29462
push userbmo:hskupin@gmail.com
push dateWed, 14 Sep 2016 15:32:52 +0000
bugs1290806
milestone51.0a1
Bug 1290806 - Fix TestSwitchWindow.test_windows by waiting for the newly opened window. MozReview-Commit-ID: 750cIdl27CZ
testing/marionette/harness/marionette/tests/unit/test_window_management.py
--- 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)