Bug 1302707 - Add Marionette.set_page_load_timeout and adjust to new driver API. r=automatedtester, a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Wed, 14 Sep 2016 18:13:06 +0100
changeset 358125 2d92e455676a087f25d35ae8b21105a280f81f5b
parent 358124 915cc04590552b21eaaf227d7fb2723d9ce5a15c
child 358126 abd8c70863b5e66ad6a06daa82bd1a4a9cbb84f3
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester, test-only
Bug 1302707 - Add Marionette.set_page_load_timeout and adjust to new driver API. r=automatedtester, a=test-only MozReview-Commit-ID: 939khISAOcU
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -533,19 +533,16 @@ class Alert(object):
         self.marionette._send_message("sendKeysToDialog", body)
 class Marionette(object):
     """Represents a Marionette connection to a browser or device."""
     CONTEXT_CHROME = 'chrome'  # non-browser content: windows, dialogs, etc.
     CONTEXT_CONTENT = 'content'  # browser content: iframes, divs, etc.
-    TIMEOUT_SEARCH = 'implicit'
-    TIMEOUT_SCRIPT = 'script'
-    TIMEOUT_PAGE = 'page load'
     DEFAULT_SHUTDOWN_TIMEOUT = 65  # Firefox will kill hanging threads after 60s
     def __init__(self, host='localhost', port=2828, app=None, bin=None,
                  baseurl=None, timeout=None, socket_timeout=DEFAULT_SOCKET_TIMEOUT,
                  startup_timeout=None, **instance_args):
@@ -721,22 +718,31 @@ class Marionette(object):
             error = obj["error"]
             message = obj["message"]
             stacktrace = obj["stacktrace"]
         raise errors.lookup(error)(message, stacktrace=stacktrace)
     def reset_timeouts(self):
+        """Resets timeouts to their defaults to the `self.timeout`
+        attribute. If unset, only the page load timeout is reset to
+        30 seconds.
+        """
+        timeout_types = {"search": self.set_search_timeout,
+                         "script": self.set_script_timeout,
+                         "page load": self.set_page_load_timeout}
         if self.timeout is not None:
-            self.timeouts(self.TIMEOUT_SEARCH, self.timeout)
-            self.timeouts(self.TIMEOUT_SCRIPT, self.timeout)
-            self.timeouts(self.TIMEOUT_PAGE, self.timeout)
+            for typ, ms in self.timeout:
+                timeout_types[typ](ms)
-            self.timeouts(self.TIMEOUT_PAGE, 30000)
+            self.set_page_load_timeout(30000)
     def check_for_crash(self):
         returncode = None
         name = None
         crashed = False
         if self.instance:
             if self.instance.runner.check_for_crashes(
                     test_name=self.test_name or os.path.basename(__file__)):
@@ -1182,48 +1188,63 @@ class Marionette(object):
         self.session_id = None
         self.session = None
         self.window = None
     def session_capabilities(self):
-        '''
-        A JSON dictionary representing the capabilities of the current session.
-        '''
+        """A JSON dictionary representing the capabilities of the
+        current session.
+        """
         return self.session
     def set_script_timeout(self, timeout):
         """Sets the maximum number of ms that an asynchronous script is
         allowed to run.
         If a script does not return in the specified amount of time,
         a ScriptTimeoutException is raised.
         :param timeout: The maximum number of milliseconds an asynchronous
             script can run without causing an ScriptTimeoutException to
             be raised
-        self._send_message("setScriptTimeout", {"ms": timeout})
+        self._send_message("timeouts", {"script": timeout})
     def set_search_timeout(self, timeout):
         """Sets a timeout for the find methods.
         When searching for an element using
         either :class:`Marionette.find_element` or
         :class:`Marionette.find_elements`, the method will continue
         trying to locate the element for up to timeout ms. This can be
         useful if, for example, the element you're looking for might
         not exist immediately, because it belongs to a page which is
         currently being loaded.
         :param timeout: Timeout in milliseconds.
-        self._send_message("setSearchTimeout", {"ms": timeout})
+        self._send_message("timeouts", {"implicit": timeout})
+    def set_page_load_timeout(self, timeout):
+        """Sets a timeout for loading pages.
+        A page load timeout specifies the amount of time the Marionette
+        instance should wait for a page load operation to complete. A
+        ``TimeoutException`` is returned if this limit is exceeded.
+        :param timeout: Timeout in milliseconds.
+        """
+        self._send_message("timeouts", {"page load": timeout})
     def current_window_handle(self):
         """Get the current window's handle.
         Returns an opaque server-assigned identifier to this window
         that uniquely identifies it within this Marionette instance.
         This can be used to switch to this window at a later point.