Skip to content

Commit

Permalink
Fix for issues...
Browse files Browse the repository at this point in the history
Issue #49
Issue #50
Issue #58
Issue #57
Issue #55
Issue #48
Issue #46
Issue #40
  • Loading branch information
dtu11 committed Dec 21, 2017
1 parent af1a82c commit 3af49f3
Show file tree
Hide file tree
Showing 17 changed files with 444 additions and 742 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public class OptionSet
public string Value { get; set; }
}

public class MultiValueOptionSet
{
public string Name { get; set; }
public string[] Values { get; set; }
}

public class Lookup
{
public string Name { get; set; }
Expand Down
19 changes: 11 additions & 8 deletions Microsoft.Dynamics365.UIAutomation.Api/DTOs/XrmElementReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public static class Elements
{ "Dialog_AddConnectionSave", "id(\"connection|NoRelationship|Form|Mscrm.Form.connection.SaveAndClose-Large\")" },
{ "Dialog_RoleLookupButton", "id(\"record2roleid\")" },
{ "Dialog_RoleLookupTable", "id(\"record2roleid_IMenu\")" },
{ "Dialog_WarningFooter" , "//*[@id=\"crmDialogFooter\"]" },
{ "Dialog_WarningCloseButton", "//*[@id=\"butBegin\"]" },

//GuidedHelp
{ "GuidedHelp_MarsOverlay" , "id(\"marsOverlay\")"},
Expand Down Expand Up @@ -152,10 +154,8 @@ public static class Elements
{ "Notes_ActivityAddTaskDueTime" ,"id(\"selectTable_Date\")"},

//Login
{ "Login_UserId", "id(\"i0116\")"},
{ "Login_Password", "id(\"i0118\")"},
{ "Login_OldUserId", "id(\"cred_userid_inputtext\")"},
{ "Login_OldPassword", "id(\"cred_password_inputtext\")"},
{ "Login_UserId", "//input[@type='email']"},
{ "Login_Password", "//input[@type='password']"},
{ "Login_SignIn", "id(\"cred_sign_in_button\")"},
{ "Login_CrmMainPage", "id(\"crmTopBar\")"},
{ "Login_StaySignedIn", "id(\"idSIButton9\")"},
Expand Down Expand Up @@ -279,7 +279,9 @@ public static class Elements
//SetValue
{ "SetValue_LookupRenderClass" , "Lookup_RenderButton_td"},
{ "SetValue_EditClass" , "ms-crm-Inline-Edit"},
{ "SetValue_ValueClass" , "ms-crm-Inline-Value"},
{ "SetValue_ValueClass" , "ms-crm-Inline-Value"},
{ "SetValue_MultiSelectPicklistDelete" , "sol-quick-delete"},


//DashBoard
{ "DashBoard_ViewContainerClass" , "ms-crm-VS-Menu"},
Expand Down Expand Up @@ -337,6 +339,8 @@ public static class Dialogs
public static string WorkflowHeader = "Dialog_WorkflowHeader";
public static string ProcessFlowHeader = "Dialog_ProcessFlowHeader";
public static string AddConnectionHeader = "Dialog_AddConnectionHeader";
public static string WarningFooter = "Dialog_WarningFooter";
public static string WarningCloseButton = "Dialog_WarningCloseButton";

public static class CloseOpportunity
{
Expand Down Expand Up @@ -404,6 +408,7 @@ public static class SetValue
public static string CompositionLinkControl = "SetValue_CompositionLinkControlId";
public static string Cancel = "SetValue_Cancel";
public static string Save = "SetValue_Save";
public static string MultiSelectPicklistDeleteClass = "SetValue_MultiSelectPicklistDelete";
}

public static class QuickCreate
Expand Down Expand Up @@ -609,9 +614,7 @@ public static class LookUp
public static class Login
{
public static string UserId = "Login_UserId";
public static string Password = "Login_Password";
public static string OldSignInUserId = "Login_OldUserId";
public static string OldSignInPassword = "Login_OldPassword";
public static string LoginPassword = "Login_Password";
public static string SignIn = "Login_SignIn";
public static string CrmMainPage = "Login_CrmMainPage";
public static string StaySignedIn = "Login_StaySignedIn";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>\bin\Release\</OutputPath>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down
28 changes: 3 additions & 25 deletions Microsoft.Dynamics365.UIAutomation.Api/Pages/LoginPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,20 @@ private LoginResult Login(IWebDriver driver, Uri uri, SecureString username, Sec
{
var redirect = false;
bool online = !(this.OnlineDomains != null && !this.OnlineDomains.Any(d => uri.Host.EndsWith(d)));
bool redirectToNewPassword = false;
driver.Navigate().GoToUrl(uri);

if (online)
{
if (driver.IsVisible(By.Id("use_another_account_link")))
driver.ClickWhenAvailable(By.Id("use_another_account_link"));

if (driver.IsVisible(By.XPath(Elements.Xpath[Reference.Login.UserId])))
{
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.");

driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.UserId])).SendKeys(username.ToUnsecureString());
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.UserId])).SendKeys(Keys.Tab);
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.UserId])).SendKeys(Keys.Enter);
redirectToNewPassword = true;
Thread.Sleep(2000);
}
else
{
driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Login.OldSignInUserId]),
$"The Office 365 sign in page did not return the expected result and the user '{username}' could not be signed in.");

driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.OldSignInUserId])).SendKeys(username.ToUnsecureString());
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.OldSignInUserId])).SendKeys(Keys.Tab);
}

//If expecting redirect then wait for redirect to trigger
if (redirectAction != null)
Expand All @@ -128,24 +115,15 @@ private LoginResult Login(IWebDriver driver, Uri uri, SecureString username, Sec
}
else
{
if (redirectToNewPassword)
{
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.Password])).SendKeys(password.ToUnsecureString());
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.Password])).SendKeys(Keys.Tab);
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.Password])).Submit();
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.LoginPassword])).SendKeys(password.ToUnsecureString());
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.LoginPassword])).SendKeys(Keys.Tab);
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.LoginPassword])).Submit();

if (driver.IsVisible(By.XPath(Elements.Xpath[Reference.Login.StaySignedIn])))
{
driver.ClickWhenAvailable(By.XPath(Elements.Xpath[Reference.Login.StaySignedIn]));
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.StaySignedIn])).Submit();
}
}
else
{
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.OldSignInPassword])).SendKeys(password.ToUnsecureString());
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.OldSignInPassword])).SendKeys(Keys.Tab);
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.OldSignInPassword])).Submit();
}

driver.WaitUntilVisible(By.XPath(Elements.Xpath[Reference.Login.CrmMainPage])
, new TimeSpan(0, 0, 60),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,10 @@ public BrowserCommandResult<bool> AddTask(string subject, string description, Da
this.SetValue(Elements.ElementId[Reference.ActivityFeed.ActivityTaskSubjectId], subject);
this.SetValue(Elements.ElementId[Reference.ActivityFeed.ActivityTaskDescriptionId], description);
this.SetCalenderValue(Elements.ElementId[Reference.ActivityFeed.ActivityAddTaskDueDateId], dueDate.ToShortDateString());
driver.ClickWhenAvailable(By.XPath(Elements.Xpath[Reference.ActivityFeed.ActivityTaskScheduledEnd]));
this.SetCalenderValue(Elements.ElementId[Reference.ActivityFeed.ActivityAddTaskDueTimeId], dueDate.ToShortTimeString());
this.SetValue(priority);
driver.ClickWhenAvailable(By.XPath(Elements.Xpath[Reference.ActivityFeed.ActivityTaskOk]));
return true;
Expand Down
47 changes: 0 additions & 47 deletions Microsoft.Dynamics365.UIAutomation.Api/Pages/XrmCommandBarPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// Licensed under the MIT license.

using Microsoft.Dynamics365.UIAutomation.Browser;
using OpenQA.Selenium;
using System;
using System.Collections.ObjectModel;
using System.Linq;

namespace Microsoft.Dynamics365.UIAutomation.Api
{
Expand All @@ -30,48 +26,5 @@ public XrmCommandBarPage(InteractiveBrowser browser)
{
SwitchToDefault();
}


/// <summary>
/// Gets the Commands
/// </summary>
/// <param name="moreCommands">The MoreCommands</param>
/// <example></example>
private BrowserCommandResult<ReadOnlyCollection<IWebElement>> GetCommands(bool moreCommands = false)
{
return this.Execute("Get Command Bar Buttons", driver =>
{
driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.CommandBar.RibbonManager]),new TimeSpan(0,0,5));
IWebElement ribbon = null;
if (moreCommands)
ribbon = driver.FindElement(By.XPath(Elements.Xpath[Reference.CommandBar.List]));
else
ribbon = driver.FindElement(By.XPath(Elements.Xpath[Reference.CommandBar.RibbonManager]));
var items = ribbon.FindElements(By.TagName("li"));
return items;//.Where(item => item.Text.Length > 0).ToDictionary(item => item.Text, item => item.GetAttribute("id"));
});
}

