Bug 1453009 - Add assert_element to wdspec. r?whimboo draft
authorAndreas Tolfsen <ato@sny.no>
Tue, 10 Apr 2018 18:33:04 +0100
changeset 779865 ca3c4dc6ac1eb266677d0a3fe6fd0585eb117c7b
parent 779856 0a2dae2d8cf9f628c55668514c54a23da446d5de
child 779866 a510dedab11d674e37f9b387a941b7c15f948fe7
push id105897
push userbmo:ato@sny.no
push dateTue, 10 Apr 2018 18:35:01 +0000
reviewerswhimboo
bugs1453009
milestone61.0a1
Bug 1453009 - Add assert_element to wdspec. r?whimboo Adds a new assert_element function for determining that something is either a webdriver.Element or a web element reference (JSON Object with the identifier). MozReview-Commit-ID: 7EStn4CkYvw
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webdriver/tests/support/asserts.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -600948,17 +600948,17 @@
    "570274d59020c4d8d0b8ecd604660ee7d710a165",
    "wdspec"
   ],
   "webdriver/tests/support/__init__.py": [
    "5a31a3917a5157516c10951a3b3d5ffb43b992d9",
    "support"
   ],
   "webdriver/tests/support/asserts.py": [
-   "1b839404daaca1d059cba98377edb91691ef7e82",
+   "7c971f6fdfa238fcd44b558c55d0279a4754ec97",
    "support"
   ],
   "webdriver/tests/support/fixtures.py": [
    "cfae7bac775181b96107346746f0e5b17b4e2eed",
    "support"
   ],
   "webdriver/tests/support/http_request.py": [
    "cb40c781fea2280b98135522def5e6a116d7b946",
--- a/testing/web-platform/tests/webdriver/tests/support/asserts.py
+++ b/testing/web-platform/tests/webdriver/tests/support/asserts.py
@@ -98,16 +98,28 @@ def assert_dialog_handled(session, expec
     try:
         assert_error(result, "no such alert")
     except:
         assert (result.status == 200 and
                 result.body["value"] != expected_text), (
             "Dialog with text '%s' was not handled." % expected_text)
 
 
+def assert_element(obj):
+    """
+    Tests that `obj` is an ``Element`` or a raw dictionary representing
+    a web element.
+    """
+    if isinstance(obj, Element):
+        return
+
+    assert isinstance(obj, dict), "Expected JSON Object"
+    assert Element.identifier in obj, "Expected web element identifier"
+
+
 def assert_same_element(session, a, b):
     """Verify that two element references describe the same 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: