Skip to content

Support latest selenium #317

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 4 commits into from
Nov 20, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
include:
- os: ubuntu-latest
python-version: pypy3.9
tox-env: py3.9

- os: ubuntu-latest
python-version: 3.11
python-version: 3.12
tox-env: devel

steps:
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ services:
webserver:
container_name: webserver
build:
context: docker
context: .
environment:
- PYTHONDONTWRITEBYTECODE=1
networks:
Expand Down
13 changes: 13 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
Release Notes
=============

4.0.2 (2023-09-13)
------------------

* Support selenium 4.10-4.15

* Thanks to `@noamkush <https://github.com/noamkush>`_ for the PR.

* Remove py dependency

* Thanks to `@treiher <https://github.com/treiher>`_ for reporting the issue.

* Thanks to `@sandre35 <https://github.com/sandre35>`_ for the PR.

4.0.1 (2023-05-28)
------------------

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ classifiers = [
dependencies = [
"pytest>=6.0.0",
"pytest-base-url>=2.0.0",
"pytest-html>=2.0.0",
"pytest-html>=4.0.0",
"pytest-variables>=2.0.0",
"requests>=2.26.0",
"selenium>=4.0.0",
"selenium>=4.10.0",
"tenacity>=6.0.0",
]
dynamic = [
Expand Down
28 changes: 14 additions & 14 deletions src/pytest_selenium/drivers/browserstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import pytest
from selenium.webdriver.common.options import ArgOptions

from pytest_selenium.drivers.cloud import Provider
from pytest_selenium.exceptions import MissingCloudSettingError
Expand Down Expand Up @@ -93,23 +94,22 @@ def pytest_selenium_runtest_makereport(item, report, summary, extra):
summary.append("WARNING: Failed to update job status: {0}".format(e))


def driver_kwargs(request, test, capabilities, **kwargs):
def driver_kwargs(test, capabilities, **kwargs):
provider = BrowserStack()
assert provider.job_access
if (
"bstack:options" in capabilities
and type(capabilities["bstack:options"]) is dict
):
capabilities["bstack:options"].setdefault("sessionName", test)
capabilities["bstack:options"].setdefault("userName", provider.username)
capabilities["bstack:options"].setdefault("accessKey", provider.key)
options = ArgOptions()
bstack_options = capabilities.pop("bstack:options", None)
if isinstance(bstack_options, dict):
bstack_options.setdefault("sessionName", test)
bstack_options.setdefault("userName", provider.username)
bstack_options.setdefault("accessKey", provider.key)
options.set_capability("bstack:options", bstack_options)
else:
capabilities.setdefault("name", test)
capabilities.setdefault("browserstack.user", provider.username)
capabilities.setdefault("browserstack.key", provider.key)
kwargs = {
options.set_capability("name", test)
options.set_capability("browserstack.user", provider.username)
options.set_capability("browserstack.key", provider.key)
return {
"command_executor": provider.executor,
"desired_capabilities": capabilities,
"keep_alive": True,
"options": options,
}
return kwargs
24 changes: 10 additions & 14 deletions src/pytest_selenium/drivers/chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import pytest
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service


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

if driver_args is not None:
kwargs["service_args"] = driver_args
if driver_path is not None:
kwargs["executable_path"] = driver_path
return kwargs
def driver_kwargs(chrome_options, chrome_service, **kwargs):
return {"options": chrome_options, "service": chrome_service}


@pytest.fixture
def chrome_options():
return Options()


@pytest.fixture
def chrome_service(driver_path, driver_args, driver_log):
return Service(
executable_path=driver_path, service_args=driver_args, log_output=driver_log
)
18 changes: 7 additions & 11 deletions src/pytest_selenium/drivers/crossbrowsertesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# 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 py.xml import html
import html
import pytest

from pytest_selenium.drivers.cloud import Provider
Expand Down Expand Up @@ -113,13 +113,9 @@ def driver_kwargs(request, test, capabilities, **kwargs):


def _video_html(video):
html.__tagspec__.update(dict([(x, 1) for x in ("video", "source")]))
video_attrs = {
"controls": "",
"poster": video.get("image"),
"play-pause-on-click": "",
"style": "border:1px solid #e6e6e6; float:right; height:240px; "
"margin-left:5px; overflow:hidden; width:320px",
}
source_attrs = {"src": video.get("video"), "type": "video/mp4"}
return str(html.video(html.source(**source_attrs), **video_attrs))
return (
f'<video controls="" play-pause-on-click="" poster="{html.escape(video.get("image"))}"'
'style="border:1px solid #e6e6e6; float:right; height:240px; margin-left:5px; overflow:hidden; width:320px">'
f'<source src="{html.escape(video.get("video"))}" type="video/mp4"></source>'
"</video>"
)
23 changes: 10 additions & 13 deletions src/pytest_selenium/drivers/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import pytest
from selenium.webdriver.edge.options import Options
from selenium.webdriver.edge.service import Service


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

kwargs = {
"service_log_path": driver_log,
"options": edge_options,
}

if capabilities:
kwargs["capabilities"] = capabilities
if driver_path is not None:
kwargs["executable_path"] = driver_path

return kwargs
def driver_kwargs(edge_options, edge_service, **kwargs):
return {"options": edge_options, "service": edge_service}


@pytest.fixture
def edge_options():
return Options()


@pytest.fixture
def edge_service(driver_path, driver_args, driver_log):
return Service(
executable_path=driver_path, service_args=driver_args, log_output=driver_log
)
21 changes: 10 additions & 11 deletions src/pytest_selenium/drivers/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service

LOGGER = logging.getLogger(__name__)

Expand All @@ -26,17 +27,8 @@ def pytest_configure(config):
)


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

if capabilities:
kwargs["capabilities"] = capabilities
if driver_path is not None:
kwargs["executable_path"] = driver_path

kwargs["options"] = firefox_options

return kwargs
def driver_kwargs(firefox_options, firefox_service, **kwargs):
return {"options": firefox_options, "service": firefox_service}


@pytest.fixture
Expand All @@ -52,6 +44,13 @@ def firefox_options(request):
return options


@pytest.fixture
def firefox_service(driver_path, driver_args, driver_log):
return Service(
executable_path=driver_path, service_args=driver_args, log_output=driver_log
)


def get_arguments_from_markers(node):
arguments = []
for m in node.iter_markers("firefox_arguments"):
Expand Down
22 changes: 15 additions & 7 deletions src/pytest_selenium/drivers/internet_explorer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# 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/.
import pytest
from selenium.webdriver.ie.options import Options
from selenium.webdriver.ie.service import Service


def driver_kwargs(capabilities, driver_log, driver_path, **kwargs):
def driver_kwargs(ie_options, ie_service, **kwargs):
return {"options": ie_options, "service": ie_service}

kwargs = {"service_log_path": driver_log}

if capabilities:
kwargs["capabilities"] = capabilities
if driver_path is not None:
kwargs["executable_path"] = driver_path
return kwargs
@pytest.fixture
def ie_options():
return Options()


@pytest.fixture
def ie_service(driver_path, driver_args, driver_log):
return Service(
executable_path=driver_path, service_args=driver_args, log_output=driver_log
)
20 changes: 16 additions & 4 deletions src/pytest_selenium/drivers/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,28 @@

import os

import pytest

HOST = os.environ.get("SELENIUM_HOST", "localhost")
PORT = os.environ.get("SELENIUM_PORT", 4444)


def driver_kwargs(capabilities, host, port, **kwargs):
def driver_kwargs(remote_options, host, port, **kwargs):
host = host if host.startswith("http") else f"http://{host}"
executor = f"{host}:{port}/wd/hub"

kwargs = {
return {
"command_executor": executor,
"desired_capabilities": capabilities,
"options": remote_options,
}
return kwargs


@pytest.fixture
def remote_options(chrome_options, firefox_options, edge_options, capabilities):
browser = capabilities.get("browserName", "").upper()
if browser == "CHROME":
return chrome_options
elif browser == "FIREFOX":
return firefox_options
elif browser == "EDGE":
return edge_options
25 changes: 20 additions & 5 deletions src/pytest_selenium/drivers/safari.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
# 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/.
import pytest
from selenium.webdriver.safari.options import Options
from selenium.webdriver.safari.service import Service


def driver_kwargs(capabilities, driver_path, **kwargs):
kwargs = {"desired_capabilities": capabilities}
if driver_path is not None:
kwargs["executable_path"] = driver_path
return kwargs
def driver_kwargs(safari_options, safari_service, **kwargs):
return {
"options": safari_options,
"service": safari_service,
}


@pytest.fixture
def safari_options():
return Options()


@pytest.fixture
def safari_service(driver_path, driver_args, driver_log):
return Service(
executable_path=driver_path, service_args=driver_args, log_output=driver_log
)
Loading