Skip to content

chore: Remove Selenium 3 deprecations #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/pytest_selenium/drivers/chrome.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
# 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 pytest
from selenium import __version__ as SELENIUM_VERSION
from selenium.webdriver.chrome.options import Options


def driver_kwargs(
capabilities, driver_args, driver_log, driver_path, chrome_options, **kwargs
):
kwargs = {"desired_capabilities": capabilities, "service_log_path": driver_log}

# Selenium 3.8.0 deprecated chrome_options in favour of options
if Version(SELENIUM_VERSION) < Version("3.8.0"):
kwargs["chrome_options"] = chrome_options
else:
kwargs["options"] = chrome_options
kwargs = {
"desired_capabilities": capabilities,
"service_log_path": driver_log,
"options": chrome_options,
}

if driver_args is not None:
kwargs["service_args"] = driver_args
Expand Down
15 changes: 4 additions & 11 deletions src/pytest_selenium/drivers/edge.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
# 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 pytest
from selenium import __version__ as SELENIUM_VERSION
from selenium.webdriver.edge.options import Options


def driver_kwargs(capabilities, driver_log, driver_path, edge_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}

if Version(SELENIUM_VERSION) >= Version("4.0.0"):
kwargs["options"] = edge_options
kwargs = {
"service_log_path": driver_log,
"options": edge_options,
}

if capabilities:
kwargs["capabilities"] = capabilities
Expand Down
8 changes: 1 addition & 7 deletions src/pytest_selenium/drivers/internet_explorer.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# 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
from selenium import __version__ as SELENIUM_VERSION


def driver_kwargs(capabilities, driver_log, driver_path, **kwargs):

# Selenium 3.14.0 deprecated log_file in favour of service_log_path
if Version(SELENIUM_VERSION) < Version("3.14.0"):
kwargs = {"log_file": driver_log}
else:
kwargs = {"service_log_path": driver_log}
kwargs = {"service_log_path": driver_log}

if capabilities:
kwargs["capabilities"] = capabilities
Expand Down
32 changes: 0 additions & 32 deletions src/pytest_selenium/pytest_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from .utils import CaseInsensitiveDict
from . import drivers

import warnings

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -228,22 +227,6 @@ def selenium(driver):

@pytest.hookimpl(trylast=True)
def pytest_configure(config):
if config.getoption("host"):
warnings.warn(
"--host has been deprecated and will be removed in a "
"future release. Please use --selenium-host instead.",
DeprecationWarning,
)
config.option.selenium_host = config.getoption("host")

if config.getoption("port"):
warnings.warn(
"--port has been deprecated and will be removed in a "
"future release. Please use --selenium-port instead.",
DeprecationWarning,
)
config.option.selenium_port = config.getoption("port")

capabilities = config._variables.get("capabilities", {})
capabilities.update({k: v for k, v in config.getoption("capabilities")})
config.addinivalue_line(
Expand Down Expand Up @@ -479,21 +462,6 @@ def pytest_addoption(parser):
help="selenium eventlistener class, e.g. "
"package.module.EventListenerClassName.",
)
group._addoption(
"--host",
metavar="str",
help="DEPRECATED host that the selenium server is listening on, "
"which will default to the cloud provider default "
"or localhost.",
)
group._addoption(
"--port",
type=int,
metavar="num",
help="DEPRECATED port that the selenium server is listening on, "
"which will default to the cloud provider default "
"or localhost.",
)
group._addoption(
"--selenium-host",
metavar="str",
Expand Down
32 changes: 12 additions & 20 deletions testing/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# 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 contextlib import ExitStack as does_not_raise
from functools import partial

import pytest_selenium
Expand Down Expand Up @@ -138,14 +137,7 @@ def test_pass(driver_kwargs):
)


@pytest.mark.parametrize(
("host_arg_name", "port_arg_name", "context"),
[
("--selenium-host", "--selenium-port", does_not_raise()),
("--host", "--port", pytest.warns(DeprecationWarning)),
],
)
def test_arguments_order(testdir, host_arg_name, port_arg_name, context):
def test_arguments_order(testdir):
host = "notlocalhost"
port = "4441"
file_test = testdir.makepyfile(
Expand All @@ -158,17 +150,17 @@ def test_pass(driver_kwargs):
host, port
)
)
with context:
testdir.quick_qa(
"--driver",
"Remote",
host_arg_name,
host,
port_arg_name,
port,
file_test,
passed=1,
)

testdir.quick_qa(
"--driver",
"Remote",
"--selenium-host",
host,
"--selenium-port",
port,
file_test,
passed=1,
)


def test_arguments_order_random(testdir):
Expand Down
6 changes: 0 additions & 6 deletions testing/test_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import pytest
import sys
from packaging.version import Version
from selenium import __version__ as SELENIUM_VERSION


pytestmark = pytest.mark.nondestructive
Expand All @@ -27,10 +25,6 @@ def test_pass(webtext):


@pytest.mark.skipif(sys.platform != "win32", reason="Edge only runs on Windows")
@pytest.mark.skipif(
Version(SELENIUM_VERSION) < Version("4.0.0"),
reason="Edge chromium only supported for selenium >= 4.0.0",
)
@pytest.mark.edge
@pytest.mark.parametrize("use_chromium", [True, False], ids=["chromium", "legacy"])
def test_launch(use_chromium, testdir, httpserver):
Expand Down
33 changes: 12 additions & 21 deletions testing/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# 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 contextlib import ExitStack as does_not_raise

import pytest

pytestmark = pytest.mark.nondestructive
Expand All @@ -25,14 +23,7 @@ def test_pass(metadata):
testdir.quick_qa("--driver", "Remote", file_test, passed=1)


@pytest.mark.parametrize(
("host_arg_name", "port_arg_name", "context"),
[
("--selenium-host", "--selenium-port", does_not_raise()),
("--host", "--port", pytest.warns(DeprecationWarning)),
],
)
def test_metadata_host_port(testdir, host_arg_name, port_arg_name, context):
def test_metadata_host_port(testdir):
host = "notlocalhost"
port = "4441"
file_test = testdir.makepyfile(
Expand All @@ -45,14 +36,14 @@ def test_pass(metadata):
host, port
)
)
with context:
testdir.quick_qa(
"--driver",
"Remote",
host_arg_name,
host,
port_arg_name,
port,
file_test,
passed=1,
)

testdir.quick_qa(
"--driver",
"Remote",
"--selenium-host",
host,
"--selenium-port",
port,
file_test,
passed=1,
)
15 changes: 4 additions & 11 deletions testing/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,17 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import re
from packaging.version import Version

import pytest
from pytest_html import __version__ as PYTEST_HTML_VERSION


pytestmark = pytest.mark.nondestructive

URL_LINK = '<a class="url" href="{0}/" target="_blank">URL</a>'

if Version(PYTEST_HTML_VERSION) < Version("2.0.0"):
SCREENSHOT_LINK_REGEX = '<a class="image" href=".*" target="_blank">Screenshot</a>'
SCREENSHOT_REGEX = '<div class="image"><a href=".*"><img src=".*"/></a></div>'
else:
SCREENSHOT_LINK_REGEX = (
'<a class="image" href=".*" target="_blank"><img src=".*"/></a>'
)
SCREENSHOT_REGEX = '<div class="image"><a class="image" href=".*" target="_blank">'
'<img src=".*"/></a></div>'
SCREENSHOT_LINK_REGEX = '<a class="image" href=".*" target="_blank"><img src=".*"/></a>'
SCREENSHOT_REGEX = '<div class="image"><a class="image" href=".*" target="_blank">'
'<img src=".*"/></a></div>'

LOGS_REGEX = '<a class="text" href=".*" target="_blank">.* Log</a>'
HTML_REGEX = '<a class="text" href=".*" target="_blank">HTML</a>'
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ deps =
pytest-localserver
pytest-xdist
pytest-mock
commands = pytest -n auto -v -r a --color=yes --html={envlogdir}/report.html --self-contained-html {posargs}
commands = pytest -n auto -v -r a --color=yes --strict-config --strict-markers --html={envlogdir}/report.html --self-contained-html {posargs}

[testenv:docs]
basepython = python3
Expand All @@ -39,6 +39,7 @@ exclude = .eggs,.tox,docs
testpaths = testing
# Register markers used by tests
markers =
firefox
edge
safari
chrome
Expand Down