Skip to content

Commit

Permalink
Support latest selenium.
Browse files Browse the repository at this point in the history
  • Loading branch information
noamk-hl committed Nov 20, 2023
1 parent 965bd12 commit 8fb0894
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 145 deletions.
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
4 changes: 4 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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.
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
)
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
)
6 changes: 3 additions & 3 deletions src/pytest_selenium/drivers/saucelabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json

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 @@ -114,11 +115,10 @@ def driver_kwargs(request, test, capabilities, **kwargs):
if tags:
_capabilities["tags"] = tags

kwargs = {
return {
"command_executor": provider.executor,
"desired_capabilities": capabilities,
"options": ArgOptions(),
}
return kwargs


def _video_html(session):
Expand Down
17 changes: 9 additions & 8 deletions src/pytest_selenium/drivers/testingbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from hashlib import md5

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

from pytest_selenium.drivers.cloud import Provider

Expand Down Expand Up @@ -91,18 +92,18 @@ def pytest_selenium_runtest_makereport(item, report, summary, extra):
def driver_kwargs(request, test, capabilities, host, port, **kwargs):
provider = TestingBot(host, port)

capabilities.setdefault("name", test)
capabilities.setdefault("client_key", provider.key)
capabilities.setdefault("client_secret", provider.secret)
options = ArgOptions()
options.set_capability("name", test)
options.set_capability("client_key", provider.key)
options.set_capability("client_secret", provider.secret)
markers = [x.name for x in request.node.iter_markers()]
groups = capabilities.get("groups", []) + markers
groups = capabilities.pop("groups", []) + markers
if groups:
capabilities["groups"] = groups
kwargs = {
options.set_capability("groups", groups)
return {
"command_executor": provider.executor,
"desired_capabilities": capabilities,
"options": options,
}
return kwargs


def _video_html(video_url, session):
Expand Down
Loading

0 comments on commit 8fb0894

Please sign in to comment.