Bug 1354310 - Ensure to use page load timeout for Wait().until() in unit tests. r=ato a=test-only
authorHenrik Skupin <mail@hskupin.info>
Fri, 07 Apr 2017 09:26:23 +0200
changeset 379510 0fe6857edafffdf71681d78b52d30802a287ebe9
parent 379509 f770bcf06b7b032c590aedaab07b87904e2210b3
child 379511 55b6fa40ef642b91c69b0f7e25d42d0809ae477d
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1354310
milestone53.0
Bug 1354310 - Ensure to use page load timeout for Wait().until() in unit tests. r=ato a=test-only Tests which have to wait for a page being loaded should always use a timeout as set via self.marionette.timeout.page_load. MozReview-Commit-ID: HFTOYy6WYNk
testing/marionette/harness/marionette_harness/tests/unit/test_click.py
testing/marionette/harness/marionette_harness/tests/unit/test_file_upload.py
testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py
testing/marionette/harness/marionette_harness/tests/unit/test_switch_window_content.py
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_click.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_click.py
@@ -92,32 +92,40 @@ class TestLegacyClick(MarionetteTestCase
         button = self.marionette.find_element(By.TAG_NAME, "button")
         button.click()
         self.assertEqual(1, self.marionette.execute_script("return window.clicks", sandbox=None))
 
     def test_click_number_link(self):
         test_html = self.marionette.absolute_url("clicks.html")
         self.marionette.navigate(test_html)
         self.marionette.find_element(By.LINK_TEXT, "333333").click()
-        Wait(self.marionette, timeout=30, ignored_exceptions=errors.NoSuchElementException).until(
-            lambda m: m.find_element(By.ID, "username"))
+        # Bug 1335778 - Missing implicit wait for page being loaded
+        Wait(self.marionette, timeout=self.marionette.timeout.page_load,
+             ignored_exceptions=errors.NoSuchElementException).until(
+            lambda m: m.find_element(By.ID, "username"),
+            message="Username field hasn't been found")
         self.assertEqual(self.marionette.title, "XHTML Test Page")
 
     def test_clicking_an_element_that_is_not_displayed_raises(self):
         test_html = self.marionette.absolute_url("hidden.html")
         self.marionette.navigate(test_html)
 
         with self.assertRaises(errors.ElementNotInteractableException):
             self.marionette.find_element(By.ID, "child").click()
 
     def test_clicking_on_a_multiline_link(self):
         test_html = self.marionette.absolute_url("clicks.html")
         self.marionette.navigate(test_html)
         self.marionette.find_element(By.ID, "overflowLink").click()
-        self.wait_for_condition(lambda mn: self.marionette.title == "XHTML Test Page")
+        # Bug 1335778 - Missing implicit wait for page being loaded
+        Wait(self.marionette, timeout=self.marionette.timeout.page_load,
+             ignored_exceptions=errors.NoSuchElementException).until(
+            lambda m: m.find_element(By.ID, "username"),
+            message="Username field hasn't been found")
+        self.assertEqual(self.marionette.title, "XHTML Test Page")
 
     def test_scroll_into_view_near_end(self):
         self.marionette.navigate(fixed_overlay)
         link = self.marionette.find_element(By.TAG_NAME, "a")
         link.click()
         self.assertTrue(self.marionette.execute_script("return window.clicked", sandbox=None))
 
 
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_file_upload.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_file_upload.py
@@ -97,17 +97,19 @@ class TestFileUpload(MarionetteTestCase)
         url = self.marionette.get_url()
 
         with tempfile() as f:
             f.write("camembert")
             f.flush()
             self.input.send_keys(f.name)
             self.submit.click()
 
-        Wait(self.marionette).until(lambda m: m.get_url() != url)
+        Wait(self.marionette, timeout=self.marionette.timeout.page_load).until(
+            lambda m: m.get_url() != url,
+            message="URL didn't change after submitting a file upload")
         self.assertIn("multipart/form-data", self.body.text)
 
     def test_change_event(self):
         self.marionette.navigate(single)
         self.marionette.execute_script("""
             window.changeEvs = [];
             let el = arguments[arguments.length - 1];
             el.addEventListener("change", ev => window.changeEvs.push(ev));
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py
@@ -92,20 +92,22 @@ class BaseNavigationTestCase(WindowManag
               return tabBrowser.isRemoteBrowser;
             """)
 
 
 class TestNavigate(BaseNavigationTestCase):
 
     def test_set_location_through_execute_script(self):
         self.marionette.execute_script(
-            "window.location.href = '{}'".format(self.test_page_remote),
-            sandbox=None)
-        Wait(self.marionette).until(
-            lambda mn: self.test_page_remote == mn.get_url())
+            "window.location.href = arguments[0];",
+            script_args=(self.test_page_remote,), sandbox=None)
+
+        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)
 
     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)
