Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/selenium/webdriver/marionette/mn_options_tests.py
1865 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.webdriver.common.by import By
21
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
22
from selenium.webdriver.common.options import PageLoadStrategy
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 Log, Options
26
27
28
@pytest.fixture
29
def driver_kwargs(driver_kwargs):
30
driver_kwargs["options"] = Options()
31
return driver_kwargs
32
33
34
class TestIntegration:
35
def test_we_can_pass_options(self, driver, pages):
36
pages.load("formPage.html")
37
driver.find_element(By.ID, "cheese")
38
39
40
class TestUnit:
41
def test_ctor(self):
42
opts = Options()
43
assert opts.binary_location == ""
44
assert opts._preferences == {"remote.active-protocols": 1}
45
assert opts._profile is None
46
assert not opts._arguments
47
assert isinstance(opts.log, Log)
48
49
def test_binary(self):
50
opts = Options()
51
assert opts.binary_location == ""
52
53
other_binary = FirefoxBinary()
54
assert other_binary != opts.binary_location
55
opts.binary = other_binary
56
assert other_binary._start_cmd == opts.binary_location
57
58
path = "/path/to/binary"
59
opts.binary = path
60
assert isinstance(opts.binary, FirefoxBinary)
61
assert opts.binary._start_cmd == path
62
63
def test_prefs(self):
64
opts = Options()
65
assert len(opts.preferences) == 1
66
assert isinstance(opts.preferences, dict)
67
68
opts.set_preference("spam", "ham")
69
assert len(opts.preferences) == 2
70
opts.set_preference("eggs", True)
71
assert len(opts.preferences) == 3
72
opts.set_preference("spam", "spam")
73
assert len(opts.preferences) == 3
74
assert opts.preferences == {"eggs": True, "remote.active-protocols": 1, "spam": "spam"}
75
76
def test_profile(self, tmpdir_factory):
77
opts = Options()
78
assert opts.profile is None
79
80
other_profile = FirefoxProfile()
81
assert other_profile != opts.profile
82
opts.profile = other_profile
83
assert other_profile == opts.profile
84
85
opts.profile = str(tmpdir_factory.mktemp("profile"))
86
assert isinstance(opts.profile, FirefoxProfile)
87
88
def test_arguments(self):
89
opts = Options()
90
assert len(opts.arguments) == 0
91
92
opts.add_argument("--foo")
93
assert len(opts.arguments) == 1
94
opts.arguments.append("--bar")
95
assert len(opts.arguments) == 2
96
assert opts.arguments == ["--foo", "--bar"]
97
98
def test_to_capabilities(self):
99
opts = Options()
100
firefox_caps = DesiredCapabilities.FIREFOX.copy()
101
firefox_caps.update(
102
{
103
"pageLoadStrategy": PageLoadStrategy.normal,
104
"moz:firefoxOptions": {"prefs": {"remote.active-protocols": 1}},
105
}
106
)
107
assert opts.to_capabilities() == firefox_caps
108
109
profile = FirefoxProfile()
110
opts.profile = profile
111
caps = opts.to_capabilities()
112
assert "moz:firefoxOptions" in caps
113
assert "profile" in caps["moz:firefoxOptions"]
114
assert isinstance(caps["moz:firefoxOptions"]["profile"], str)
115
assert caps["moz:firefoxOptions"]["profile"] == profile.encoded
116
117
opts.add_argument("--foo")
118
caps = opts.to_capabilities()
119
assert "moz:firefoxOptions" in caps
120
assert "args" in caps["moz:firefoxOptions"]
121
assert caps["moz:firefoxOptions"]["args"] == ["--foo"]
122
123
binary = FirefoxBinary()
124
opts.binary = binary
125
caps = opts.to_capabilities()
126
assert "moz:firefoxOptions" in caps
127
assert "binary" in caps["moz:firefoxOptions"]
128
assert isinstance(caps["moz:firefoxOptions"]["binary"], str)
129
assert caps["moz:firefoxOptions"]["binary"] == binary._start_cmd
130
131
opts.set_preference("spam", "ham")
132
caps = opts.to_capabilities()
133
assert "moz:firefoxOptions" in caps
134
assert "prefs" in caps["moz:firefoxOptions"]
135
assert isinstance(caps["moz:firefoxOptions"]["prefs"], dict)
136
assert caps["moz:firefoxOptions"]["prefs"]["spam"] == "ham"
137
138