Skip to content

Commit f3004e4

Browse files
authored
Fix AAD IT failure of cannot redirect to password page (Azure#19479)
1 parent c1bf419 commit f3004e4

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/AADSeleniumITHelper.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.openqa.selenium.By;
66
import org.openqa.selenium.Keys;
77
import org.openqa.selenium.support.ui.ExpectedConditions;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
810

911
import java.util.HashMap;
1012
import java.util.Map;
@@ -14,6 +16,8 @@
1416

1517
public class AADSeleniumITHelper extends SeleniumITHelper {
1618

19+
private static final Logger LOGGER = LoggerFactory.getLogger(AADSeleniumITHelper.class);
20+
1721
private String username;
1822
private String password;
1923

@@ -42,7 +46,23 @@ public AADSeleniumITHelper(Class<?> appClass, Map<String, String> properties, St
4246
public void logIn() {
4347
driver.get(app.root() + "oauth2/authorization/azure");
4448
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("loginfmt"))).sendKeys(username + Keys.ENTER);
45-
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("passwd"))).sendKeys(password + Keys.ENTER);
49+
try {
50+
try {
51+
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("passwd"))).sendKeys(password + Keys.ENTER);
52+
} catch (Exception exception) {
53+
// Sometimes AAD cannot locate the user account and will ask to select it's a work account or personal account.
54+
// Here select work accout.
55+
// 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
56+
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("aadTileTitle"))).click();
57+
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("passwd"))).sendKeys(password + Keys.ENTER);
58+
}
59+
} catch (Exception exception) {
60+
String passwdUrl = driver.getCurrentUrl();
61+
LOGGER.info(passwdUrl);
62+
String pageSource = driver.getPageSource();
63+
LOGGER.info(pageSource);
64+
throw exception;
65+
}
4666
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[type='submit']"))).click();
4767
}
4868

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
<configuration>
2-
<logger name="org.apache.hc" level="INFO" />
2+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
3+
<encoder>
4+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
5+
</encoder>
6+
</appender>
7+
8+
<root level="INFO">
9+
<appender-ref ref="STDOUT" />
10+
</root>
311
</configuration>

0 commit comments

Comments
 (0)