Skip to content

Commit

Permalink
Add clickDialogButton methods for FedCM
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cbiesinger committed Jun 4, 2024
1 parent 53ed43c commit 532fab7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public interface FederatedCredentialManagementDialog {
String DIALOG_TYPE_ACCOUNT_LIST = "AccountChooser";
String DIALOG_TYPE_AUTO_REAUTH = "AutoReauthn";

String BUTTON_CONFIRM_IDP_LOGIN_CONTINUE = "ConfirmIdpLoginContinue";
// The following buttons need an account index.
String BUTTON_TERMS_OF_SERVICE = "TermsOfService";
String BUTTON_PRIVACY_POLICY = "PrivacyPolicy";

/** Closes the dialog as if the user had clicked X. */
void cancelDialog();

Expand Down Expand Up @@ -58,4 +63,19 @@ public interface FederatedCredentialManagementDialog {
* <p>If this is an auto reauth dialog, returns the single account that is being signed in.
*/
List<FederatedCredentialManagementAccount> getAccounts();

/**
* Clicks a button on the dialog.
*
* @param button The button to click.
*/
void clickButton(String button);

/**
* Clicks a button on the dialog that requires an account index.
*
* @param button The button to click.
* @param index The account index, if needed by the specified button.
*/
void clickButton(String button, int index);
}
11 changes: 11 additions & 0 deletions java/src/org/openqa/selenium/remote/FedCmDialogImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,15 @@ public List<FederatedCredentialManagementAccount> getAccounts() {
}
return accounts;
}

@Override
public void clickButton(String button) {
executeMethod.execute(DriverCommand.CLICK_DIALOG, Map.of("dialogButton", button));
}

@Override
public void clickButton(String button, int index) {
executeMethod.execute(DriverCommand.CLICK_DIALOG,
Map.of("dialogButton", button, "index", index));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,35 @@ void testSelectAccount() {
response = jsAwareDriver.executeScript("return await promise");
assertThat(response).asInstanceOf(MAP).containsEntry("token", "a token");
}

@Test
@NotYetImplemented(
value = CHROME,
reason = "https://github.com/SeleniumHQ/selenium/pull/12096#issuecomment-2017760822")
void testClickDialogButton() {
fedcmDriver.setDelayEnabled(false);
assertNull(fedcmDriver.getFederatedCredentialManagementDialog());

Object response = triggerFedCm();

waitForDialog();

FederatedCredentialManagementDialog dialog =
fedcmDriver.getFederatedCredentialManagementDialog();

assertEquals("Sign in to localhost with localhost", dialog.getTitle());
assertEquals("AccountChooser", dialog.getDialogType());

dialog.clickButton(dialog.BUTTON_PRIVACY_POLICY, 1);
int windowCount = localDriver.getWindowHandles().size();
WebDriverWait wait = new WebDriverWait(localDriver, Duration.ofSeconds(5));
wait.until(
driver ->
driver.getWindowHandles().size() > windowCount);

dialog.selectAccount(0);

response = jsAwareDriver.executeScript("return await promise");
assertThat(response).asInstanceOf(MAP).containsEntry("token", "a token");
}
}

0 comments on commit 532fab7

Please sign in to comment.