Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.21191.0750")]
[assembly: AssemblyFileVersion("1.0.21191.0750")]
[assembly: AssemblyVersion("1.0.21208.0840")]
[assembly: AssemblyFileVersion("1.0.21208.0840")]
84 changes: 51 additions & 33 deletions Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using System.Resources;
using System.Security;
using System.Threading;
using System.Web;
Expand Down Expand Up @@ -49,26 +51,50 @@ internal BrowserCommandResult<bool> InitializeModes()
// Wait for main page to load before attempting this. If you don't do this it might still be authenticating and the URL will be wrong
WaitForMainPage();

var uri = driver.Url;
var queryParams = "&flags=easyreproautomation=true";

if (Browser.Options.UCITestMode) queryParams += ",testmode=true";
if (Browser.Options.UCIPerformanceMode) queryParams += "&perf=true";

if (!uri.Contains(queryParams) && !uri.Contains(HttpUtility.UrlEncode(queryParams)))
string uri = driver.Url;
if (string.IsNullOrEmpty(uri))
return false;

var prevQuery = GetUrlQueryParams(uri);
bool requireRedirect = false;
string queryParams = "";
if (prevQuery.Get("flags") == null)
{
var testModeUri = uri + queryParams;
queryParams+= "&flags=easyreproautomation=true";
if (Browser.Options.UCITestMode)
queryParams += ",testmode=true";
requireRedirect = true;
}

driver.Navigate().GoToUrl(testModeUri);
if (Browser.Options.UCIPerformanceMode && prevQuery.Get("perf") == null)
{
queryParams += "&perf=true";
requireRedirect = true;
}

if (!requireRedirect)
return true;

var testModeUri = uri + queryParams;
driver.Navigate().GoToUrl(testModeUri);

// Again wait for loading
WaitForMainPage();

return true;
});
}

private NameValueCollection GetUrlQueryParams(string url)
{
if (string.IsNullOrEmpty(url))
return null;

Uri uri = new Uri(url);
var query = uri.Query.ToLower();
NameValueCollection result = HttpUtility.ParseQueryString(query);
return result;
}


public string[] OnlineDomains { get; set; }

Expand Down Expand Up @@ -179,7 +205,7 @@ private LoginResult Login(IWebDriver driver, Uri uri, SecureString username, Sec
return success ? LoginResult.Success : LoginResult.Failure;
}

private bool IsUserAlreadyLogged() => WaitForMainPage(10.Seconds());
private bool IsUserAlreadyLogged() => WaitForMainPage(2.Seconds());

private static string GenerateOneTimeCode(SecureString mfaSecretKey)
{
Expand Down Expand Up @@ -244,7 +270,7 @@ private static IWebElement GetOtcInput(IWebDriver driver)
private static bool ClickStaySignedIn(IWebDriver driver)
{
var xpath = By.XPath(Elements.Xpath[Reference.Login.StaySignedIn]);
var element = driver.ClickIfVisible(xpath, 5.Seconds());
var element = driver.ClickIfVisible(xpath, 2.Seconds());
return element != null;
}

Expand Down Expand Up @@ -283,7 +309,7 @@ internal BrowserCommandResult<LoginResult> PassThroughLogin(Uri uri)
//else we landed on the Web Client main page or app picker page
SwitchToDefaultContent(driver);
},
() => new InvalidOperationException("Load Main Page Fail.")
() => throw new InvalidOperationException("Load Main Page Fail.")
);

return LoginResult.Success;
Expand Down Expand Up @@ -364,28 +390,20 @@ internal BrowserCommandResult<bool> OpenApp(string appName, int thinkTime = Cons
{
driver.WaitForPageToLoad();
driver.SwitchTo().DefaultContent();
var success = false;
//Handle left hand Nav in Web Client
if (!driver.Url.Contains("appid"))
{

var query = GetUrlQueryParams(driver.Url);
bool isSomeAppOpen = query.Get("appid") != null || query.Get("app") != null;

bool success = false;
if (!isSomeAppOpen)
success = TryToClickInAppTile(appName, driver);
}

else if (driver.Url.Contains("forceUCI=1"))
{
success = TryOpenAppFromMenu(driver, appName, AppReference.Navigation.UCIAppMenuButton);
}
else
{
success = TryOpenAppFromMenu(driver, appName, AppReference.Navigation.WebAppMenuButton);
}

success = TryOpenAppFromMenu(driver, appName, AppReference.Navigation.UCIAppMenuButton) ||
TryOpenAppFromMenu(driver, appName, AppReference.Navigation.WebAppMenuButton);

if (!success)
throw new InvalidOperationException($"App Name {appName} not found.");

Thread.Sleep(1000);
WaitForMainPage();

InitializeModes();

// Wait for app page elements to be visible (shell and sitemapLauncherButton)
Expand All @@ -397,15 +415,15 @@ internal BrowserCommandResult<bool> OpenApp(string appName, int thinkTime = Cons
if (!success)
throw new InvalidOperationException($"App '{appName}' was found but app page was not loaded.");

return success;
return true;
});
}

private bool TryOpenAppFromMenu(IWebDriver driver, string appName, string appMenuButton)
{
bool found = false;
var xpathToAppMenu = By.XPath(AppElements.Xpath[appMenuButton]);
driver.WaitUntilClickable(xpathToAppMenu, TimeSpan.FromSeconds(5),
driver.WaitUntilClickable(xpathToAppMenu, 5.Seconds(),
appMenu =>
{
appMenu.Click(true);
Expand Down Expand Up @@ -447,7 +465,7 @@ private static bool TryToClickInAppTile(string appName, IWebDriver driver)
}
return true;
},
TimeSpan.FromSeconds(30)
5.Seconds()
);

var xpathToAppContainer = By.XPath(AppElements.Xpath[AppReference.Navigation.UCIAppContainer]);
Expand Down
33 changes: 27 additions & 6 deletions Microsoft.Dynamics365.UIAutomation.Sample/UCI/Login/Login.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,38 @@ public class Login : TestsBase
[TestCleanup]
public override void FinishTest() => base.FinishTest();

public override void NavigateToHomePage() => NavigateTo(UCIAppName.Sales, "Sales", "Accounts");

[TestMethod]
public void MultiFactorLogin()
{
_xrmApp.Grid.SwitchView("All Accounts");
trace.Log("Login success");
}

[TestMethod]
public void MultiFactorLogin_NavigateToApp()
{
trace.Log("Login success");
NavigateTo(UCIAppName.Sales);
}

[TestMethod]
public void MultiFactorLogin_NavigateToApp_CustomerService()
{
trace.Log("Login success");

NavigateTo(UCIAppName.CustomerService);
trace.Log("Open Customer Service Success");
}

_xrmApp.CommandBar.ClickCommand("New");
[TestMethod]
public void MultiFactorLogin_NavigateToApp_ChangeApp()
{
trace.Log("Login success");
NavigateTo(UCIAppName.Sales);

_xrmApp.Entity.SetValue("name", "Test API Account" + TestSettings.GetRandomString(5,5) );
_xrmApp.Entity.SetValue("telephone1", "555-555-5555");
trace.Log("Open Sales Success");

NavigateTo(UCIAppName.CustomerService);
trace.Log("Open Customer Service Success");
}
}
}