Bug 1368767 - Fix race condition in test_set_location_through_execute_script. r=ato
authorHenrik Skupin <mail@hskupin.info>
Mon, 09 Apr 2018 16:07:15 +0200
changeset 457389 4f6778d6135cfc33119f167a31c42c020cab5b6c
parent 457388 031bed4cc2cd9776ae817d2cffb51986fc1dd1bb
child 457390 b5065c61bbd78a43d3a8dfa4d6531d2071e2fbc8
push id153
push userfmarier@mozilla.com
push dateTue, 10 Apr 2018 02:28:40 +0000
reviewersato
bugs1368767
milestone61.0a1
Bug 1368767 - Fix race condition in test_set_location_through_execute_script. r=ato 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)