Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] Add clickDialogButton methods for FedCM #14072

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());

int windowCount = localDriver.getWindowHandles().size();
dialog.clickButton(dialog.BUTTON_PRIVACY_POLICY, 1);
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");
}
}