Unreviewed. Update W3C WebDriver imported tests.
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / retrieval / find_element_from_element.py
1 import pytest
2
3 from tests.support.asserts import assert_error, assert_same_element, assert_success
4 from tests.support.inline import inline
5
6
7 def find_element(session, element, using, value):
8     return session.transport.send("POST",
9                                   "session/%s/element/%s/element" % (session.session_id, element),
10                                   {"using": using, "value": value})
11
12
13 @pytest.mark.parametrize("using", ["a", True, None, 1, [], {}])
14 def test_invalid_using_argument(session, using):
15     # Step 1 - 2
16     response = find_element(session, "notReal", using, "value")
17     assert_error(response, "invalid argument")
18
19
20 @pytest.mark.parametrize("value", [None, [], {}])
21 def test_invalid_selector_argument(session, value):
22     # Step 3 - 4
23     response = find_element(session, "notReal", "css selector", value)
24     assert_error(response, "invalid argument")
25
26
27 def test_closed_context(session, create_window):
28     # Step 5
29     new_window = create_window()
30     session.window_handle = new_window
31     session.close()
32
33     response = find_element(session, "notReal", "css selector", "foo")
34
35     assert_error(response, "no such window")
36
37
38 @pytest.mark.parametrize("using,value",
39                          [("css selector", "#linkText"),
40                           ("link text", "full link text"),
41                           ("partial link text", "link text"),
42                           ("tag name", "a"),
43                           ("xpath", "//a")])
44 def test_find_element(session, using, value):
45     # Step 8 - 9
46     session.url = inline("<div><a href=# id=linkText>full link text</a></div>")
47     element = session.find.css("div", all=False)
48     response = find_element(session, element.id, using, value)
49     assert_success(response)
50
51
52 @pytest.mark.parametrize("using,value",[("css selector", "#wontExist")])
53 def test_no_element(session, using, value):
54     # Step 8 - 9
55     session.url = inline("<div></div>")
56     element = session.find.css("div", all=False)
57     response = find_element(session, element.id, using, value)
58     assert_error(response, "no such element")
59
60
61 @pytest.mark.parametrize("using,value",
62                          [("css selector", "#linkText"),
63                           ("link text", "full link text"),
64                           ("partial link text", "link text"),
65                           ("tag name", "a"),
66                           ("xpath", "//*[name()='a']")])
67 def test_xhtml_namespace(session, using, value):
68     session.url = inline("""<p><a href="#" id="linkText">full link text</a></p>""", doctype="xhtml")
69     from_element = session.execute_script("""return document.querySelector("p")""")
70     expected = session.execute_script("return document.links[0]")
71
72     response = find_element(session, from_element.id, using, value)
73     value = assert_success(response)
74     assert_same_element(session, value, expected)