Skip to content

Commit c2f5115

Browse files
committed
move fedcm commands to a new fedcm namespace
1 parent 1559f8f commit c2f5115

File tree

3 files changed

+90
-16
lines changed

3 files changed

+90
-16
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@ class HasFedCmDialog(WebDriver):
2222
"""Mixin that provides FedCM-specific functionality."""
2323

2424
@property
25-
def fedcm_dialog(self):
25+
def dialog(self):
2626
"""Returns the FedCM dialog object for interaction."""
2727
return Dialog(self)
2828

29-
def enable_fedcm_delay(self, enable):
30-
"""Disables the promise rejection delay for FedCm.
29+
def enable_fedcm_delay(self):
30+
"""Re-enables the promise rejection delay for FedCM."""
31+
self.fedcm.enable_delay()
32+
33+
def disable_fedcm_delay(self):
34+
"""Disables the promise rejection delay for FedCM.
3135
3236
FedCm by default delays promise resolution in failure cases for
3337
privacy reasons. This method allows turning it off to let tests
3438
run faster where this is not relevant.
3539
"""
36-
self.set_fedcm_delay(enable)
40+
self.fedcm.disable_delay()
3741

3842
def fedcm_cooldown(self):
3943
"""Resets the FedCm dialog cooldown.
@@ -42,21 +46,21 @@ def fedcm_cooldown(self):
4246
dismissed, this method resets that cooldown so that the dialog
4347
can be triggered again immediately.
4448
"""
45-
self.reset_fedcm_cooldown()
49+
self.fedcm.reset_cooldown()
4650

47-
def wait_for_fedcm_dialog(self, timeout=5, poll_frequency=0.5, ignored_exceptions=None):
51+
def fedcm_dialog(self, timeout=5, poll_frequency=0.5, ignored_exceptions=None):
4852
"""Waits for the FedCM dialog to appear."""
4953
from selenium.common.exceptions import NoAlertPresentException
5054
from selenium.webdriver.support.wait import WebDriverWait
5155

5256
if ignored_exceptions is None:
5357
ignored_exceptions = (NoAlertPresentException,)
5458

55-
def check_fedcm():
59+
def _check_fedcm():
5660
try:
57-
return self.fedcm_dialog if self.fedcm_dialog.type else None
61+
return self.dialog if self.dialog.type else None
5862
except NoAlertPresentException:
5963
return None
6064

6165
wait = WebDriverWait(self, timeout, poll_frequency=poll_frequency, ignored_exceptions=ignored_exceptions)
62-
return wait.until(lambda _: check_fedcm())
66+
return wait.until(lambda _: _check_fedcm())

py/selenium/webdriver/common/fedcm/dialog.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,32 @@ def __init__(self, driver) -> None:
3333
@property
3434
def type(self) -> Optional[str]:
3535
"""Gets the type of the dialog currently being shown."""
36-
return self._driver.get_fedcm_dialog_type()
36+
return self._driver.fedcm.dialog_type
3737

3838
@property
3939
def title(self) -> str:
4040
"""Gets the title of the dialog."""
41-
return self._driver.get_fedcm_title()
41+
return self._driver.fedcm.title
4242

4343
@property
4444
def subtitle(self) -> Optional[str]:
4545
"""Gets the subtitle of the dialog."""
46-
result = self._driver.get_fedcm_subtitle()
46+
result = self._driver.fedcm.subtitle
4747
return result.get("subtitle") if result else None
4848

4949
def get_accounts(self) -> List[Account]:
5050
"""Gets the list of accounts shown in the dialog."""
51-
accounts = self._driver.get_fedcm_account_list()
51+
accounts = self._driver.fedcm.account_list
5252
return [Account(account) for account in accounts]
5353

5454
def select_account(self, index: int) -> None:
5555
"""Selects an account from the dialog by index."""
56-
self._driver.select_fedcm_account(index)
56+
self._driver.fedcm.select_account(index)
5757

5858
def click_continue(self) -> None:
5959
"""Clicks the continue button in the dialog."""
60-
self._driver.click_fedcm_dialog_button()
60+
self._driver.fedcm.click_continue()
6161

6262
def cancel(self) -> None:
6363
"""Cancels/dismisses the dialog."""
64-
self._driver.cancel_fedcm_dialog()
64+
self._driver.fedcm.cancel_dialog()
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from typing import List
19+
from typing import Optional
20+
21+
from .command import Command
22+
23+
24+
class FedCM:
25+
def __init__(self, driver) -> None:
26+
self._driver = driver
27+
28+
@property
29+
def title(self) -> str:
30+
"""Gets the title of the dialog."""
31+
return self._driver.execute(Command.GET_FEDCM_TITLE)["value"].get("title")
32+
33+
@property
34+
def subtitle(self) -> Optional[str]:
35+
"""Gets the subtitle of the dialog."""
36+
return self._driver.execute(Command.GET_FEDCM_TITLE)["value"].get("subtitle")
37+
38+
@property
39+
def dialog_type(self) -> str:
40+
"""Gets the type of the dialog currently being shown."""
41+
return self._driver.execute(Command.GET_FEDCM_DIALOG_TYPE).get("value")
42+
43+
@property
44+
def account_list(self) -> List[dict]:
45+
"""Gets the list of accounts shown in the dialog."""
46+
return self._driver.execute(Command.GET_FEDCM_ACCOUNT_LIST).get("value")
47+
48+
def select_account(self, index: int) -> None:
49+
"""Selects an account from the dialog by index."""
50+
self._driver.execute(Command.SELECT_FEDCM_ACCOUNT, {"accountIndex": index})
51+
52+
def click_continue(self) -> None:
53+
"""Clicks the continue button in the dialog."""
54+
self._driver.execute(Command.CLICK_FEDCM_DIALOG_BUTTON, {"dialogButton": "ConfirmIdpLoginContinue"})
55+
56+
def cancel_dialog(self) -> None:
57+
"""Cancels/dismisses the FedCM dialog."""
58+
self._driver.execute(Command.CANCEL_FEDCM_DIALOG)
59+
60+
def enable_delay(self) -> None:
61+
"""Re-enables the promise rejection delay for FedCM."""
62+
self._driver.execute(Command.SET_FEDCM_DELAY, {"enabled": True})
63+
64+
def disable_delay(self) -> None:
65+
"""Disables the promise rejection delay for FedCM."""
66+
self._driver.execute(Command.SET_FEDCM_DELAY, {"enabled": False})
67+
68+
def reset_cooldown(self) -> None:
69+
"""Resets the FedCM dialog cooldown, allowing immediate retriggers."""
70+
self._driver.execute(Command.RESET_FEDCM_COOLDOWN)

0 commit comments

Comments
 (0)