The following is the third on a series of articles by @Ali Youssefi that we will be cross-posting into this Test Community Blog. These articles were first published by Ali in the Dynamics community b...
I am trying to Extend the LoginDetails and WebClient but i am getting the following error. Please find the below screenshot. ErrorMessage: " System.MissingMethodException : Method not found: 'Boolean Microsoft.Dynamics365.UIAutomation.Browser.SeleniumExtensions.IsVisible(OpenQA.Selenium.IWebDriver, OpenQA.Selenium.By)'."
Any idea what could be the problem.
LoginDetails page Extension class code.
using System; using System.Collections.Generic; using System.Text; using System.Linq; using System.Threading; using System.Security; using Microsoft.Dynamics365.UIAutomation.Browser; using Microsoft.Dynamics365.UIAutomation.Api; using OpenQA.Selenium; using OpenQA.Selenium.Support.Extensions; using OpenQA.Selenium.Support.Events; using System.Diagnostics;
namespace LD.Mellodirect.Integration.QA.CRMUIDataMapping.Pages { public class LoginPage : LoginDialog { public string[] OnlineDomains { get; set; } //public InteractiveBrowser browser; public LoginPage(InteractiveBrowser browser) : base(browser) { this.OnlineDomains = Constants.Xrm.XrmDomains; //this.browser = browser; }
private LoginResult D365Login(IWebDriver driver, Uri uri, SecureString username, SecureString password,Action<LoginRedirectEventArgs> redirection) { bool online = !(this.OnlineDomains != null && !this.OnlineDomains.Any(d => uri.Host.EndsWith(d))); driver.Navigate().GoToUrl(uri); bool redirect = false; if (online) { if (driver.IsVisible(By.Id("use_another_account_link"))) driver.ClickWhenAvailable(By.Id("use_another_account_link")); driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Login.UserId]), $"The Office 365 sign in page did not return the expected result and the user '{username}' could not be signed in.");
if (driver.IsVisible(By.XPath(Elements.Xpath[Reference.Login.StaySignedIn]))) { driver.ClickWhenAvailable(By.XPath(Elements.Xpath[Reference.Login.StaySignedIn]));
if (driver.HasElement(By.XPath(Elements.Xpath[Reference.Login.StaySignedIn]))) driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.StaySignedIn])).Submit(); }
driver.WaitUntilVisible(By.XPath("//div[contains(@data-id,'topBar') or contains(@id,'crmTopBar')]") , new TimeSpan(0, 0, 60), e => { driver.WaitForPageToLoad(); } ); } } return redirect ? LoginResult.Redirect : LoginResult.Success; }
public void VerifyDefaultPageLoaded(SecureString userName,SecureString password,IWebDriver driver) { var d = driver; d.FindElement(By.Id("passwordInput")).SendKeys(password.ToUnsecureString()); d.ClickWhenAvailable(By.Id("submitButton"), new TimeSpan(0,0,30)); d.WaitUntilVisible(By.XPath("//div[contains(@data-id,'topBar') or contains(@id,'crmTopBar')]") , new TimeSpan(0,0,60), e => { d.WaitForPageToLoad(); }, f => { throw new Exception("Login page failed."); } ); }
using System; using System.Collections.Generic; using System.Text; using System.Security; using System.Web; using Microsoft.Dynamics365.UIAutomation.Browser; using Microsoft.Dynamics365.UIAutomation.Api.UCI; using OpenQA.Selenium; using Microsoft.Dynamics365.UIAutomation.Api.UCI.DTO; using OpenQA.Selenium.Interactions; using System.Linq; using System.Threading; using System.Diagnostics; using OtpNet;
namespace LD.Mellodirect.Integration.QA.CRMUIDataMapping.Pages { public class LoginClient : WebClient { public LoginClient(BrowserOptions options):base(options) { base.Browser = new InteractiveBrowser(options); base.OnlineDomains = Constants.Xrm.XrmDomains; base.ClientSessionId = Guid.NewGuid(); }
var getvalue = input.GetAttribute("value"); if (!getvalue.Equals(value)) throw new InvalidOperationException($"Timeout after 10 seconds. Expected: {value}. Actual: {input.GetAttribute("value")}"); }
private bool EnterOneTimeCode(IWebDriver driver,SecureString mfaSecretKey) { try { IWebElement input = GetOtcInput(driver); if (input == null) return true; if (mfaSecretKey == null) throw new InvalidOperationException("The application is wait for the OTC but your MFA-SecretKey is not set. Please check your configuration."); var oneTimeCode = GenerateOneTimeCode(mfaSecretKey); SetInputValue(driver, input, oneTimeCode, TimeSpan.FromSeconds(1.0)); input.Submit(); return true; } catch (Exception e) { var message = $"An Error occur entering OTC. Exception: {e.Message}"; Trace.TraceInformation(message); throw new InvalidOperationException(message, e); } }
if (!online) return LoginResult.Success; var idAnotherAccount = By.Id("use_another_account_link"); if(driver.IsVisible(idAnotherAccount)) driver.FindElement(idAnotherAccount).Click();
if (entered && !success) { throw new InvalidOperationException("Somthing went wrong entering the OTC. Please check the MFA-SecretKey in configuration."); }