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
--- 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)