diff --git a/src/pytest_selenium/drivers/firefox.py b/src/pytest_selenium/drivers/firefox.py index fd8c303..4a9a2c1 100644 --- a/src/pytest_selenium/drivers/firefox.py +++ b/src/pytest_selenium/drivers/firefox.py @@ -1,46 +1,15 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -from packaging.version import Version -import warnings import logging import pytest -from selenium import __version__ as SELENIUM_VERSION -from selenium.webdriver import FirefoxProfile -from selenium.webdriver.firefox.firefox_binary import FirefoxBinary + from selenium.webdriver.firefox.options import Options LOGGER = logging.getLogger(__name__) -def pytest_addoption(parser): - group = parser.getgroup("selenium", "selenium") - group._addoption( - "--firefox-path", metavar="path", help="path to the firefox binary." - ) - group._addoption( - "--firefox-preference", - action="append", - default=[], - dest="firefox_preferences", - metavar=("name", "value"), - nargs=2, - help="additional firefox preferences.", - ) - group._addoption( - "--firefox-profile", metavar="path", help="path to the firefox profile." - ) - group._addoption( - "--firefox-extension", - action="append", - default=[], - dest="firefox_extensions", - metavar="path", - help="path to a firefox extension.", - ) - - def pytest_configure(config): config.addinivalue_line( "markers", @@ -58,36 +27,22 @@ def pytest_configure(config): def driver_kwargs(capabilities, driver_log, driver_path, firefox_options, **kwargs): - - # Selenium 3.14.0 deprecated log_path in favour of service_log_path - if Version(SELENIUM_VERSION) < Version("3.14.0"): - kwargs = {"log_path": driver_log} - else: - kwargs = {"service_log_path": driver_log} + kwargs = {"service_log_path": driver_log} if capabilities: kwargs["capabilities"] = capabilities if driver_path is not None: kwargs["executable_path"] = driver_path - # Selenium 3.8.0 deprecated firefox_options in favour of options - if Version(SELENIUM_VERSION) < Version("3.8.0"): - kwargs["firefox_options"] = firefox_options - else: - kwargs["options"] = firefox_options + kwargs["options"] = firefox_options + return kwargs @pytest.fixture -def firefox_options(request, firefox_path, firefox_profile): +def firefox_options(request): options = Options() - if firefox_profile is not None: - options.profile = firefox_profile - - if firefox_path is not None: - options.binary = FirefoxBinary(firefox_path) - for arg in get_arguments_from_markers(request.node): options.add_argument(arg) @@ -109,64 +64,3 @@ def get_preferences_from_markers(node): for mark in node.iter_markers("firefox_preferences"): preferences.update(mark.args[0]) return preferences - - -@pytest.fixture(scope="session") -def firefox_path(pytestconfig): - if pytestconfig.getoption("firefox_path"): - warnings.warn( - "--firefox-path has been deprecated and will be removed in a " - "future release. Please make sure the Firefox binary is in the " - "default location, or the system path. If you want to specify a " - "binary path then use the firefox_options fixture to and set this " - "using firefox_options.binary.", - DeprecationWarning, - ) - return pytestconfig.getoption("firefox_path") - - -@pytest.fixture -def firefox_profile(pytestconfig): - profile = None - if pytestconfig.getoption("firefox_profile"): - profile = FirefoxProfile(pytestconfig.getoption("firefox_profile")) - warnings.warn( - "--firefox-profile has been deprecated and will be removed in " - "a future release. Please use the firefox_options fixture to " - "set a profile path or FirefoxProfile object using " - "firefox_options.profile.", - DeprecationWarning, - ) - if pytestconfig.getoption("firefox_preferences"): - profile = profile or FirefoxProfile() - warnings.warn( - "--firefox-preference has been deprecated and will be removed in " - "a future release. Please use the firefox_options fixture to set " - "preferences using firefox_options.set_preference. If you are " - "using Firefox 47 or earlier then you will need to create a " - "FirefoxProfile object with preferences and set this using " - "firefox_options.profile.", - DeprecationWarning, - ) - for preference in pytestconfig.getoption("firefox_preferences"): - name, value = preference - if value.isdigit(): - # handle integer preferences - value = int(value) - elif value.lower() in ["true", "false"]: - # handle boolean preferences - value = value.lower() == "true" - profile.set_preference(name, value) - profile.update_preferences() - if pytestconfig.getoption("firefox_extensions"): - profile = profile or FirefoxProfile() - warnings.warn( - "--firefox-extensions has been deprecated and will be removed in " - "a future release. Please use the firefox_options fixture to " - "create a FirefoxProfile object with extensions and set this " - "using firefox_options.profile.", - DeprecationWarning, - ) - for extension in pytestconfig.getoption("firefox_extensions"): - profile.add_extension(extension) - return profile diff --git a/src/pytest_selenium/drivers/remote.py b/src/pytest_selenium/drivers/remote.py index 78179eb..5693d85 100644 --- a/src/pytest_selenium/drivers/remote.py +++ b/src/pytest_selenium/drivers/remote.py @@ -8,12 +8,11 @@ PORT = os.environ.get("SELENIUM_PORT", 4444) -def driver_kwargs(capabilities, firefox_profile, host, port, **kwargs): +def driver_kwargs(capabilities, host, port, **kwargs): executor = "http://{0}:{1}/wd/hub".format(host, port) kwargs = { "command_executor": executor, "desired_capabilities": capabilities, - "browser_profile": firefox_profile, } return kwargs diff --git a/src/pytest_selenium/pytest_selenium.py b/src/pytest_selenium/pytest_selenium.py index d6297da..19b37f4 100644 --- a/src/pytest_selenium/pytest_selenium.py +++ b/src/pytest_selenium/pytest_selenium.py @@ -148,7 +148,6 @@ def driver_kwargs( driver_log, driver_path, firefox_options, - firefox_profile, edge_options, pytestconfig, ): @@ -162,7 +161,6 @@ def driver_kwargs( driver_log=driver_log, driver_path=driver_path, firefox_options=firefox_options, - firefox_profile=firefox_profile, edge_options=edge_options, host=pytestconfig.getoption("selenium_host"), port=pytestconfig.getoption("selenium_port"), diff --git a/testing/conftest.py b/testing/conftest.py index 2f7217f..58acf86 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -51,11 +51,7 @@ def chrome_options(chrome_options): [tool:pytest] filterwarnings = error::DeprecationWarning - ignore:--firefox-\w+ has been deprecated:DeprecationWarning ignore:capabilities and desired_capabilities have been deprecated, please pass in a Service object:DeprecationWarning - ignore:firefox_profile has been deprecated, please use an Options object:DeprecationWarning - ignore:Setting a profile has been deprecated. Please use the set_preference and install_addons methods:DeprecationWarning - ignore:Getting a profile has been deprecated.:DeprecationWarning ignore:desired_capabilities has been deprecated ignore:service_log_path has been deprecated """, # noqa: E501 diff --git a/testing/test_firefox.py b/testing/test_firefox.py index dff85be..68476da 100644 --- a/testing/test_firefox.py +++ b/testing/test_firefox.py @@ -40,69 +40,32 @@ def test_profile(testdir, httpserver): when calling value_of_css_property. """ httpserver.serve_content(content='

Success!

Link') - profile = testdir.tmpdir.mkdir("profile") - profile.join("prefs.js").write( - 'user_pref("browser.anchor_color", "#FF69B4");' - 'user_pref("browser.display.foreground_color", "#FF0000");' - 'user_pref("browser.display.use_document_colors", false);' - ) file_test = testdir.makepyfile( """ import pytest from selenium.webdriver.common.by import By - @pytest.mark.nondestructive - def test_profile(base_url, selenium): - selenium.get(base_url) - header = selenium.find_element(By.TAG_NAME, 'h1') - anchor = selenium.find_element(By.TAG_NAME, 'a') - header_color = header.value_of_css_property('color') - anchor_color = anchor.value_of_css_property('color') - assert header_color == 'rgb(255, 0, 0)' - assert anchor_color == 'rgb(255, 105, 180)' - """ - ) - testdir.quick_qa("--firefox-profile", profile, file_test, passed=1) - -def test_profile_with_preferences(testdir, httpserver): - """Test that preferences override profile when starting Firefox. + @pytest.fixture + def firefox_options(firefox_options): + firefox_options.set_preference("browser.anchor_color", "#FF69B4") + firefox_options.set_preference("browser.display.foreground_color", + "#FF0000") + firefox_options.set_preference("browser.display.use_document_colors", + False) + return firefox_options - The profile changes the colors in the browser, which are then reflected - when calling value_of_css_property. The test checks that the color of the - h1 tag is overridden by the profile, while the color of the a tag is - overridden by the preference. - """ - httpserver.serve_content(content='

Success!

Link') - profile = testdir.tmpdir.mkdir("profile") - profile.join("prefs.js").write( - 'user_pref("browser.anchor_color", "#FF69B4");' - 'user_pref("browser.display.foreground_color", "#FF0000");' - 'user_pref("browser.display.use_document_colors", false);' - ) - file_test = testdir.makepyfile( - """ - import pytest - from selenium.webdriver.common.by import By @pytest.mark.nondestructive - def test_preferences(base_url, selenium): + def test_profile(base_url, selenium): selenium.get(base_url) header = selenium.find_element(By.TAG_NAME, 'h1') anchor = selenium.find_element(By.TAG_NAME, 'a') header_color = header.value_of_css_property('color') anchor_color = anchor.value_of_css_property('color') assert header_color == 'rgb(255, 0, 0)' - assert anchor_color == 'rgb(255, 0, 0)' + assert anchor_color == 'rgb(255, 105, 180)' """ ) - testdir.quick_qa( - "--firefox-preference", - "browser.anchor_color", - "#FF0000", - "--firefox-profile", - profile, - file_test, - passed=1, - ) + testdir.quick_qa(file_test, passed=1) @pytest.mark.xfail(reason="https://github.com/SeleniumHQ/selenium/pull/5069")