Bug 1392984 - Add Find Element From Element wdspec tests r?ato draft
authorDavid Burns <dburns@mozilla.com>
Wed, 23 Aug 2017 22:27:32 +0100
changeset 663859 c6daf1bfb66539576c5f1dc1a8249304faf80a7e
parent 663858 6f1326dd4b207cb40bbc430ee07c013e60aba5ef
child 663860 aa5d02b1d9bbb397dc8cc05a20ebde0c4aebb9cf
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 From Element wdspec tests r?ato This adds wdspec tests for Find Element From Element as in https://w3c.github.io/webdriver/webdriver-spec.html#find-element-from-element MozReview-Commit-ID: 1a4vRv9wuwr
testing/web-platform/tests/webdriver/tests/retrieval/find_element_from_element.py
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/retrieval/find_element_from_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, element, using, value):
+    return session.transport.send("POST",
+                                  "session/%s/element/%s/element" % (session.session_id, element),
+                                  {"using": using, "value": value})
+
+
+@pytest.mark.parametrize("using", ["a", True, None, 1, [], {}])
+def test_invalid_using_argument(session, using):
+    # Step 1 - 2
+    response = find_element(session, "notReal", 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, "notReal", "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, "notReal", "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("<div><a href=# id=linkText>full link text</a></div>")
+    element = session.find.css("div", all=False)
+    response = find_element(session, element.id, using, value)
+    assert_success(response)
+
+
+@pytest.mark.parametrize("using,value",[("css selector", "#wontExist")])
+def test_no_element(session, using, value):
+    # Step 8 - 9
+    session.url = inline("<div></div>")
+    element = session.find.css("div", all=False)
+    response = find_element(session, element.id, using, value)
+    assert_error(response, "no such element")