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