Skip to content

Commit eca9892

Browse files
committed
fix implementation and unit tests
1 parent 729f2bd commit eca9892

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def enable_fedcm_delay(self, enable):
3333
privacy reasons. This method allows turning it off to let tests
3434
run faster where this is not relevant.
3535
"""
36-
self.execute("setFedCmDelay", {"enabled": enable})
36+
self.set_fedcm_delay(enable)
3737

3838
def fedcm_cooldown(self):
3939
"""Resets the FedCm dialog cooldown.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def subtitle(self) -> Optional[str]:
4646
result = self._driver.get_fedcm_subtitle()
4747
return result.get("subtitle") if result else None
4848

49-
@property
5049
def get_accounts(self) -> List[Account]:
5150
"""Gets the list of accounts shown in the dialog."""
5251
accounts = self._driver.get_fedcm_account_list()

py/selenium/webdriver/remote/command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ class Command:
127127
GET_FEDCM_TITLE: str = "getFedcmTitle"
128128
GET_FEDCM_DIALOG_TYPE: str = "getFedcmDialogType"
129129
GET_FEDCM_ACCOUNT_LIST: str = "getFedcmAccountList"
130+
SELECT_FEDCM_ACCOUNT: str = "selectFedcmAccount"
130131
CLICK_FEDCM_DIALOG_BUTTON: str = "clickFedcmDialogButton"
131132
CANCEL_FEDCM_DIALOG: str = "cancelFedcmDialog"
132-
SELECT_FEDCM_ACCOUNT: str = "selectFedcmAccount"
133133
SET_FEDCM_DELAY: str = "setFedcmDelay"
134134
RESET_FEDCM_COOLDOWN: str = "resetFedcmCooldown"

py/selenium/webdriver/remote/webdriver.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,29 +1224,33 @@ def delete_downloadable_files(self) -> None:
12241224
self.execute(Command.DELETE_DOWNLOADABLE_FILES)
12251225

12261226
# Federated Credential Management (FedCM)
1227-
def cancel_fedcm_dialog(self) -> None:
1228-
"""Cancels/dismisses the FedCM dialog."""
1229-
self.execute(Command.CANCEL_FEDCM_DIALOG)
1230-
1231-
def select_fedcm_account(self, index: int) -> None:
1232-
"""Selects an account from the dialog by index."""
1233-
self.execute(Command.SELECT_FEDCM_ACCOUNT, {"accountIndex": index})
1234-
1235-
def get_fedcm_dialog_type(self):
1236-
"""Gets the type of the dialog currently being shown."""
1237-
return self.execute(Command.GET_FEDCM_DIALOG_TYPE)
1238-
12391227
def get_fedcm_title(self) -> str:
12401228
"""Gets the title of the dialog."""
1241-
return self.execute(Command.GET_FEDCM_TITLE).get("title")
1229+
return self.execute(Command.GET_FEDCM_TITLE)["value"].get("title")
12421230

12431231
def get_fedcm_subtitle(self) -> Optional[str]:
12441232
"""Gets the subtitle of the dialog."""
1245-
return self.execute(Command.GET_FEDCM_TITLE).get("subtitle")
1233+
return self.execute(Command.GET_FEDCM_TITLE)["value"].get("subtitle")
1234+
1235+
def get_fedcm_dialog_type(self):
1236+
"""Gets the type of the dialog currently being shown."""
1237+
return self.execute(Command.GET_FEDCM_DIALOG_TYPE).get("value")
12461238

12471239
def get_fedcm_account_list(self):
12481240
"""Gets the list of accounts shown in the dialog."""
1249-
return self.execute(Command.GET_FEDCM_ACCOUNT_LIST)
1241+
return self.execute(Command.GET_FEDCM_ACCOUNT_LIST).get("value")
1242+
1243+
def select_fedcm_account(self, index: int) -> None:
1244+
"""Selects an account from the dialog by index."""
1245+
self.execute(Command.SELECT_FEDCM_ACCOUNT, {"accountIndex": index})
1246+
1247+
def click_fedcm_dialog_button(self) -> None:
1248+
"""Clicks the continue button in the dialog."""
1249+
self.execute(Command.CLICK_FEDCM_DIALOG_BUTTON, {"dialogButton": "ConfirmIdpLoginContinue"})
1250+
1251+
def cancel_fedcm_dialog(self) -> None:
1252+
"""Cancels/dismisses the FedCM dialog."""
1253+
self.execute(Command.CANCEL_FEDCM_DIALOG)
12501254

12511255
def set_fedcm_delay(self, enabled: bool) -> None:
12521256
"""Disables the promise rejection delay for FedCM.
@@ -1267,7 +1271,3 @@ def reset_fedcm_cooldown(self) -> None:
12671271
can be triggered again immediately.
12681272
"""
12691273
self.execute(Command.RESET_FEDCM_COOLDOWN)
1270-
1271-
def click_fedcm_dialog_button(self) -> None:
1272-
"""Clicks the continue button in the dialog."""
1273-
self.execute(Command.CLICK_FEDCM_DIALOG_BUTTON, {"dialogButton": "ConfirmIdpLoginContinue"})

py/test/unit/selenium/webdriver/common/fedcm/dialog_tests.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,31 @@ def dialog(mock_driver):
3434

3535
def test_click_continue(dialog, mock_driver):
3636
dialog.click_continue()
37-
mock_driver.execute.assert_called_with("clickFedCmDialogButton", {"dialogButton": "ConfirmIdpLoginContinue"})
37+
mock_driver.click_fedcm_dialog_button.assert_called_once()
3838

3939

4040
def test_cancel(dialog, mock_driver):
4141
dialog.cancel()
42-
mock_driver.execute.assert_called_with("cancelFedCmDialog")
42+
mock_driver.cancel_fedcm_dialog.assert_called_once()
4343

4444

4545
def test_select_account(dialog, mock_driver):
4646
dialog.select_account(1)
47-
mock_driver.execute.assert_called_with("selectFedCmAccount", {"accountIndex": 1})
47+
mock_driver.select_fedcm_account.assert_called_once_with(1)
4848

4949

5050
def test_type(dialog, mock_driver):
51-
mock_driver.execute.return_value = {"value": "AccountChooser"}
51+
mock_driver.get_fedcm_dialog_type.return_value = "AccountChooser"
5252
assert dialog.type == "AccountChooser"
5353

5454

5555
def test_title(dialog, mock_driver):
56-
mock_driver.execute.return_value = {"title": "Sign in"}
56+
mock_driver.get_fedcm_title.return_value = "Sign in"
5757
assert dialog.title == "Sign in"
5858

5959

6060
def test_subtitle(dialog, mock_driver):
61-
mock_driver.execute.return_value = {"subtitle": "Choose an account"}
61+
mock_driver.get_fedcm_subtitle.return_value = {"subtitle": "Choose an account"}
6262
assert dialog.subtitle == "Choose an account"
6363

6464

@@ -67,8 +67,10 @@ def test_get_accounts(dialog, mock_driver):
6767
{"name": "Account1", "email": "[email protected]"},
6868
{"name": "Account2", "email": "[email protected]"},
6969
]
70-
mock_driver.execute.return_value = accounts_data
70+
mock_driver.get_fedcm_account_list.return_value = accounts_data
7171
accounts = dialog.get_accounts()
7272
assert len(accounts) == 2
7373
assert accounts[0].name == "Account1"
7474
assert accounts[0].email == "[email protected]"
75+
assert accounts[1].name == "Account2"
76+
assert accounts[1].email == "[email protected]"

0 commit comments

Comments
 (0)