Unreviewed. Update W3C WebDriver imported tests.
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / sessions / new_session / invalid_capabilities.py
1 #META: timeout=long
2
3 import pytest
4 from webdriver import error
5
6 from conftest import product, flatten
7
8
9 @pytest.mark.parametrize("value", [None, 1, "{}", []])
10 def test_invalid_capabilites(new_session, value):
11     with pytest.raises(error.InvalidArgumentException):
12         new_session({"capabilities": value})
13
14
15 @pytest.mark.parametrize("value", [None, 1, "{}", []])
16 def test_invalid_always_match(new_session, add_browser_capabilites, value):
17     with pytest.raises(error.InvalidArgumentException):
18         new_session({"capabilities": {"alwaysMatch": value, "firstMatch": [add_browser_capabilites({})]}})
19
20
21 @pytest.mark.parametrize("value", [None, 1, "[]", {}])
22 def test_invalid_first_match(new_session, add_browser_capabilites, value):
23     with pytest.raises(error.InvalidArgumentException):
24         new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({}), "firstMatch": value}})
25
26
27 invalid_data = [
28     ("acceptInsecureCerts", [1, [], {}, "false"]),
29     ("browserName", [1, [], {}, False]),
30     ("browserVersion", [1, [], {}, False]),
31     ("platformName", [1, [], {}, False]),
32     ("pageLoadStrategy", [1, [], {}, False, "invalid", "NONE", "Eager", "eagerblah", "interactive",
33                           " eager", "eager "]),
34     ("proxy", [1, [], "{}", {"proxyType": "SYSTEM"}, {"proxyType": "systemSomething"},
35                {"proxy type": "pac"}, {"proxy-Type": "system"}, {"proxy_type": "system"},
36                {"proxytype": "system"}, {"PROXYTYPE": "system"}, {"proxyType": None},
37                {"proxyType": 1}, {"proxyType": []}, {"proxyType": {"value": "system"}},
38                {" proxyType": "system"}, {"proxyType ": "system"}, {"proxyType ": " system"},
39                {"proxyType": "system "}]),
40     ("timeouts", [1, [], "{}", False, {"pageLOAD": 10}, {"page load": 10},
41                   {"page load": 10}, {"pageLoad": "10"}, {"pageLoad": {"value": 10}},
42                   {"invalid": 10}, {"pageLoad": -1}, {"pageLoad": 2**64},
43                   {"pageLoad": None}, {"pageLoad": 1.1}, {"pageLoad": 10, "invalid": 10},
44                   {" pageLoad": 10}, {"pageLoad ": 10}]),
45     ("unhandledPromptBehavior", [1, [], {}, False, "DISMISS", "dismissABC", "Accept",
46                                  " dismiss", "dismiss "])
47 ]
48
49 @pytest.mark.parametrize("body", [lambda key, value: {"alwaysMatch": {key: value}},
50                                   lambda key, value: {"firstMatch": [{key: value}]}])
51 @pytest.mark.parametrize("key,value", flatten(product(*item) for item in invalid_data))
52 def test_invalid_values(new_session, add_browser_capabilites, body, key, value):
53     capabilities = body(key, value)
54     if "alwaysMatch" in capabilities:
55         capabilities["alwaysMatch"] = add_browser_capabilites(capabilities["alwaysMatch"])
56     else:
57         capabilities["firstMatch"][0] = add_browser_capabilites(capabilities["firstMatch"][0])
58     with pytest.raises(error.InvalidArgumentException):
59         resp = new_session({"capabilities": capabilities})
60
61
62 invalid_extensions = [
63     "firefox",
64     "firefox_binary",
65     "firefoxOptions",
66     "chromeOptions",
67     "automaticInspection",
68     "automaticProfiling",
69     "platform",
70     "version",
71     "browser",
72     "platformVersion",
73     "javascriptEnabled",
74     "nativeEvents",
75     "seleniumProtocol",
76     "profile",
77     "trustAllSSLCertificates",
78     "initialBrowserUrl",
79     "requireWindowFocus",
80     "logFile",
81     "logLevel",
82     "safari.options",
83     "ensureCleanSession",
84 ]
85
86
87 @pytest.mark.parametrize("body", [lambda key, value: {"alwaysMatch": {key: value}},
88                                   lambda key, value: {"firstMatch": [{key: value}]}])
89 @pytest.mark.parametrize("key", invalid_extensions)
90 def test_invalid_extensions(new_session, add_browser_capabilites, body, key):
91     capabilities = body(key, {})
92     if "alwaysMatch" in capabilities:
93         capabilities["alwaysMatch"] = add_browser_capabilites(capabilities["alwaysMatch"])
94     else:
95         capabilities["firstMatch"][0] = add_browser_capabilites(capabilities["firstMatch"][0])
96     with pytest.raises(error.InvalidArgumentException):
97         resp = new_session({"capabilities": capabilities})
98