Bug 1411281 - Add equality test for webdriver.Session draft
authorAndreas Tolfsen <ato@sny.no>
Thu, 26 Oct 2017 17:15:16 +0100
changeset 688665 aca4bc61b314975d9830101b37507735c4e466c7
parent 688664 5fed65a031196d541a9676db83c2b37bd8cba9f8
child 688666 6b70b2012d8470656a6667c631f4dc6ec54d6aaa
push id86818
push userbmo:ato@sny.no
push dateMon, 30 Oct 2017 13:42:30 +0000
bugs1411281
milestone58.0a1
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
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
@@ -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):