Skip to content

Commit 9e52be8

Browse files
committed
remove mixin and implement in remote webdriver
1 parent 2a2772a commit 9e52be8

File tree

5 files changed

+94
-70
lines changed

5 files changed

+94
-70
lines changed

py/selenium/webdriver/chromium/webdriver.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
# under the License.
1717

1818
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
19-
from selenium.webdriver.common.driver_extensions.has_fedcm_dialog import HasFedCmDialog
2019
from selenium.webdriver.common.driver_finder import DriverFinder
2120
from selenium.webdriver.common.options import ArgOptions
2221
from selenium.webdriver.common.service import Service
2322
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
2423

2524

26-
class ChromiumDriver(HasFedCmDialog, RemoteWebDriver):
25+
class ChromiumDriver(RemoteWebDriver):
2726
"""Controls the WebDriver instance of ChromiumDriver and allows you to
2827
drive the browser."""
2928

py/selenium/webdriver/common/driver_extensions/has_fedcm_dialog.py

Lines changed: 0 additions & 66 deletions
This file was deleted.

py/selenium/webdriver/common/options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ def ignore_local_proxy_environment_variables(self) -> None:
491491

492492
class ArgOptions(BaseOptions):
493493
BINARY_LOCATION_ERROR = "Binary Location Must be a String"
494+
# FedCM capability key
495+
FEDCM_CAPABILITY = "fedcm:accounts"
494496

495497
def __init__(self) -> None:
496498
super().__init__()

py/selenium/webdriver/remote/webdriver.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from selenium.common.exceptions import WebDriverException
4444
from selenium.webdriver.common.bidi.script import Script
4545
from selenium.webdriver.common.by import By
46+
from selenium.webdriver.common.options import ArgOptions
4647
from selenium.webdriver.common.options import BaseOptions
4748
from selenium.webdriver.common.print_page_options import PrintOptions
4849
from selenium.webdriver.common.timeouts import Timeouts
@@ -53,6 +54,7 @@
5354
)
5455
from selenium.webdriver.support.relative_locator import RelativeBy
5556

57+
from ..common.fedcm.dialog import Dialog
5658
from .bidi_connection import BidiConnection
5759
from .client_config import ClientConfig
5860
from .command import Command
@@ -1245,3 +1247,90 @@ def fedcm(self) -> FedCM:
12451247
driver.fedcm.reset_cooldown()
12461248
"""
12471249
return self._fedcm
1250+
1251+
@property
1252+
def supports_fedcm(self) -> bool:
1253+
"""Returns whether the browser supports FedCM capabilities."""
1254+
return self.capabilities.get(ArgOptions.FEDCM_CAPABILITY, False)
1255+
1256+
def _require_fedcm_support(self):
1257+
"""Raises an exception if FedCM is not supported."""
1258+
if not self.supports_fedcm:
1259+
raise WebDriverException(
1260+
"This browser does not support Federated Credential Management. "
1261+
"Please ensure you're using a supported browser."
1262+
)
1263+
1264+
@property
1265+
def dialog(self):
1266+
"""Returns the FedCM dialog object for interaction."""
1267+
self._require_fedcm_support()
1268+
return Dialog(self)
1269+
1270+
def enable_fedcm_delay(self):
1271+
"""Enables the promise rejection delay for FedCM.
1272+
1273+
Raises:
1274+
WebDriverException if FedCM not supported
1275+
"""
1276+
self._require_fedcm_support()
1277+
self.fedcm.enable_delay()
1278+
1279+
def disable_fedcm_delay(self):
1280+
"""Disables the promise rejection delay for FedCM.
1281+
1282+
FedCM by default delays promise resolution in failure cases for
1283+
privacy reasons. This method allows turning it off to let tests
1284+
run faster where this is not relevant.
1285+
1286+
Raises:
1287+
WebDriverException if FedCM not supported
1288+
"""
1289+
self._require_fedcm_support()
1290+
self.fedcm.disable_delay()
1291+
1292+
def reset_fedcm_cooldown(self):
1293+
"""Resets the FedCM dialog cooldown.
1294+
1295+
If a user agent triggers a cooldown when the account chooser is
1296+
dismissed, this method resets that cooldown so that the dialog
1297+
can be triggered again immediately.
1298+
1299+
Raises:
1300+
WebDriverException if FedCM not supported
1301+
"""
1302+
self._require_fedcm_support()
1303+
self.fedcm.reset_cooldown()
1304+
1305+
def fedcm_dialog(self, timeout=5, poll_frequency=0.5, ignored_exceptions=None):
1306+
"""Waits for and returns the FedCM dialog.
1307+
1308+
Args:
1309+
timeout: How long to wait for the dialog
1310+
poll_frequency: How frequently to poll
1311+
ignored_exceptions: Exceptions to ignore while waiting
1312+
1313+
Returns:
1314+
The FedCM dialog object if found
1315+
1316+
Raises:
1317+
TimeoutException if dialog doesn't appear
1318+
WebDriverException if FedCM not supported
1319+
"""
1320+
from selenium.common.exceptions import NoAlertPresentException
1321+
from selenium.webdriver.support.wait import WebDriverWait
1322+
1323+
self._require_fedcm_support()
1324+
1325+
if ignored_exceptions is None:
1326+
ignored_exceptions = (NoAlertPresentException,)
1327+
1328+
def _check_fedcm():
1329+
try:
1330+
dialog = Dialog(self)
1331+
return dialog if dialog.type else None
1332+
except NoAlertPresentException:
1333+
return None
1334+
1335+
wait = WebDriverWait(self, timeout, poll_frequency=poll_frequency, ignored_exceptions=ignored_exceptions)
1336+
return wait.until(lambda _: _check_fedcm())

py/test/selenium/webdriver/common/fedcm_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_disable_fedcm_delay(self, driver):
100100
driver.fedcm.disable_delay()
101101

102102
def test_fedcm_cooldown_reset(self, driver):
103-
driver.fedcm_cooldown()
103+
driver.reset_fedcm_cooldown()
104104

105105
def test_fedcm_no_dialog_type_present(self, driver):
106106
with pytest.raises(NoAlertPresentException):
@@ -131,7 +131,7 @@ def test_fedcm_no_click_continue_present(self, driver):
131131
driver.fedcm.click_continue()
132132

133133
def test_verify_dialog_type_after_cooldown_reset(self, driver):
134-
driver.fedcm_cooldown()
134+
driver.reset_fedcm_cooldown()
135135
driver.execute_script("triggerFedCm();")
136136
dialog = driver.fedcm_dialog()
137137
assert dialog.type == "AccountChooser"

0 commit comments

Comments
 (0)