/// <summary>
/// Clicks the Command
/// </summary>
/// <param name="name">The Name of the command</param>
/// <param name="subName">The SubName</param>
/// <param name="moreCommands">The MoreCommands</param>
/// <param name="thinkTime">Used to simulate a wait time between human interactions. The Default is 2 seconds.</param>
/// <example>xrmBrowser.CommandBar.ClickCommand("New");</example>
public BrowserCommandResult<bool> ClickCommand(string name, string subName = "", bool moreCommands = false, int thinkTime = Constants.DefaultThinkTime)
{
Browser.ThinkTime(thinkTime);

return this.Execute(GetOptions("Click Command"), driver =>
{
ClickCommandButton(name, subName, moreCommands, thinkTime);
return true;
});
}
}
}
17 changes: 17 additions & 0 deletions Microsoft.Dynamics365.UIAutomation.Api/Pages/XrmDialogPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,5 +288,22 @@ public BrowserCommandResult<bool> AddUser(int thinkTime = Constants.DefaultThink
});
}

public BrowserCommandResult<bool> CloseWarningDialog()
{
return this.Execute(GetOptions($"Close Warning Dialog"), driver =>
{
var dialogFooter = driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Dialogs.WarningFooter]));
if (dialogFooter != null
&& (dialogFooter?.FindElements(By.XPath(Elements.Xpath[Reference.Dialogs.WarningCloseButton]))).Any())
{
var closeBtn =
dialogFooter.FindElement(By.XPath(Elements.Xpath[Reference.Dialogs.WarningCloseButton]));
closeBtn.Click();
}
return true;
});
}
}
}
140 changes: 0 additions & 140 deletions Microsoft.Dynamics365.UIAutomation.Api/Pages/XrmEntityPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.Dynamics365.UIAutomation.Browser;
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

Expand Down Expand Up @@ -228,145 +227,6 @@ public BrowserCommandResult<bool> ExpandTab(string name, int thinkTime = Constan
});
}

