private IWebDriver InitDriverAndGoToUrl(string url) { IWebDriver driver = null; try { driver = SeleniumExtensions.CreateDefaultWebDriver(); driver.Navigate().GoToUrl(url); return(driver); } catch (Exception) { driver?.Dispose(); throw; } }
public static void PerformDeviceCodeLogin( DeviceCodeResult deviceCodeResult, LabUser user, TestContext testContext, bool isAdfs = false) { using (var seleniumDriver = CreateDefaultWebDriver()) { try { var fields = new UserInformationFieldIds(user); Trace.WriteLine("Browser is open. Navigating to the Device Code url and entering the code"); string codeId = isAdfs ? "userCodeInput" : "code"; string continueId = isAdfs ? "confirmationButton" : "continueBtn"; seleniumDriver.Navigate().GoToUrl(deviceCodeResult.VerificationUrl); seleniumDriver // Device Code Flow web ui is undergoing A/B testing and is sometimes different - use 2 IDs .FindElement(SeleniumExtensions.ByIds("otc", codeId)) .SendKeys(deviceCodeResult.UserCode); IWebElement continueBtn = seleniumDriver.WaitForElementToBeVisibleAndEnabled( SeleniumExtensions.ByIds(fields.AADSignInButtonId, continueId)); continueBtn?.Click(); seleniumDriver.PerformLogin(user, Prompt.SelectAccount, false, isAdfs); Thread.Sleep(1000); // allow the browser to redirect seleniumDriver?.SaveScreenshot(testContext, "device_code_end"); Trace.WriteLine("Authentication complete"); } catch (Exception ex) { Trace.WriteLine("Browser automation failed " + ex); seleniumDriver?.SaveScreenshot(testContext); throw; } } }