Bug 1368767 - Fix race condition in test_set_location_through_execute_script. draft
authorHenrik Skupin <mail@hskupin.info>
Mon, 09 Apr 2018 16:07:15 +0200
changeset 779219 e68d1f22cf4669f23ab716a3c5162e9a05d5c930
parent 779136 f892607541ebeb4416aab16803c86807b6b76059
push id105702
push userbmo:hskupin@gmail.com
push dateMon, 09 Apr 2018 14:07:47 +0000
bugs1368767
milestone61.0a1
Bug 1368767 - Fix race condition in test_set_location_through_execute_script. Using get_url() to wait for a page load to be done doesn't work because it already returns when the location bar gets updated. Instead wait for a known element of the page. MozReview-Commit-ID: CdYux8sTAiP
testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py
@@ -114,24 +114,30 @@ class BaseNavigationTestCase(WindowManag
     def ready_state(self):
         return self.marionette.execute_script("return window.document.readyState;",
                                               sandbox=None)
 
 
 class TestNavigate(BaseNavigationTestCase):
 
     def test_set_location_through_execute_script(self):
+        test_element_locator = (By.ID, "testh1")
+
         self.marionette.execute_script(
             "window.location.href = arguments[0];",
             script_args=(self.test_page_remote,), sandbox=None)
 
+        # We cannot use get_url() to wait until the target page has been loaded,
+        # because it will return the URL of the top browsing context and doesn't
+        # wait for the page load to be complete.
         Wait(self.marionette, timeout=self.marionette.timeout.page_load).until(
-            lambda mn: self.test_page_remote == mn.get_url(),
-            message="'{}' hasn't been loaded".format(self.test_page_remote))
-        self.assertEqual("Marionette Test", self.marionette.title)
+            expected.element_present(*test_element_locator),
+            message="Target element 'testh1' has not been found")
+
+        self.assertEqual(self.test_page_remote, self.marionette.get_url())
 
     def test_navigate_chrome_unsupported_error(self):
         with self.marionette.using_context("chrome"):
             self.assertRaises(errors.UnsupportedOperationException,
                               self.marionette.navigate, "about:blank")
             self.assertRaises(errors.UnsupportedOperationException, self.marionette.go_back)
             self.assertRaises(errors.UnsupportedOperationException, self.marionette.go_forward)
             self.assertRaises(errors.UnsupportedOperationException, self.marionette.refresh)