Skip to content

Commit

Permalink
Fix AAD IT failure of cannot redirect to password page (Azure#19479)
Browse files Browse the repository at this point in the history
  • Loading branch information
yiliuTo authored Mar 3, 2021
1 parent c1bf419 commit f3004e4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -14,6 +16,8 @@

public class AADSeleniumITHelper extends SeleniumITHelper {

private static final Logger LOGGER = LoggerFactory.getLogger(AADSeleniumITHelper.class);

private String username;
private String password;

Expand Down Expand Up @@ -42,7 +46,23 @@ public AADSeleniumITHelper(Class<?> appClass, Map<String, String> properties, St
public void logIn() {
driver.get(app.root() + "oauth2/authorization/azure");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("loginfmt"))).sendKeys(username + Keys.ENTER);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("passwd"))).sendKeys(password + Keys.ENTER);
try {
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("passwd"))).sendKeys(password + Keys.ENTER);
} catch (Exception exception) {
// Sometimes AAD cannot locate the user account and will ask to select it's a work account or personal account.
// Here select work accout.
// https://docs.microsoft.com/azure/devops/organizations/accounts/faq-azure-access?view=azure-devops#q-why-do-i-have-to-choose-between-a-work-or-school-account-and-my-personal-account
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("aadTileTitle"))).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("passwd"))).sendKeys(password + Keys.ENTER);
}
} catch (Exception exception) {
String passwdUrl = driver.getCurrentUrl();
LOGGER.info(passwdUrl);
String pageSource = driver.getPageSource();
LOGGER.info(pageSource);
throw exception;
}
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[type='submit']"))).click();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<configuration>
<logger name="org.apache.hc" level="INFO" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

0 comments on commit f3004e4

Please sign in to comment.