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