Skip to content

Commit 85e560e

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 53ed43c commit 85e560e

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"privacy_policy_url": "https://rp.example/privacy_policy.html",
3-
"terms_of_service_url": "https://rp.example/terms_of_service.html"
2+
"privacy_policy_url": "privacy_policy.html",
3+
"terms_of_service_url": "terms_of_service.html"
44
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!DOCTYPE html>
2+
<title>Privacy Policy</title>
3+
4+
This is the privacy policy.

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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,31 @@ void testSelectAccount() {
138138
response = jsAwareDriver.executeScript("return await promise");
139139
assertThat(response).asInstanceOf(MAP).containsEntry("token", "a token");
140140
}
141+
142+
void testClickDialogButton() {
143+
fedcmDriver.setDelayEnabled(false);
144+
assertNull(fedcmDriver.getFederatedCredentialManagementDialog());
145+
146+
Object response = triggerFedCm();
147+
148+
waitForDialog();
149+
150+
FederatedCredentialManagementDialog dialog =
151+
fedcmDriver.getFederatedCredentialManagementDialog();
152+
153+
assertEquals("Sign in to localhost with localhost", dialog.getTitle());
154+
assertEquals("AccountChooser", dialog.getDialogType());
155+
156+
dialog.clickButton(dialog.BUTTON_PRIVACY_POLICY);
157+
int windowCount = localDriver.getWindowHandles().size();
158+
WebDriverWait wait = new WebDriverWait(localDriver, Duration.ofSeconds(5));
159+
wait.until(
160+
driver ->
161+
driver.getWindowHandles().size() > windowCount);
162+
163+
dialog.selectAccount(0);
164+
165+
response = jsAwareDriver.executeScript("return await promise");
166+
assertThat(response).asInstanceOf(MAP).containsEntry("token", "a token");
167+
}
141168
}

0 commit comments

Comments
 (0)