/// <summary>
/// Set Lookup Value for the field
/// </summary>
/// <param name="field">The Field</param>
/// <param name="index">The Index</param>
/// <example>xrmBrowser.Entity.SelectLookup("customerid", 0);</example>
public BrowserCommandResult<bool> SelectLookup(string field, [Range(0, 9)]int index)
{
return this.Execute(GetOptions($"Set Lookup Value: {field}"), driver =>
{
if (driver.HasElement(By.Id(field)))
{
var input = driver.ClickWhenAvailable(By.Id(field));
if (input.FindElement(By.ClassName(Elements.CssClass[Reference.SetValue.LookupRenderClass])) == null)
throw new InvalidOperationException($"Field: {field} is not lookup");
input.FindElement(By.ClassName(Elements.CssClass[Reference.SetValue.LookupRenderClass])).Click();
var dialogName = $"Dialog_{field}_IMenu";
var dialog = driver.FindElement(By.Id(dialogName));
var dialogItems = OpenDialog(dialog).Value;
if (dialogItems.Count < index)
throw new InvalidOperationException($"List does not have {index + 1} items.");
var dialogItem = dialogItems[index];
dialogItem.Element.Click();
}
else
throw new InvalidOperationException($"Field: {field} Does not exist");
return true;
});
}

/// <summary>
/// Set Lookup Value for the field
/// </summary>
/// <param name="field">The Field</param>
/// <param name="value">The Lookup value</param>
public BrowserCommandResult<bool> SelectLookup(string field, string value)
{
return this.Execute(GetOptions($"Set Lookup Value: {field}"), driver=>
{
if (driver.HasElement(By.Id(field)))
{
var input = driver.ClickWhenAvailable(By.Id(field));
if (input.FindElement(By.ClassName(Elements.CssClass[Reference.SetValue.LookupRenderClass])) == null)
throw new InvalidOperationException($"Field: {field} is not lookup");
var lookupIcon = input.FindElement(By.ClassName("Lookup_RenderButton_td"));
lookupIcon.Click();
var dialogName = $"Dialog_{field}_IMenu";
var dialog = driver.FindElement(By.Id(dialogName));
var dialogItems = OpenDialog(dialog).Value;
if (!dialogItems.Exists(x => x.Title == value))
throw new InvalidOperationException($"List does not have {value}.");
var dialogItem = dialogItems.Where(x => x.Title == value).First();
dialogItem.Element.Click();
}
else
throw new InvalidOperationException($"Field: {field} Does not exist");
return true;
});
}

/// <summary>
/// Set Lookup Value for the field
/// </summary>
/// <param name="field">The Field</param>
/// <param name="openLookupPage">The Open Lookup Page</param>
public BrowserCommandResult<bool> SelectLookup(string field, bool openLookupPage = true)
{
return this.Execute(GetOptions($"Set Lookup Value: {field}"), driver=>
{
if (driver.HasElement(By.Id(field)))
{
var input = driver.ClickWhenAvailable(By.Id(field));
if (input.FindElement(By.ClassName(Elements.CssClass[Reference.SetValue.LookupRenderClass])) == null)
throw new InvalidOperationException($"Field: {field} is not lookup");
input.FindElement(By.ClassName(Elements.CssClass[Reference.SetValue.LookupRenderClass])).Click();
var dialogName = $"Dialog_{field}_IMenu";
var dialog = driver.FindElement(By.Id(dialogName));
var dialogItems = OpenDialog(dialog).Value;
if (dialogItems.Any())
{
var dialogItem = dialogItems.Last();
dialogItem.Element.Click();
}
}
else
throw new InvalidOperationException($"Field: {field} Does not exist");
return true;
});
}

/// <summary>
/// Opens the dialog
/// </summary>
/// <param name="dialog"></param>
private BrowserCommandResult<List<XrmListItem>> OpenDialog(IWebElement dialog)
{
var list = new List<XrmListItem>();
var dialogItems = dialog.FindElements(By.TagName("li"));

foreach (var dialogItem in dialogItems)
{
if (dialogItem.GetAttribute("role") != null && dialogItem.GetAttribute("role") == "menuitem")
{
var links = dialogItem.FindElements(By.TagName("a"));

if (links != null && links.Count > 1)
{
var title = links[1].GetAttribute("title");

list.Add(new XrmListItem() {
Title = title,
Element = links[1] });
}
}
}

return list;
}

/// <summary>
/// Popout the form
/// </summary>
Expand Down
Loading

0 comments on commit 3af49f3

Please sign in to comment.