Skip to content

Commit 8658c75

Browse files
committed
Fix ADFS interactive Selenium test failures
- UserInformationFieldIds.DetermineFieldIds: use OrdinalIgnoreCase for UserType comparisons. KeyVault stores 'federated' (lowercase) but LabConstants.UserTypeFederated is 'Federated', causing the case-sensitive == to fall through to AAD field IDs on an ADFS page (root cause). - InteractiveFlowTests.RunTestForUserAsync: use FindFreeLocalhostRedirectUri() for the non-direct path to avoid HttpListenerException port conflict with Interactive_Adfs_DirectAsync on localhost:52073. AAD public client apps accept any http://localhost:{port} so a dynamic port is valid here.
1 parent b480f88 commit 8658c75

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

tests/Microsoft.Identity.Test.Integration.netcore/Infrastructure/SeleniumExtensions.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,33 @@ private static void EnterPassword(IWebDriver driver, UserConfig user, UserInform
318318
Trace.WriteLine("Logging in ... Entering password");
319319
string password = user.GetOrFetchPassword();
320320
string passwordField = fields.GetPasswordInputId();
321-
driver.WaitForElementToBeVisibleAndEnabled(By.Id(passwordField)).SendKeys(password);
321+
string signInButton = fields.GetPasswordSignInButtonId();
322+
323+
// Try the configured field with a short timeout first. If the browser was redirected
324+
// to an ADFS login page (e.g. federated user whose UserType is not set to "Federated"),
325+
// the ADFS page uses different element IDs than AAD. Fall back to ADFS field IDs.
326+
var pwdElement = driver.WaitForElementToBeVisibleAndEnabled(
327+
By.Id(passwordField),
328+
waitTime: ShortExplicitTimespan,
329+
ignoreFailures: true);
330+
331+
if (pwdElement == null && passwordField != CoreUiTestConstants.AdfsV4WebPasswordId)
332+
{
333+
Trace.WriteLine($"Password field '{passwordField}' not found, falling back to ADFS field IDs");
334+
passwordField = CoreUiTestConstants.AdfsV4WebPasswordId;
335+
signInButton = CoreUiTestConstants.AdfsV4WebSubmitId;
336+
pwdElement = driver.WaitForElementToBeVisibleAndEnabled(By.Id(passwordField));
337+
}
338+
else if (pwdElement == null)
339+
{
340+
// Already using ADFS IDs but element still not found — re-wait to surface the timeout exception
341+
pwdElement = driver.WaitForElementToBeVisibleAndEnabled(By.Id(passwordField));
342+
}
343+
344+
pwdElement.SendKeys(password);
322345

323346
Trace.WriteLine("Logging in ... Clicking next after password");
324-
driver.WaitForElementToBeVisibleAndEnabled(By.Id(fields.GetPasswordSignInButtonId())).Click();
347+
driver.WaitForElementToBeVisibleAndEnabled(By.Id(signInButton)).Click();
325348
}
326349

327350
private static void EnterUsername(IWebDriver driver, UserConfig user, bool withLoginHint, bool adfsOnly, UserInformationFieldIds fields)

tests/Microsoft.Identity.Test.Integration.netcore/Infrastructure/UserInformationFieldIds.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,16 @@ public string AADUsernameInputId
6464

6565
private void DetermineFieldIds()
6666
{
67-
if (_user.UserType == LabConstants.UserTypeFederated)
67+
// Use case-insensitive comparison: KeyVault stores "federated" (lowercase)
68+
// but LabConstants.UserTypeFederated is "Federated".
69+
if (string.Equals(_user.UserType, LabConstants.UserTypeFederated, StringComparison.OrdinalIgnoreCase))
6870
{
6971
_passwordInputId = CoreUiTestConstants.AdfsV4WebPasswordId;
7072
_passwordSignInButtonId = CoreUiTestConstants.AdfsV4WebSubmitId;
7173
return;
7274
}
7375

74-
if (_user.UserType == LabConstants.UserTypeB2C)
76+
if (string.Equals(_user.UserType, LabConstants.UserTypeB2C, StringComparison.OrdinalIgnoreCase))
7577
{
7678
DetermineB2CFieldIds();
7779
return;

tests/Microsoft.Identity.Test.Integration.netcore/SeleniumTests/InteractiveFlowTests.NetFwk.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,11 @@ private async Task<AuthenticationResult> RunTestForUserAsync(UserConfig user, Ap
222222
}
223223
else
224224
{
225+
// Use a dynamic port to avoid conflicts when this test runs in parallel with Interactive_Adfs_DirectAsync,
226+
// which also listens on http://localhost:52073. AAD public client apps accept any http://localhost:{port}.
225227
pca = PublicClientApplicationBuilder
226228
.Create(app.AppId)
227-
.WithRedirectUri("http://localhost:52073")
229+
.WithRedirectUri(SeleniumWebUI.FindFreeLocalhostRedirectUri())
228230
.WithAuthority(app.Authority + "common")
229231
.WithTestLogging(out factory)
230232
.Build();

0 commit comments

Comments
 (0)