Skip to content
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
11 changes: 3 additions & 8 deletions py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import socket
import subprocess
import time
from test.selenium.webdriver.common.network import get_lan_ip
from test.selenium.webdriver.common.webserver import SimpleWebServer
from urllib.request import urlopen

import pytest

from selenium import webdriver
from test.selenium.webdriver.common.network import get_lan_ip
from test.selenium.webdriver.common.webserver import SimpleWebServer

drivers = (
"chrome",
Expand Down Expand Up @@ -97,7 +97,7 @@ def pytest_ignore_collect(path, config):


def get_driver_class(driver_option):
"""Generate the driver class name from the lowercase driver option"""
"""Generate the driver class name from the lowercase driver option."""
if driver_option == "webkitgtk":
driver_class = "WebKitGTK"
elif driver_option == "wpewebkit":
Expand All @@ -113,10 +113,8 @@ def get_driver_class(driver_option):
@pytest.fixture(scope="function")
def driver(request):
kwargs = {}

# browser can be changed with `--driver=firefox` as an argument or to addopts in pytest.ini
driver_class = get_driver_class(getattr(request, "param", "Chrome"))

# skip tests if not available on the platform
_platform = platform.system()
if driver_class == "Safari" and _platform != "Darwin":
Expand All @@ -125,12 +123,10 @@ def driver(request):
pytest.skip("IE and EdgeHTML Tests can only run on Windows")
if "WebKit" in driver_class and _platform == "Windows":
pytest.skip("WebKit tests cannot be run on Windows")

# skip tests for drivers that don't support BiDi when --bidi is enabled
if request.config.option.bidi:
if driver_class in ("Ie", "Safari", "WebKitGTK", "WPEWebKit"):
pytest.skip(f"{driver_class} does not support BiDi")

# conditionally mark tests as expected to fail based on driver
marker = request.node.get_closest_marker(f"xfail_{driver_class.lower()}")

Expand Down Expand Up @@ -182,7 +178,6 @@ def fin():

driver_instance = getattr(webdriver, driver_class)(**kwargs)
yield driver_instance

# Close the browser after BiDi tests. Those make event subscriptions
# and doesn't seems to be stable enough, causing the flakiness of the
# subsequent tests.
Expand Down
31 changes: 26 additions & 5 deletions py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,36 @@ ignore_missing_imports = true
# Automatically keep imports alphabetically sorted, on single lines in
# PEP recommended sections (https://peps.python.org/pep-0008/#imports)
# files or individual lines can be ignored via `# isort:skip|# isort:skip_file`.
profile = "black"
py_version=39
force_single_line = true
profile = "black"
py_version = 39
quiet = true
skip = "selenium/webdriver/common/devtools"

[tool.black]
extend-exclude = 'selenium/webdriver/common/devtools'
extend-exclude = "selenium/webdriver/common/devtools"
line-length = 120
target-version = ['py39']
target-version = ["py39"]

[tool.autoflake]
exclude = "selenium/webdriver/common/devtools"
ignore-pass-after-docstring = true
in-place = true
quiet = true
recursive = true
remove-all-unused-imports = true
remove-duplicate-keys = true
remove-unused-variables = true

[tool.flake8]
exclude = "selenium/webdriver/common/devtools"
# Disable E501 once line length is better handled
extend-ignore = ["E501", "E203"]
# This does nothing for now as E501 is ignored
max-line-length = 120
min-python-version = "3.9"

[tool.docformatter]
exclude = 'selenium/webdriver/common/devtools'
exclude = "selenium/webdriver/common/devtools"
in-place = true
recursive = true
12 changes: 6 additions & 6 deletions py/selenium/webdriver/support/expected_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _predicate(driver: WebDriver):


def visibility_of_element_located(
locator: Tuple[str, str]
locator: Tuple[str, str],
) -> Callable[[WebDriverOrWebElement], Union[Literal[False], WebElement]]:
"""An expectation for checking that an element is present on the DOM of a
page and visible. Visibility means that the element is not only displayed
Expand Down Expand Up @@ -337,7 +337,7 @@ def _predicate(driver: WebDriverOrWebElement):


def visibility_of_all_elements_located(
locator: Tuple[str, str]
locator: Tuple[str, str],
) -> Callable[[WebDriverOrWebElement], Union[List[WebElement], Literal[False]]]:
"""An expectation for checking that all elements are present on the DOM of
a page and visible. Visibility means that the elements are not only
Expand Down Expand Up @@ -486,7 +486,7 @@ def _predicate(driver: WebDriverOrWebElement):


def frame_to_be_available_and_switch_to_it(
locator: Union[Tuple[str, str], str, WebElement]
locator: Union[Tuple[str, str], str, WebElement],
) -> Callable[[WebDriver], bool]:
"""An expectation for checking whether the given frame is available to
switch to.
Expand Down Expand Up @@ -527,7 +527,7 @@ def _predicate(driver: WebDriver):


def invisibility_of_element_located(
locator: Union[WebElement, Tuple[str, str]]
locator: Union[WebElement, Tuple[str, str]],
) -> Callable[[WebDriverOrWebElement], Union[WebElement, bool]]:
"""An Expectation for checking that an element is either invisible or not
present on the DOM.
Expand Down Expand Up @@ -576,7 +576,7 @@ def _predicate(driver: WebDriverOrWebElement):


def invisibility_of_element(
element: Union[WebElement, Tuple[str, str]]
element: Union[WebElement, Tuple[str, str]],
) -> Callable[[WebDriverOrWebElement], Union[WebElement, bool]]:
"""An Expectation for checking that an element is either invisible or not
present on the DOM.
Expand All @@ -602,7 +602,7 @@ def invisibility_of_element(


def element_to_be_clickable(
mark: Union[WebElement, Tuple[str, str]]
mark: Union[WebElement, Tuple[str, str]],
) -> Callable[[WebDriverOrWebElement], Union[Literal[False], WebElement]]:
"""An Expectation for checking an element is visible and enabled such that
you can click it.
Expand Down
59 changes: 31 additions & 28 deletions py/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ envlist = docs, flake8, isort, validate-pyproject
[testenv:validate-pyproject]
skip_install = true
deps =
validate-pyproject==0.23
packaging==24.2
validate-pyproject==0.24.1
packaging==25.0
commands =
validate-pyproject ./pyproject.toml

Expand Down Expand Up @@ -33,42 +33,45 @@ deps =
commands = mypy --install-types {posargs}

[testenv:linting-ci]
; checks linting for CI with stricter exiting when failing.
; checks linting for CI with stricter exiting when failing and no rewriting
skip_install = true
deps =
isort==5.13.2
black==24.1.1
flake8==6.1.0
flake8-typing-imports==1.14.0
isort==6.0.1
black==25.1.0
autoflake==2.3.1
flake8==7.1.2
flake8-pyproject==1.2.3
flake8-typing-imports==1.16.0
docformatter==1.7.5
commands =
; execute isort in check only mode.
isort --check-only --diff selenium/ test/ conftest.py
; execute black in check only mode with diff.
black --check --diff selenium/ test/ conftest.py -l 120
flake8 selenium/ test/ --min-python-version=3.9
docformatter --check -r selenium/
black --check --diff selenium/ test/ conftest.py
autoflake --check-diff selenium/ test/ conftest.py
flake8 selenium/ test/ conftest.py
docformatter --check --diff selenium/ test/ conftest.py

[testenv:linting]
; A consolidated linting based recipe, responsible for executing linting tools across the code base.
; This encompasses isort for imports, black for general formatting and flake8.
; IMPORTANT: black & isort rewrite files, flake8 merely alerts to the failure.
; This encompasses:
; - isort for imports
; - black and flake8 for general formatting
; - autoflake for unused imports and variables
; - docformatter for docstrings
; IMPORTANT:
; - isort, black, autoflake, docformatter: will rewrite files
; - flake8: only alerts to the failures
skip_install = true
deps =
isort==5.13.2
black==24.1.1
flake8==6.1.0
flake8-typing-imports==1.14.0
isort==6.0.1
black==25.1.0
autoflake==2.3.1
flake8==7.1.2
flake8-pyproject==1.2.3
flake8-typing-imports==1.16.0
docformatter==1.7.5
commands =
isort selenium/ test/ conftest.py
black selenium/ test/ conftest.py -l 120
flake8 selenium/ test/ --min-python-version=3.9
docformatter --in-place -r selenium/

[flake8]
exclude = .tox,selenium/webdriver/common/devtools,docs/source/conf.py,*venv
# Disable this once black is applied throughout & line length is better handled.
extend-ignore = E501, E203
# This does nothing for now as E501 is ignored.
max-line-length = 120
black selenium/ test/ conftest.py
autoflake selenium/ test/ conftest.py
flake8 selenium/ test/ conftest.py
docformatter selenium/ test/ conftest.py
Loading