diff --git a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/AADSeleniumITHelper.java b/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/AADSeleniumITHelper.java index 0a778f952e232..1e0f1013e4b8c 100644 --- a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/AADSeleniumITHelper.java +++ b/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/AADSeleniumITHelper.java @@ -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; @@ -14,6 +16,8 @@ public class AADSeleniumITHelper extends SeleniumITHelper { + private static final Logger LOGGER = LoggerFactory.getLogger(AADSeleniumITHelper.class); + private String username; private String password; @@ -42,7 +46,23 @@ public AADSeleniumITHelper(Class appClass, Map 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(); } diff --git a/sdk/spring/azure-spring-boot-test-selenium-common/src/main/resources/logback.xml b/sdk/spring/azure-spring-boot-test-selenium-common/src/main/resources/logback.xml index d03be69be311a..b35926b405923 100644 --- a/sdk/spring/azure-spring-boot-test-selenium-common/src/main/resources/logback.xml +++ b/sdk/spring/azure-spring-boot-test-selenium-common/src/main/resources/logback.xml @@ -1,3 +1,11 @@ - + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + +