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
--- 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: