Bug 1411281 - Make assert_same_element accept webdriver.Element draft
authorAndreas Tolfsen <ato@sny.no>
Wed, 25 Oct 2017 16:54:03 +0100
changeset 688669 e606001490ea131046e9bbd45371d29f1f0f7252
parent 688668 66a80dd6524b9bb393fbfe00082a8f72b660cf5a
child 738134 9e0504045f7fda82bb0061b909f319dd7d1ac068
push id86818
push userbmo:ato@sny.no
push dateMon, 30 Oct 2017 13:42:30 +0000
bugs1411281
milestone58.0a1
Bug 1411281 - Make assert_same_element accept webdriver.Element Allow assert_same_element to compare web element references (JSON Objects) with webdriver.Element and vice versa. Tests will typically look up some element using traditional means and use that as the trusted comparison when retrieving the same element using the session.transport.send primitive that returns the plain JSON Object. MozReview-Commit-ID: 2DScnviOevb
testing/web-platform/tests/webdriver/tests/support/asserts.py
--- a/testing/web-platform/tests/webdriver/tests/support/asserts.py
+++ b/testing/web-platform/tests/webdriver/tests/support/asserts.py
@@ -97,29 +97,40 @@ def assert_dialog_handled(session, expec
     except:
         assert (result.status == 200 and
                 result.body["value"] != expected_text), (
                "Dialog with text '%s' was not handled." % expected_text)
 
 
 def assert_same_element(session, a, b):
     """Verify that two element references describe the same element."""
-    assert isinstance(a, dict), "Actual value is not a dictionary"
-    assert isinstance(b, dict), "Expected value is not a dictionary"
-    assert Element.identifier in a, "Actual value does not describe an element"
-    assert Element.identifier in b, "Expected value does not describe an element"
+    if isinstance(a, dict):
+        assert Element.identifier in a, "Actual value does not describe an element"
+        a_id = a[Element.identifier]
+    elif isinstance(a, Element):
+        a_id = a.id
+    else:
+        raise AssertionError("Actual value is not a dictionary or web element")
 
-    if a[Element.identifier] == b[Element.identifier]:
+    if isinstance(b, dict):
+        assert Element.identifier in b, "Expected value does not describe an element"
+        b_id = b[Element.identifier]
+    elif isinstance(b, Element):
+        b_id = b.id
+    else:
+        raise AssertionError("Expected value is not a dictionary or web element")
+
+    if a_id == b_id:
         return
 
     message = ("Expected element references to describe the same element, " +
         "but they did not.")
 
     # Attempt to provide more information, accounting for possible errors such
     # as stale element references or not visible elements.
     try:
-        a_markup = session.execute_script("return arguments[0].outerHTML;", args=[a])
-        b_markup = session.execute_script("return arguments[0].outerHTML;", args=[b])
+        a_markup = session.execute_script("return arguments[0].outerHTML;", args=(a,))
+        b_markup = session.execute_script("return arguments[0].outerHTML;", args=(b,))
         message += " Actual: `%s`. Expected: `%s`." % (a_markup, b_markup)
     except WebDriverException:
         pass
 
     raise AssertionError(message)