Bug 1461463 - [wdspec] Add timeout reset finalizer to session fixture. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 17 May 2018 09:17:28 +0200
changeset 800977 731ae50a8e878ab8cbc9df3bbd6c853e5fb3ee73
parent 800976 0518792ebf5b08c512a2a63c8b71ea5387407271
child 800978 eede9b81db656e33e125c12bffbb79a425a0b435
push id111539
push userbmo:hskupin@gmail.com
push dateTue, 29 May 2018 15:41:27 +0000
bugs1461463
milestone62.0a1
Bug 1461463 - [wdspec] Add timeout reset finalizer to session fixture. If tests modify the timeout values those have to be reset for the next test. MozReview-Commit-ID: FqFwhduDR2m
testing/web-platform/tests/webdriver/tests/support/fixtures.py
--- a/testing/web-platform/tests/webdriver/tests/support/fixtures.py
+++ b/testing/web-platform/tests/webdriver/tests/support/fixtures.py
@@ -9,16 +9,20 @@ import sys
 import webdriver
 
 from tests.support.http_request import HTTPRequest
 from tests.support.wait import wait
 
 default_host = "http://127.0.0.1"
 default_port = "4444"
 
+default_script_timeout = 30
+default_page_load_timeout = 300
+default_implicit_wait_timeout = 0
+
 
 def ignore_exceptions(f):
     def inner(*args, **kwargs):
         try:
             return f(*args, **kwargs)
         except webdriver.error.WebDriverException as e:
             print("Ignored exception %s" % e, file=sys.stderr)
     inner.__name__ = f.__name__
@@ -48,16 +52,24 @@ def _dismiss_user_prompts(session):
             session.alert.dismiss()
         except webdriver.NoSuchAlertException:
             pass
 
     session.window_handle = current_window
 
 
 @ignore_exceptions
+def _restore_timeouts(session):
+    """Restores modified timeouts to their default values"""
+    session.timeouts.implicit = default_implicit_wait_timeout
+    session.timeouts.page_load = default_page_load_timeout
+    session.timeouts.script = default_script_timeout
+
+
+@ignore_exceptions
 def _restore_window_state(session):
     """Reset window to an acceptable size, bringing it out of maximized,
     minimized, or fullscreened state
 
     """
     session.window.size = (800, 600)
 
 
@@ -163,16 +175,17 @@ def session(configuration, request):
 
     # finalisers are popped off a stack,
     # making their ordering reverse
     request.addfinalizer(lambda: _switch_to_top_level_browsing_context(_current_session))
     request.addfinalizer(lambda: _restore_window_state(_current_session))
     request.addfinalizer(lambda: _restore_windows(_current_session))
     request.addfinalizer(lambda: _dismiss_user_prompts(_current_session))
     request.addfinalizer(lambda: _ensure_valid_window(_current_session))
+    request.addfinalizer(lambda: _restore_timeouts(_current_session))
 
     return _current_session
 
 
 def new_session(configuration, request):
     """Return a factory function that will attempt to start a session with a given body.
 
     This is intended for tests that are themselves testing new session creation, and the