Bug 1368767 - Fix race condition in test_set_location_through_execute_script. r=ato a=test-only
authorHenrik Skupin <mail@hskupin.info>
Mon, 09 Apr 2018 16:07:15 +0200
changeset 463137 463126f49ddcf84bec22efe85ade6548b18c88dd
parent 463136 9ef40c935262a5af12474cfb34cb9c95f9222ba7
child 463138 2a948d61629384c23fbbf9187468cc00ebdcef81
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1368767
milestone60.0
Bug 1368767 - Fix race condition in test_set_location_through_execute_script. r=ato a=test-only 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
@@ -108,24 +108,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)