Bug 1392984 - Add Find Elements wdspec tests r=ato
authorDavid Burns <dburns@mozilla.com>
Wed, 23 Aug 2017 21:48:39 +0100
changeset 430058 f77826e523e560f46216e3c35dc9841873c05af6
parent 430057 b4f917de7d599724082616fb587016b807876075
child 430059 3ebe0b1a5fa257d9d25458f339ec62987da6290a
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1392984
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1392984 - Add Find Elements wdspec tests r=ato This adds tests for the Find Elements command in https://w3c.github.io/webdriver/webdriver-spec.html#find-element MozReview-Commit-ID: G0nC5iKAQSJ
testing/web-platform/tests/webdriver/tests/retrieval/find_elements.py
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/retrieval/find_elements.py
@@ -0,0 +1,60 @@
+import pytest
+
+from tests.support.asserts import assert_error, assert_success
+from tests.support.inline import inline
+
+
+def find_elements(session, using, value):
+    return session.transport.send("POST",
+                                  "session/%s/elements" % session.session_id,
+                                  {"using": using, "value": value})
+
+
+@pytest.mark.parametrize("using", ["a", True, None, 1, [], {}])
+def test_invalid_using_argument(session, using):
+    # Step 1 - 2
+    response = find_elements(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_elements(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 = session.transport.send("POST",
+                                      "session/%s/elements" % session.session_id,
+                                      {"using": "css selector", "value": "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_elements(session, using, value):
+    # Step 8 - 9
+    session.url = inline("<a href=# id=linkText>full link text</a>")
+
+    response = find_elements(session, using, value)
+    assert_success(response)
+    assert len(response.body["value"]) == 1
+
+
+@pytest.mark.parametrize("using,value", [("css selector", "#wontExist")])
+def test_no_element(session, using, value):
+    # Step 8 - 9
+    response = find_elements(session, using, value)
+    assert_success(response)
+    assert response.body["value"] == []