Bug 1411281 - Add equality test for webdriver.Session
When comparing two instances of webdriver.Session we want to first
check that there is a current session, then the type of the object
to compare with to make sure the "session_id" attribute is present,
then finally we compare the session IDs.
MozReview-Commit-ID: 6Ch4Uy2MEhB
--- a/testing/web-platform/tests/tools/webdriver/webdriver/client.py
+++ b/testing/web-platform/tests/tools/webdriver/webdriver/client.py
@@ -349,18 +349,23 @@ class UserPrompt(object):
@text.setter
@command
def text(self, value):
body = {"value": list(value)}
self.session.send_session_command("POST", "alert/text", body=body)
class Session(object):
- def __init__(self, host, port, url_prefix="/", capabilities=None,
- timeout=None, extension=None):
+ def __init__(self,
+ host,
+ port,
+ url_prefix="/",
+ capabilities=None,
+ timeout=None,
+ extension=None):
self.transport = transport.HTTPWireProtocol(
host, port, url_prefix, timeout=timeout)
self.capabilities = capabilities
self.session_id = None
self.timeouts = None
self.window = None
self.find = None
self._element_cache = {}
@@ -368,16 +373,20 @@ class Session(object):
self.extension_cls = extension
self.timeouts = Timeouts(self)
self.window = Window(self)
self.find = Find(self)
self.alert = UserPrompt(self)
self.actions = Actions(self)
+ def __eq__(self, other):
+ return (self.session_id is not None and isinstance(other, Session)
+ and self.session_Id == other.session_id)
+
def __enter__(self):
self.start()
return self
def __exit__(self, *args, **kwargs):
self.end()
def __del__(self):