Bug 1408509 - Turn some WebDriver client assertions into errors. r?whimboo draft
authorAndreas Tolfsen <ato@sny.no>
Fri, 22 Jun 2018 14:03:25 +0100
changeset 810828 284b67f6da24d3e83d804830eef0c35c7244ce44
parent 810827 7d370b365d635321cbb61f13085f034671fa4118
push id114124
push userbmo:ato@sny.no
push dateTue, 26 Jun 2018 15:47:34 +0000
reviewerswhimboo
bugs1408509
milestone63.0a1
Bug 1408509 - Turn some WebDriver client assertions into errors. r?whimboo In Python, assert only raises AssertException when __debug__ is true which it isn't for optimised code. There are some cases in the WebDriver client where we genuinely want to stop the user from performing certain actions, and this patch turns those into raised exceptions. MozReview-Commit-ID: GbEafJmAqu
testing/web-platform/tests/tools/webdriver/webdriver/client.py
--- a/testing/web-platform/tests/tools/webdriver/webdriver/client.py
+++ b/testing/web-platform/tests/tools/webdriver/webdriver/client.py
@@ -11,17 +11,16 @@ def command(func):
     def inner(self, *args, **kwargs):
         if hasattr(self, "session"):
             session = self.session
         else:
             session = self
 
         if session.session_id is None:
             session.start()
-        assert session.session_id is not None
 
         return func(self, *args, **kwargs)
 
     inner.__name__ = func.__name__
     inner.__doc__ = func.__doc__
 
     return inner
 
@@ -660,29 +659,29 @@ class Element(object):
 
         :param id: Web element UUID which must be unique across
             all browsing contexts.
         :param session: Current ``webdriver.Session``.
         """
         self.id = id
         self.session = session
 
-        assert id not in self.session._element_cache
+        if id in self.session._element_cache:
+            raise ValueError("Element already in cache: %s" % id)
         self.session._element_cache[self.id] = self
 
     def __repr__(self):
         return "<%s %s>" % (self.__class__.__name__, self.id)
 
     def __eq__(self, other):
         return (isinstance(other, Element) and self.id == other.id and
                 self.session == other.session)
 
     @classmethod
     def from_json(cls, json, session):
-        assert Element.identifier in json
         uuid = json[Element.identifier]
         if uuid in session._element_cache:
             return session._element_cache[uuid]
         return cls(uuid, session)
 
     def send_element_command(self, method, uri, body=None):
         url = "element/%s/%s" % (self.id, uri)
         return self.session.send_session_command(method, url, body)