Debian Codegraph @

test/unit/selenium/webdriver/firefox/firefox_options_tests.py

raw symbols SCIP
1 # Licensed to the Software Freedom Conservancy (SFC) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The SFC licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17
18 import pytest
19
20 from selenium.common.exceptions import InvalidArgumentException
21 from selenium.webdriver.common.options import PageLoadStrategy
22 from selenium.webdriver.common.proxy import Proxy
23 from selenium.webdriver.common.proxy import ProxyType
24 from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
25 from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
26 from selenium.webdriver.firefox.options import Options
27
28
29 @pytest.fixture
30 def options():
31 return Options()
32
33
34 def test_set_binary_with_firefox_binary(options):
35 binary = FirefoxBinary("foo")
36 options.binary = binary
37 assert options.binary_location == "foo"
38
39
40 def test_set_binary_with_path(options):
41 options.binary = "/foo"
42 assert options.binary_location == "/foo"
43
44
45 def test_get_binary(options):
46 options.binary = "/foo"
47 assert options.binary._start_cmd == "/foo"
48
49
50 def test_set_binary_location(options):
51 options.binary_location = "/foo"
52 assert options.binary_location == "/foo"
53
54
55 def test_get_binary_location(options):
56 options._binary_location = "/foo"
57 assert options.binary_location == "/foo"
58
59
60 def test_set_preference(options):
61 options.set_preference("foo", "bar")
62 assert options._preferences["foo"] == "bar"
63
64
65 def test_get_preferences(options):
66 options._preferences = {"foo": "bar"}
67 assert options.preferences["foo"] == "bar"
68
69
70 def test_set_proxy(options):
71 proxy = Proxy({"proxyType": ProxyType.MANUAL})
72 options.proxy = proxy
73 assert options._proxy == proxy
74
75
76 def test_set_proxy_isnt_in_moz_prefix(options):
77 proxy = Proxy({"proxyType": ProxyType.MANUAL})
78 options.proxy = proxy
79
80 caps = options.to_capabilities()
81 assert caps["proxy"]["proxyType"] == "manual"
82 assert caps.get("moz:firefoxOptions") == {"prefs": {"remote.active-protocols": 3}}
83
84
85 def test_raises_exception_if_proxy_is_not_proxy_object(options):
86 with pytest.raises(InvalidArgumentException):
87 options.proxy = "foo"
88
89
90 def test_get_proxy(options):
91 options._proxy = "foo"
92 assert options.proxy == "foo"
93
94
95 def test_set_profile_with_firefox_profile(options):
96 profile = FirefoxProfile()
97 options.profile = profile
98 assert options._profile == profile
99
100
101 def test_set_profile_with_path(options):
102 options.profile = None
103 assert isinstance(options._profile, FirefoxProfile)
104
105
106 def test_get_profile(options):
107 options._profile = "foo"
108 assert options.profile == "foo"
109
110
111 def test_add_arguments(options):
112 options.add_argument("foo")
113 assert "foo" in options._arguments
114
115
116 def test_get_arguments(options):
117 options._arguments = ["foo"]
118 assert "foo" in options.arguments
119
120
121 def test_raises_exception_if_argument_is_falsy(options):
122 with pytest.raises(ValueError):
123 options.add_argument(None)
124
125
126 def test_set_log_level(options):
127 options.log.level = "debug"
128 assert options.log.level == "debug"
129
130
131 def test_creates_capabilities(options):
132 profile = FirefoxProfile()
133 options._arguments = ["foo"]
134 options._binary_location = "/bar"
135 options._preferences = {"foo": "bar"}
136 options.proxy = Proxy({"proxyType": ProxyType.MANUAL})
137 options._profile = profile
138 options.log.level = "debug"
139 caps = options.to_capabilities()
140 opts = caps.get(Options.KEY)
141 assert opts
142 assert "foo" in opts["args"]
143 assert opts["binary"] == "/bar"
144 assert opts["prefs"]["foo"] == "bar"
145 assert isinstance(opts["profile"], str) and opts["profile"]
146 assert caps["proxy"]["proxyType"] == "manual"
147 assert opts["log"]["level"] == "debug"
148
149
150 def test_starts_with_default_capabilities(options):
151 from selenium.webdriver import DesiredCapabilities
152
153 caps = DesiredCapabilities.FIREFOX.copy()
154 caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
155 assert options._caps == caps
156
157
158 def test_is_a_baseoptions(options):
159 from selenium.webdriver.common.options import BaseOptions
160
161 assert isinstance(options, BaseOptions)
162
163
164 def test_raises_exception_with_invalid_page_load_strategy(options):
165 with pytest.raises(ValueError):
166 options.page_load_strategy = "never"
167
168
169 def test_set_page_load_strategy(options):
170 options.page_load_strategy = PageLoadStrategy.normal
171 assert options._caps["pageLoadStrategy"] == PageLoadStrategy.normal
172
173
174 def test_get_page_load_strategy(options):
175 options._page_load_strategy = PageLoadStrategy.normal
176 assert options._caps["pageLoadStrategy"] == PageLoadStrategy.normal
177
178
179 def test_creates_capabilities_with_page_load_strategy(options):
180 options.page_load_strategy = PageLoadStrategy.eager
181 caps = options.to_capabilities()
182 assert caps["pageLoadStrategy"] == PageLoadStrategy.eager
183
184
185 def test_enables_firefox_mobile(options):
186 options.enable_mobile()
187 result_caps = options.to_capabilities()
188 assert result_caps["moz:firefoxOptions"]["androidPackage"] == "org.mozilla.firefox"