Skip to content

Commit 7badb78

Browse files
committed
Add clickDialogButton methods for FedCM
This builds on commit 7ad44ee The specification for clickdialogbutton is here: https://fedidcg.github.io/FedCM/#webdriver-clickdialogbutton The version that takes an index is specified here: w3c-fedid/FedCM#610 Bug #12088
1 parent 8ac19e4 commit 7badb78

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

java/src/org/openqa/selenium/federatedcredentialmanagement/FederatedCredentialManagementDialog.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public interface FederatedCredentialManagementDialog {
2929
String DIALOG_TYPE_ACCOUNT_LIST = "AccountChooser";
3030
String DIALOG_TYPE_AUTO_REAUTH = "AutoReauthn";
3131

32+
String BUTTON_CONFIRM_IDP_LOGIN_CONTINUE = "ConfirmIdpLoginContinue";
33+
// The following buttons need an account index.
34+
String BUTTON_TERMS_OF_SERVICE = "TermsOfService";
35+
String BUTTON_PRIVACY_POLICY = "PrivacyPolicy";
36+
3237
/** Closes the dialog as if the user had clicked X. */
3338
void cancelDialog();
3439

@@ -58,4 +63,19 @@ public interface FederatedCredentialManagementDialog {
5863
* <p>If this is an auto reauth dialog, returns the single account that is being signed in.
5964
*/
6065
List<FederatedCredentialManagementAccount> getAccounts();
66+
67+
/**
68+
* Clicks a button on the dialog.
69+
*
70+
* @param button The button to click.
71+
*/
72+
void clickButton(String button);
73+
74+
/**
75+
* Clicks a button on the dialog that requires an account index.
76+
*
77+
* @param button The button to click.
78+
* @param index The account index, if needed by the specified button.
79+
*/
80+
void clickButton(String button, int index);
6181
}

java/src/org/openqa/selenium/remote/FedCmDialogImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,15 @@ public List<FederatedCredentialManagementAccount> getAccounts() {
7070
}
7171
return accounts;
7272
}
73+
74+
@Override
75+
public void clickButton(String button) {
76+
executeMethod.execute(DriverCommand.CLICK_DIALOG, Map.of("dialogButton", button));
77+
}
78+
79+
@Override
80+
public void clickButton(String button, int index) {
81+
executeMethod.execute(DriverCommand.CLICK_DIALOG,
82+
Map.of("dialogButton", button, "index", index));
83+
}
7384
}

java/test/org/openqa/selenium/federatedcredentialmanagement/FederatedCredentialManagementTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,35 @@ void testSelectAccount() {
138138
response = jsAwareDriver.executeScript("return await promise");
139139
assertThat(response).asInstanceOf(MAP).containsEntry("token", "a token");
140140
}
141+
142+
@Test
143+
@NotYetImplemented(
144+
value = CHROME,
145+
reason = "https://github.com/SeleniumHQ/selenium/pull/12096#issuecomment-2017760822")
146+
void testClickDialogButton() {
147+
fedcmDriver.setDelayEnabled(false);
148+
assertNull(fedcmDriver.getFederatedCredentialManagementDialog());
149+
150+
Object response = triggerFedCm();
151+
152+
waitForDialog();
153+
154+
FederatedCredentialManagementDialog dialog =
155+
fedcmDriver.getFederatedCredentialManagementDialog();
156+
157+
assertEquals("Sign in to localhost with localhost", dialog.getTitle());
158+
assertEquals("AccountChooser", dialog.getDialogType());
159+
160+
int windowCount = localDriver.getWindowHandles().size();
161+
dialog.clickButton(dialog.BUTTON_PRIVACY_POLICY, 1);
162+
WebDriverWait wait = new WebDriverWait(localDriver, Duration.ofSeconds(5));
163+
wait.until(
164+
driver ->
165+
driver.getWindowHandles().size() > windowCount);
166+
167+
dialog.selectAccount(0);
168+
169+
response = jsAwareDriver.executeScript("return await promise");
170+
assertThat(response).asInstanceOf(MAP).containsEntry("token", "a token");
171+
}
141172
}

0 commit comments

Comments
 (0)