Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py
1990 views
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, ProxyType
23
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
24
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
25
from selenium.webdriver.firefox.options import Options
26
27
28
@pytest.fixture
29
def options():
30
return Options()
31
32
33
def test_set_binary_with_firefox_binary(options):
34
binary = FirefoxBinary("foo")
35
options.binary = binary
36
assert options.binary_location == "foo"
37
38
39
def test_set_binary_with_path(options):
40
options.binary = "/foo"
41
assert options.binary_location == "/foo"
42
43
44
def test_get_binary(options):
45
options.binary = "/foo"
46
assert options.binary._start_cmd == "/foo"
47
48
49
def test_set_binary_location(options):
50
options.binary_location = "/foo"
51
assert options.binary_location == "/foo"
52
53
54
def test_get_binary_location(options):
55
options._binary_location = "/foo"
56
assert options.binary_location == "/foo"
57
58
59
def test_set_preference(options):
60
options.set_preference("foo", "bar")
61
assert options._preferences["foo"] == "bar"
62
63
64
def test_get_preferences(options):
65
options._preferences = {"foo": "bar"}
66
assert options.preferences["foo"] == "bar"
67
68
69
def test_set_proxy(options):
70
proxy = Proxy({"proxyType": ProxyType.MANUAL})
71
options.proxy = proxy
72
assert options._proxy == proxy
73
74
75
def test_set_proxy_isnt_in_moz_prefix(options):
76
proxy = Proxy({"proxyType": ProxyType.MANUAL})
77
options.proxy = proxy
78
79
caps = options.to_capabilities()
80
assert caps["proxy"]["proxyType"] == "manual"
81
assert caps.get("moz:firefoxOptions") == {"prefs": {"remote.active-protocols": 1}}
82
83
84
def test_raises_exception_if_proxy_is_not_proxy_object(options):
85
with pytest.raises(InvalidArgumentException):
86
options.proxy = "foo"
87
88
89
def test_get_proxy(options):
90
options._proxy = "foo"
91
assert options.proxy == "foo"
92
93
94
def test_set_profile_with_firefox_profile(options):
95
profile = FirefoxProfile()
96
options.profile = profile
97
assert options._profile == profile
98
99
100
def test_set_profile_with_path(options):
101
options.profile = None
102
assert isinstance(options._profile, FirefoxProfile)
103
104
105
def test_get_profile(options):
106
options._profile = "foo"
107
assert options.profile == "foo"
108
109
110
def test_add_arguments(options):
111
options.add_argument("foo")
112
assert "foo" in options._arguments
113
114
115
def test_get_arguments(options):
116
options._arguments = ["foo"]
117
assert "foo" in options.arguments
118
119
120
def test_raises_exception_if_argument_is_falsy(options):
121
with pytest.raises(ValueError):
122
options.add_argument(None)
123
124
125
def test_set_log_level(options):
126
options.log.level = "debug"
127
assert options.log.level == "debug"
128
129
130
def test_creates_capabilities(options):
131
profile = FirefoxProfile()
132
options._arguments = ["foo"]
133
options._binary_location = "/bar"
134
options._preferences = {"foo": "bar"}
135
options.proxy = Proxy({"proxyType": ProxyType.MANUAL})
136
options._profile = profile
137
options.log.level = "debug"
138
caps = options.to_capabilities()
139
opts = caps.get(Options.KEY)
140
assert opts
141
assert "foo" in opts["args"]
142
assert opts["binary"] == "/bar"
143
assert opts["prefs"]["foo"] == "bar"
144
assert isinstance(opts["profile"], str) and opts["profile"]
145
assert caps["proxy"]["proxyType"] == "manual"
146
assert opts["log"]["level"] == "debug"
147
148
149
def test_starts_with_default_capabilities(options):
150
from selenium.webdriver import DesiredCapabilities
151
152
caps = DesiredCapabilities.FIREFOX.copy()
153
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
154
assert options._caps == caps
155
156
157
def test_is_a_baseoptions(options):
158
from selenium.webdriver.common.options import BaseOptions
159
160
assert isinstance(options, BaseOptions)
161
162
163
def test_raises_exception_with_invalid_page_load_strategy(options):
164
with pytest.raises(ValueError):
165
options.page_load_strategy = "never"
166
167
168
def test_set_page_load_strategy(options):
169
options.page_load_strategy = PageLoadStrategy.normal
170
assert options._caps["pageLoadStrategy"] == PageLoadStrategy.normal
171
172
173
def test_get_page_load_strategy(options):
174
options._page_load_strategy = PageLoadStrategy.normal
175
assert options._caps["pageLoadStrategy"] == PageLoadStrategy.normal
176
177
178
def test_creates_capabilities_with_page_load_strategy(options):
179
options.page_load_strategy = PageLoadStrategy.eager
180
caps = options.to_capabilities()
181
assert caps["pageLoadStrategy"] == PageLoadStrategy.eager
182
183
184
def test_enables_firefox_mobile(options):
185
options.enable_mobile()
186
result_caps = options.to_capabilities()
187
assert result_caps["moz:firefoxOptions"]["androidPackage"] == "org.mozilla.firefox"
188
189