Skip to content

Commit 2f76e44

Browse files
dosasichich
authored
Remove deprecated firefox cmdline options. (#282)
Co-authored-by: ich <[email protected]> Co-authored-by: ich <[email protected]>
1 parent 4a06ef2 commit 2f76e44

File tree

5 files changed

+17
-167
lines changed

5 files changed

+17
-167
lines changed
+5-111
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,15 @@
11
# This Source Code Form is subject to the terms of the Mozilla Public
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4-
from packaging.version import Version
5-
import warnings
64
import logging
75

86
import pytest
9-
from selenium import __version__ as SELENIUM_VERSION
10-
from selenium.webdriver import FirefoxProfile
11-
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
7+
128
from selenium.webdriver.firefox.options import Options
139

1410
LOGGER = logging.getLogger(__name__)
1511

1612

17-
def pytest_addoption(parser):
18-
group = parser.getgroup("selenium", "selenium")
19-
group._addoption(
20-
"--firefox-path", metavar="path", help="path to the firefox binary."
21-
)
22-
group._addoption(
23-
"--firefox-preference",
24-
action="append",
25-
default=[],
26-
dest="firefox_preferences",
27-
metavar=("name", "value"),
28-
nargs=2,
29-
help="additional firefox preferences.",
30-
)
31-
group._addoption(
32-
"--firefox-profile", metavar="path", help="path to the firefox profile."
33-
)
34-
group._addoption(
35-
"--firefox-extension",
36-
action="append",
37-
default=[],
38-
dest="firefox_extensions",
39-
metavar="path",
40-
help="path to a firefox extension.",
41-
)
42-
43-
4413
def pytest_configure(config):
4514
config.addinivalue_line(
4615
"markers",
@@ -58,36 +27,22 @@ def pytest_configure(config):
5827

5928

6029
def driver_kwargs(capabilities, driver_log, driver_path, firefox_options, **kwargs):
61-
62-
# Selenium 3.14.0 deprecated log_path in favour of service_log_path
63-
if Version(SELENIUM_VERSION) < Version("3.14.0"):
64-
kwargs = {"log_path": driver_log}
65-
else:
66-
kwargs = {"service_log_path": driver_log}
30+
kwargs = {"service_log_path": driver_log}
6731

6832
if capabilities:
6933
kwargs["capabilities"] = capabilities
7034
if driver_path is not None:
7135
kwargs["executable_path"] = driver_path
7236

73-
# Selenium 3.8.0 deprecated firefox_options in favour of options
74-
if Version(SELENIUM_VERSION) < Version("3.8.0"):
75-
kwargs["firefox_options"] = firefox_options
76-
else:
77-
kwargs["options"] = firefox_options
37+
kwargs["options"] = firefox_options
38+
7839
return kwargs
7940

8041

8142
@pytest.fixture
82-
def firefox_options(request, firefox_path, firefox_profile):
43+
def firefox_options(request):
8344
options = Options()
8445

85-
if firefox_profile is not None:
86-
options.profile = firefox_profile
87-
88-
if firefox_path is not None:
89-
options.binary = FirefoxBinary(firefox_path)
90-
9146
for arg in get_arguments_from_markers(request.node):
9247
options.add_argument(arg)
9348

@@ -109,64 +64,3 @@ def get_preferences_from_markers(node):
10964
for mark in node.iter_markers("firefox_preferences"):
11065
preferences.update(mark.args[0])
11166
return preferences
112-
113-
114-
@pytest.fixture(scope="session")
115-
def firefox_path(pytestconfig):
116-
if pytestconfig.getoption("firefox_path"):
117-
warnings.warn(
118-
"--firefox-path has been deprecated and will be removed in a "
119-
"future release. Please make sure the Firefox binary is in the "
120-
"default location, or the system path. If you want to specify a "
121-
"binary path then use the firefox_options fixture to and set this "
122-
"using firefox_options.binary.",
123-
DeprecationWarning,
124-
)
125-
return pytestconfig.getoption("firefox_path")
126-
127-
128-
@pytest.fixture
129-
def firefox_profile(pytestconfig):
130-
profile = None
131-
if pytestconfig.getoption("firefox_profile"):
132-
profile = FirefoxProfile(pytestconfig.getoption("firefox_profile"))
133-
warnings.warn(
134-
"--firefox-profile has been deprecated and will be removed in "
135-
"a future release. Please use the firefox_options fixture to "
136-
"set a profile path or FirefoxProfile object using "
137-
"firefox_options.profile.",
138-
DeprecationWarning,
139-
)
140-
if pytestconfig.getoption("firefox_preferences"):
141-
profile = profile or FirefoxProfile()
142-
warnings.warn(
143-
"--firefox-preference has been deprecated and will be removed in "
144-
"a future release. Please use the firefox_options fixture to set "
145-
"preferences using firefox_options.set_preference. If you are "
146-
"using Firefox 47 or earlier then you will need to create a "
147-
"FirefoxProfile object with preferences and set this using "
148-
"firefox_options.profile.",
149-
DeprecationWarning,
150-
)
151-
for preference in pytestconfig.getoption("firefox_preferences"):
152-
name, value = preference
153-
if value.isdigit():
154-
# handle integer preferences
155-
value = int(value)
156-
elif value.lower() in ["true", "false"]:
157-
# handle boolean preferences
158-
value = value.lower() == "true"
159-
profile.set_preference(name, value)
160-
profile.update_preferences()
161-
if pytestconfig.getoption("firefox_extensions"):
162-
profile = profile or FirefoxProfile()
163-
warnings.warn(
164-
"--firefox-extensions has been deprecated and will be removed in "
165-
"a future release. Please use the firefox_options fixture to "
166-
"create a FirefoxProfile object with extensions and set this "
167-
"using firefox_options.profile.",
168-
DeprecationWarning,
169-
)
170-
for extension in pytestconfig.getoption("firefox_extensions"):
171-
profile.add_extension(extension)
172-
return profile

src/pytest_selenium/drivers/remote.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
PORT = os.environ.get("SELENIUM_PORT", 4444)
99

1010

11-
def driver_kwargs(capabilities, firefox_profile, host, port, **kwargs):
11+
def driver_kwargs(capabilities, host, port, **kwargs):
1212
executor = "http://{0}:{1}/wd/hub".format(host, port)
1313

1414
kwargs = {
1515
"command_executor": executor,
1616
"desired_capabilities": capabilities,
17-
"browser_profile": firefox_profile,
1817
}
1918
return kwargs

src/pytest_selenium/pytest_selenium.py

-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ def driver_kwargs(
148148
driver_log,
149149
driver_path,
150150
firefox_options,
151-
firefox_profile,
152151
edge_options,
153152
pytestconfig,
154153
):
@@ -162,7 +161,6 @@ def driver_kwargs(
162161
driver_log=driver_log,
163162
driver_path=driver_path,
164163
firefox_options=firefox_options,
165-
firefox_profile=firefox_profile,
166164
edge_options=edge_options,
167165
host=pytestconfig.getoption("selenium_host"),
168166
port=pytestconfig.getoption("selenium_port"),

testing/conftest.py

-4
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ def chrome_options(chrome_options):
5151
[tool:pytest]
5252
filterwarnings =
5353
error::DeprecationWarning
54-
ignore:--firefox-\w+ has been deprecated:DeprecationWarning
5554
ignore:capabilities and desired_capabilities have been deprecated, please pass in a Service object:DeprecationWarning
56-
ignore:firefox_profile has been deprecated, please use an Options object:DeprecationWarning
57-
ignore:Setting a profile has been deprecated. Please use the set_preference and install_addons methods:DeprecationWarning
58-
ignore:Getting a profile has been deprecated.:DeprecationWarning
5955
ignore:desired_capabilities has been deprecated
6056
ignore:service_log_path has been deprecated
6157
""", # noqa: E501

testing/test_firefox.py

+11-48
Original file line numberDiff line numberDiff line change
@@ -40,69 +40,32 @@ def test_profile(testdir, httpserver):
4040
when calling value_of_css_property.
4141
"""
4242
httpserver.serve_content(content='<h1>Success!</h1><a href="#">Link</a>')
43-
profile = testdir.tmpdir.mkdir("profile")
44-
profile.join("prefs.js").write(
45-
'user_pref("browser.anchor_color", "#FF69B4");'
46-
'user_pref("browser.display.foreground_color", "#FF0000");'
47-
'user_pref("browser.display.use_document_colors", false);'
48-
)
4943
file_test = testdir.makepyfile(
5044
"""
5145
import pytest
5246
from selenium.webdriver.common.by import By
53-
@pytest.mark.nondestructive
54-
def test_profile(base_url, selenium):
55-
selenium.get(base_url)
56-
header = selenium.find_element(By.TAG_NAME, 'h1')
57-
anchor = selenium.find_element(By.TAG_NAME, 'a')
58-
header_color = header.value_of_css_property('color')
59-
anchor_color = anchor.value_of_css_property('color')
60-
assert header_color == 'rgb(255, 0, 0)'
61-
assert anchor_color == 'rgb(255, 105, 180)'
62-
"""
63-
)
64-
testdir.quick_qa("--firefox-profile", profile, file_test, passed=1)
65-
6647
67-
def test_profile_with_preferences(testdir, httpserver):
68-
"""Test that preferences override profile when starting Firefox.
48+
@pytest.fixture
49+
def firefox_options(firefox_options):
50+
firefox_options.set_preference("browser.anchor_color", "#FF69B4")
51+
firefox_options.set_preference("browser.display.foreground_color",
52+
"#FF0000")
53+
firefox_options.set_preference("browser.display.use_document_colors",
54+
False)
55+
return firefox_options
6956
70-
The profile changes the colors in the browser, which are then reflected
71-
when calling value_of_css_property. The test checks that the color of the
72-
h1 tag is overridden by the profile, while the color of the a tag is
73-
overridden by the preference.
74-
"""
75-
httpserver.serve_content(content='<h1>Success!</h1><a href="#">Link</a>')
76-
profile = testdir.tmpdir.mkdir("profile")
77-
profile.join("prefs.js").write(
78-
'user_pref("browser.anchor_color", "#FF69B4");'
79-
'user_pref("browser.display.foreground_color", "#FF0000");'
80-
'user_pref("browser.display.use_document_colors", false);'
81-
)
82-
file_test = testdir.makepyfile(
83-
"""
84-
import pytest
85-
from selenium.webdriver.common.by import By
8657
@pytest.mark.nondestructive
87-
def test_preferences(base_url, selenium):
58+
def test_profile(base_url, selenium):
8859
selenium.get(base_url)
8960
header = selenium.find_element(By.TAG_NAME, 'h1')
9061
anchor = selenium.find_element(By.TAG_NAME, 'a')
9162
header_color = header.value_of_css_property('color')
9263
anchor_color = anchor.value_of_css_property('color')
9364
assert header_color == 'rgb(255, 0, 0)'
94-
assert anchor_color == 'rgb(255, 0, 0)'
65+
assert anchor_color == 'rgb(255, 105, 180)'
9566
"""
9667
)
97-
testdir.quick_qa(
98-
"--firefox-preference",
99-
"browser.anchor_color",
100-
"#FF0000",
101-
"--firefox-profile",
102-
profile,
103-
file_test,
104-
passed=1,
105-
)
68+
testdir.quick_qa(file_test, passed=1)
10669

10770

10871
@pytest.mark.xfail(reason="https://github.com/SeleniumHQ/selenium/pull/5069")

0 commit comments

Comments
 (0)