Bug 1411281 - Swap webdriver.Element ctor arguments draft
authorAndreas Tolfsen <ato@sny.no>
Wed, 25 Oct 2017 10:13:18 +0100
changeset 688667 afb95a8f64b674745f6346080a95d5dee3539c29
parent 688666 6b70b2012d8470656a6667c631f4dc6ec54d6aaa
child 688668 66a80dd6524b9bb393fbfe00082a8f72b660cf5a
push id86818
push userbmo:ato@sny.no
push dateMon, 30 Oct 2017 13:42:30 +0000
bugs1411281
milestone58.0a1
Bug 1411281 - Swap webdriver.Element ctor arguments It is more natural for the web element UUID to come first, followed by the associated session state. The patch also adds ctor documentation. MozReview-Commit-ID: 5iV4SZzMeKS
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
@@ -543,17 +543,17 @@ class Session(object):
         if data is not None:
             return self._element(data)
 
     def _element(self, data):
         elem_id = data[Element.identifier]
         assert elem_id
         if elem_id in self._element_cache:
             return self._element_cache[elem_id]
-        return Element(self, elem_id)
+        return Element(elem_id, self)
 
     @command
     def cookies(self, name=None):
         if name is None:
             url = "cookie"
         else:
             url = "cookie/%s" % name
         return self.send_session_command("GET", url, {})
@@ -614,19 +614,27 @@ class Element(object):
     """
     Representation of a web element.
 
     A web element is an abstraction used to identify an element when
     it is transported via the protocol, between remote- and local ends.
     """
     identifier = "element-6066-11e4-a52e-4f735466cecf"
 
-    def __init__(self, session, id):
+    def __init__(self, id, session):
+        """
+        Construct a new web element representation.
+
+        :param id: Web element UUID which must be unique across
+            all browsing contexts.
+        :param session: Current ``webdriver.Session``.
+        """
+        self.id = 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):