|
5 | 5 | import org.openqa.selenium.By; |
6 | 6 | import org.openqa.selenium.Keys; |
7 | 7 | import org.openqa.selenium.support.ui.ExpectedConditions; |
| 8 | +import org.slf4j.Logger; |
| 9 | +import org.slf4j.LoggerFactory; |
8 | 10 |
|
9 | 11 | import java.util.HashMap; |
10 | 12 | import java.util.Map; |
|
14 | 16 |
|
15 | 17 | public class AADSeleniumITHelper extends SeleniumITHelper { |
16 | 18 |
|
| 19 | + private static final Logger LOGGER = LoggerFactory.getLogger(AADSeleniumITHelper.class); |
| 20 | + |
17 | 21 | private String username; |
18 | 22 | private String password; |
19 | 23 |
|
@@ -42,7 +46,23 @@ public AADSeleniumITHelper(Class<?> appClass, Map<String, String> properties, St |
42 | 46 | public void logIn() { |
43 | 47 | driver.get(app.root() + "oauth2/authorization/azure"); |
44 | 48 | 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 | + } |
46 | 66 | wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[type='submit']"))).click(); |
47 | 67 | } |
48 | 68 |
|
|
0 commit comments