Skip to content
Open
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
49 changes: 47 additions & 2 deletions py/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ py_library(
exclude = [
"selenium/webdriver/common/action_chains.py",
"selenium/webdriver/common/actions/**",
"selenium/webdriver/common/alert.py",
"selenium/webdriver/common/api_request_context.py",
"selenium/webdriver/common/bidi/**",
"selenium/webdriver/common/devtools/**",
Expand Down Expand Up @@ -336,6 +337,17 @@ py_library(
],
)

py_library(
name = "common_alert",
srcs = ["selenium/webdriver/common/alert.py"],
imports = ["."],
visibility = ["//visibility:public"],
deps = [
":common",
":remote",
],
)

py_library(
name = "common_api_request_context",
srcs = ["selenium/webdriver/common/api_request_context.py"],
Expand Down Expand Up @@ -387,7 +399,10 @@ py_library(
# Support utilities (wait conditions, event listeners, etc.)
py_library(
name = "support",
srcs = glob(["selenium/webdriver/support/**/*.py"]),
srcs = glob(
["selenium/webdriver/support/**/*.py"],
exclude = ["selenium/webdriver/support/color.py"],
),
imports = ["."],
visibility = ["//visibility:public"],
deps = [
Expand All @@ -397,6 +412,14 @@ py_library(
],
)

py_library(
name = "support_color",
srcs = ["selenium/webdriver/support/color.py"],
imports = ["."],
visibility = ["//visibility:public"],
deps = [],
)

# Chromium base (shared by Chrome and Edge)
py_library(
name = "chromium",
Expand Down Expand Up @@ -513,6 +536,7 @@ py_library(
":chromium",
":common",
":common_actions",
":common_alert",
":common_api_request_context",
":common_fedcm",
":common_print_page_options",
Expand All @@ -525,6 +549,7 @@ py_library(
":remote",
":safari",
":support",
":support_color",
":webkitgtk",
":wpewebkit",
],
Expand Down Expand Up @@ -762,7 +787,24 @@ VIRTUAL_AUTH_TESTS = ["test/selenium/webdriver/common/virtual_authenticator_test

API_REQUEST_TESTS = ["test/selenium/webdriver/common/api_request_context_tests.py"]

FEATURE_TESTS = FEDCM_TESTS + TIMEOUTS_TESTS + VIRTUAL_AUTH_TESTS + API_REQUEST_TESTS
# alerts_tests.py and webdriverwait_tests.py both call driver.switch_to.alert,
# requiring :common_alert at runtime, so they share a sub-suite.
ALERT_TESTS = [
"test/selenium/webdriver/common/alerts_tests.py",
"test/selenium/webdriver/common/webdriverwait_tests.py",
]

# rendered_webelement_tests.py is the only browser test that imports Color.
RENDERED_WEBELEMENT_TESTS = ["test/selenium/webdriver/common/rendered_webelement_tests.py"]

FEATURE_TESTS = (
FEDCM_TESTS +
TIMEOUTS_TESTS +
VIRTUAL_AUTH_TESTS +
API_REQUEST_TESTS +
ALERT_TESTS +
RENDERED_WEBELEMENT_TESTS
)

# Test files that import from selenium.webdriver.common.actions / action_chains.
# These are kept separate so they can depend on :common_actions without pulling
Expand Down Expand Up @@ -908,6 +950,8 @@ FEATURE_SUITE_DEFS = {
"timeouts": (TIMEOUTS_TESTS, ":common_timeouts"),
"virtual-auth": (VIRTUAL_AUTH_TESTS, ":common_virtual_authenticator"),
"api-request": (API_REQUEST_TESTS, ":common_api_request_context"),
"alerts": (ALERT_TESTS, ":common_alert"),
"rendered": (RENDERED_WEBELEMENT_TESTS, ":support_color"),
}

# Generate test-<browser>-<feature> targets (non-bidi, one per feature library)
Expand Down Expand Up @@ -966,6 +1010,7 @@ FEATURE_SUITE_DEFS = {
target_compatible_with = BROWSERS[browser]["target_compatible_with"],
test_suffix = "%s-bidi" % browser,
deps = [
":common_alert", # bidi_browsing_context_tests.py calls EC.alert_is_present()
":init-tree",
":webserver",
] + BROWSER_TESTS[browser]["deps"] + TEST_DEPS,
Expand Down
10 changes: 9 additions & 1 deletion py/selenium/webdriver/remote/switch_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@
# under the License.


from __future__ import annotations

from typing import TYPE_CHECKING

from selenium.common.exceptions import NoSuchElementException, NoSuchFrameException, NoSuchWindowException
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.command import Command
from selenium.webdriver.remote.webelement import WebElement

if TYPE_CHECKING:
from selenium.webdriver.common.alert import Alert


class SwitchTo:
def __init__(self, driver) -> None:
Expand All @@ -45,6 +51,8 @@ def alert(self) -> Alert:
Example:
alert = driver.switch_to.alert
"""
from selenium.webdriver.common.alert import Alert

alert = Alert(self._driver)
_ = alert.text
return alert
Expand Down
8 changes: 6 additions & 2 deletions py/selenium/webdriver/support/expected_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
# specific language governing permissions and limitations
# under the License.

from __future__ import annotations

import re
from collections.abc import Callable, Iterable
from typing import Any, Literal, TypeVar
from typing import TYPE_CHECKING, Any, Literal, TypeVar

from selenium.common.exceptions import (
NoAlertPresentException,
Expand All @@ -26,9 +28,11 @@
StaleElementReferenceException,
WebDriverException,
)
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.remote.webdriver import WebDriver, WebElement

if TYPE_CHECKING:
from selenium.webdriver.common.alert import Alert

"""
* Canned "Expected Conditions" which are generally useful within webdriver
* tests.
Expand Down
Loading