Bug 1411281 - Add equality test for webdriver.Element draft
authorAndreas Tolfsen <ato@sny.no>
Wed, 25 Oct 2017 09:59:52 +0100
changeset 688666 6b70b2012d8470656a6667c631f4dc6ec54d6aaa
parent 688665 aca4bc61b314975d9830101b37507735c4e466c7
child 688667 afb95a8f64b674745f6346080a95d5dee3539c29
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.Element When comparing two instances of webdriver.Element we want to first check the type, to make sure the "id" attribute is present, then compare the web element reference UUIDs. These are supposed to be unique across all browsing contexts. MozReview-Commit-ID: 68PUBQxPdQ5
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
@@ -620,16 +620,20 @@ class Element(object):
     identifier = "element-6066-11e4-a52e-4f735466cecf"
 
     def __init__(self, session, id):
         self.session = session
         self.id = id
         assert id not in self.session._element_cache
         self.session._element_cache[self.id] = self
 
+    def __eq__(self, other):
+        return isinstance(other, Element) and self.id == other.id \
+                and self.session == other.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)
 
     def json(self):
         return {Element.identifier: self.id}
 
     @command