@@ -216,51 +218,52 @@ class TestNavigate(BaseNavigationTestCas
         self.assertFalse(self.is_remote_tab)
 
         with self.marionette.using_context("chrome"):
             urlbar = self.marionette.find_element(By.ID, "urlbar")
             urlbar.send_keys(self.mod_key + "a")
             urlbar.send_keys(self.mod_key + "x")
             urlbar.send_keys("about:support" + Keys.ENTER)
 
-        Wait(self.marionette).until(
+        Wait(self.marionette, timeout=self.marionette.timeout.page_load).until(
             lambda mn: mn.get_url() == "about:support",
             message="'about:support' hasn't been loaded")
         self.assertFalse(self.is_remote_tab)
 
     @skip_if_mobile("Interacting with chrome elements not available for Fennec")
     @run_if_e10s("Requires e10s mode enabled")
     def test_type_to_remote_tab(self):
         self.assertTrue(self.is_remote_tab)
 
         with self.marionette.using_context("chrome"):
             urlbar = self.marionette.find_element(By.ID, "urlbar")
             urlbar.send_keys(self.mod_key + "a")
             urlbar.send_keys(self.mod_key + "x")
             urlbar.send_keys(self.test_page_remote + Keys.ENTER)
 
-        Wait(self.marionette).until(
+        Wait(self.marionette, timeout=self.marionette.timeout.page_load).until(
             lambda mn: mn.get_url() == self.test_page_remote,
             message="'{}' hasn't been loaded".format(self.test_page_remote))
         self.assertTrue(self.is_remote_tab)
 
     @skip_if_mobile("On Android no shortcuts are available")
     def test_navigate_shortcut_key(self):
 
         def open_with_shortcut():
             self.marionette.navigate(self.test_page_remote)
             with self.marionette.using_context("chrome"):
                 main_win = self.marionette.find_element(By.ID, "main-window")
                 main_win.send_keys(self.mod_key, Keys.SHIFT, "a")
 
         new_tab = self.open_tab(trigger=open_with_shortcut)
         self.marionette.switch_to_window(new_tab)
 
-        Wait(self.marionette).until(lambda mn: mn.get_url() == "about:addons",
-                                    message="'about:addons' hasn't been loaded")
+        Wait(self.marionette, timeout=self.marionette.timeout.page_load).until(
+            lambda mn: mn.get_url() == "about:addons",
+            message="'about:addons' hasn't been loaded")
 
 
 class TestBackForwardNavigation(BaseNavigationTestCase):
 
     def run_bfcache_test(self, test_pages):
         # Helper method to run simple back and forward testcases.
         for index, page in enumerate(test_pages):
             if "error" in page:
@@ -441,31 +444,31 @@ class TestBackForwardNavigation(BaseNavi
         # Force triggering a timeout error
         self.marionette.timeout.page_load = 0.5
         with self.assertRaises(errors.TimeoutException):
             self.marionette.go_back()
         self.marionette.timeout.reset()
 
         Wait(self.marionette, self.marionette.timeout.page_load).until(
             lambda mn: urls[0] == mn.get_url(),
-            message="Slow loading page has been successfully loaded after going back")
+            message="'{}' has been successfully loaded after going back".format(urls[0]))
         self.assertEqual(self.marionette.find_element(By.ID, "delay").text, "3")
 
         self.marionette.go_forward()
         self.assertEqual(urls[1], self.marionette.get_url())
 
         # Force triggering a timeout error
         self.marionette.timeout.page_load = 0.5
         with self.assertRaises(errors.TimeoutException):
             self.marionette.go_forward()
         self.marionette.timeout.reset()
 
         Wait(self.marionette, self.marionette.timeout.page_load).until(
             lambda mn: urls[2] == mn.get_url(),
-            message="Slow loading page has been successfully loaded after going forward")
+            message="'{}' has been successfully loaded after going back".format(urls[2]))
         self.assertEqual(self.marionette.find_element(By.ID, "delay").text, "4")
 
     def test_certificate_error(self):
         test_pages = [
             {"url": self.test_page_insecure,
              "error": errors.InsecureCertificateException},
             {"url": self.test_page_remote},
             {"url": self.test_page_insecure,
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_switch_window_content.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_switch_window_content.py
@@ -86,17 +86,17 @@ class TestSwitchToWindowContent(WindowMa
         with self.marionette.using_context("content"):
             self.assertEqual(self.marionette.get_url(), self.test_page)
 
         self.marionette.switch_to_window(new_tab)
         self.assertEqual(self.marionette.current_window_handle, new_tab)
         self.assertNotEqual(self.get_selected_tab_index(), self.selected_tab_index)
 
         with self.marionette.using_context("content"):
-            Wait(self.marionette).until(
+            Wait(self.marionette, timeout=self.marionette.timeout.page_load).until(
                 lambda _: self.marionette.get_url() == self.empty_page,
                 message="{} has been loaded in the newly opened tab.".format(self.empty_page))
 
         self.marionette.switch_to_window(self.start_tab, focus=True)
         self.assertEqual(self.marionette.current_window_handle, self.start_tab)
         self.assertEqual(self.get_selected_tab_index(), self.selected_tab_index)
         with self.marionette.using_context("content"):
             self.assertEqual(self.marionette.get_url(), self.test_page)