Bug 1392984 - Add Find Element wdspec tests r?ato draft
authorDavid Burns <dburns@mozilla.com>
Wed, 23 Aug 2017 21:30:51 +0100
changeset 663857 46dbe6aa7f1a7ad48fd46bc5a73ddaa2d99b72bf
parent 661583 ec521bf6357cf3564d5785a66da787be53be45cd
child 663858 6f1326dd4b207cb40bbc430ee07c013e60aba5ef
push id79548
push userbmo:dburns@mozilla.com
push dateWed, 13 Sep 2017 13:12:21 +0000
reviewersato
bugs1392984
milestone57.0a1
Bug 1392984 - Add Find Element wdspec tests r?ato This adds tests for the Find Element command in https://w3c.github.io/webdriver/webdriver-spec.html#find-element MozReview-Commit-ID: Lgezt2pTXcU
testing/web-platform/tests/webdriver/tests/retrieval/__init__.py
testing/web-platform/tests/webdriver/tests/retrieval/find_element.py
new file mode 100644
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/retrieval/find_element.py
@@ -0,0 +1,59 @@
+import pytest
+
+
+from tests.support.asserts import assert_error, assert_success
+from tests.support.inline import inline
+
+
+def find_element(session, using, value):
+    return session.transport.send("POST",
+                                  "session/%s/element" % session.session_id,
+                                  {"using": using, "value": value})
+
+
+# 12.2 Find Element
+
+@pytest.mark.parametrize("using", ["a", True, None, 1, [], {}])
+def test_invalid_using_argument(session, using):
+    # Step 1 - 2
+    response = find_element(session, using, "value")
+    assert_error(response, "invalid argument")
+
+
+@pytest.mark.parametrize("value", [None, [], {}])
+def test_invalid_selector_argument(session, value):
+    # Step 3 - 4
+    response = find_element(session, "css selector", value)
+    assert_error(response, "invalid argument")
+
+
+def test_closed_context(session, create_window):
+    # Step 5
+    new_window = create_window()
+    session.window_handle = new_window
+    session.close()
+
+    response = find_element(session, "css selector", "foo")
+
+    assert_error(response, "no such window")
+
+
+@pytest.mark.parametrize("using,value",
+                         [("css selector", "#linkText"),
+                          ("link text", "full link text"),
+                          ("partial link text", "link text"),
+                          ("tag name", "a"),
+                          ("xpath", "//a")])
+def test_find_element(session, using, value):
+    # Step 8 - 9
+    session.url = inline("<a href=# id=linkText>full link text</a>")
+
+    response = find_element(session, using, value)
+    assert_success(response)
+
+
+@pytest.mark.parametrize("using,value", [("css selector", "#wontExist")])
+def test_no_element(session, using, value):
+    # Step 8 - 9
+    response = find_element(session, using, value)
+    assert_error(response, "no such element")