Bug 1302707 - Add Marionette.set_page_load_timeout and adjust to new driver API; r?automatedtester
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_SOCKET_TIMEOUT = 60
DEFAULT_STARTUP_TIMEOUT = 120
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):
else:
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)
else:
- 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__)):
@@ -1192,48 +1198,63 @@ class Marionette(object):
self._send_message("deleteSession")
self.session_id = None
self.session = None
self.window = None
self.client.close()
@property
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})
@property
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.