diff --git a/Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs b/Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs index f7b425a3..5538cd03 100644 --- a/Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs +++ b/Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs @@ -1904,13 +1904,13 @@ internal BrowserCommandResult SetValue(LookupItem[] controls, bool clearFi if (clearFirst) TryRemoveLookupValue(driver, fieldContainer, control); - TryToSetValue(fieldContainer, controls); + TryToSetValue(driver, fieldContainer, controls); return true; }); } - private void TryToSetValue(ISearchContext fieldContainer, LookupItem[] controls) + private void TryToSetValue(IWebDriver driver, ISearchContext fieldContainer, LookupItem[] controls) { IWebElement input; bool found = fieldContainer.TryFindElement(By.TagName("input"), out input); @@ -1925,6 +1925,8 @@ private void TryToSetValue(ISearchContext fieldContainer, LookupItem[] controls) else { input.SendKeys(value, true); + driver.WaitForTransaction(); + ThinkTime(3.Seconds()); input.SendKeys(Keys.Tab); input.SendKeys(Keys.Enter); } @@ -2434,7 +2436,7 @@ private string[] TryGetValue(IWebElement fieldContainer, LookupItem[] controls) { if (existingValues.Count > 0) { - string[] lookupValues = existingValues.Select(v => v.GetAttribute("innerText").ToLowerString()).ToArray(); //IE can return line breaks + string[] lookupValues = existingValues.Select(v => v.GetAttribute("innerText").TrimSpecialCharacters()).ToArray(); //IE can return line breaks return lookupValues; } @@ -2891,7 +2893,7 @@ internal BrowserCommandResult SetHeaderValue(LookupItem[] controls, bool c if (clearFirst) TryRemoveLookupValue(driver, container, control); - TryToSetValue(container, controls); + TryToSetValue(driver, container, controls); return true; })); } diff --git a/Microsoft.Dynamics365.UIAutomation.Browser/Extensions/StringExtensions.cs b/Microsoft.Dynamics365.UIAutomation.Browser/Extensions/StringExtensions.cs index a793758d..70a9ee93 100644 --- a/Microsoft.Dynamics365.UIAutomation.Browser/Extensions/StringExtensions.cs +++ b/Microsoft.Dynamics365.UIAutomation.Browser/Extensions/StringExtensions.cs @@ -37,7 +37,10 @@ public static string ToUnsecureString(this SecureString secureString) Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString); } } - public static string ToLowerString(this string value) + public static string ToLowerString(this string value) + => value?.TrimSpecialCharacters().ToLower(); + + public static string TrimSpecialCharacters(this string value) { char[] trimCharacters = { '\r', @@ -50,13 +53,15 @@ public static string ToLowerString(this string value) (char) 59902, //๎งพ }; - return value?.Trim() - .Trim(trimCharacters) - .Replace("\r", string.Empty) - .Replace("\n", string.Empty) - .Replace(Environment.NewLine, string.Empty) - .ToLower(); + var result = value?.Trim() + .Trim(trimCharacters) + .Replace("\r", string.Empty) + .Replace("\n", string.Empty) + .Replace(Environment.NewLine, string.Empty); + + return result; } + public static bool Contains(this string source, string value, StringComparison compare) { return source.IndexOf(value, compare) >= 0; diff --git a/Microsoft.Dynamics365.UIAutomation.Sample/UCI/SetValue.cs b/Microsoft.Dynamics365.UIAutomation.Sample/UCI/SetValue.cs index 8e0b1ab9..5f889ef5 100644 --- a/Microsoft.Dynamics365.UIAutomation.Sample/UCI/SetValue.cs +++ b/Microsoft.Dynamics365.UIAutomation.Sample/UCI/SetValue.cs @@ -91,7 +91,7 @@ public void UCITestActivityPartySetValue() xrmApp.ThinkTime(500); xrmApp.Entity.SetValue(new LookupItem[] { - new LookupItem { Name = "to", Value = "Adeventure Works", Index = 0 }, + new LookupItem { Name = "to", Value = "Adventure Works", Index = 0 }, new LookupItem { Name = "to", Value = "", Index = 0 } }); xrmApp.ThinkTime(500); @@ -103,6 +103,38 @@ public void UCITestActivityPartySetValue() } } + [TestMethod] + public void UCITestActivityPartySetValue_CaseSensitive() + { + var client = new WebClient(TestSettings.Options); + using (var xrmApp = new XrmApp(client)) + { + xrmApp.OnlineLogin.Login(_xrmUri, _username, _password, _mfaSecrectKey); + + xrmApp.Navigation.OpenApp(UCIAppName.Sales); + + xrmApp.Navigation.OpenSubArea("Sales", "Activities"); + + xrmApp.Grid.SwitchView("All Phone Calls"); + xrmApp.ThinkTime(500); + + xrmApp.Grid.OpenRecord(0); + xrmApp.ThinkTime(500); + + xrmApp.Entity.SetValue(new [] { + new LookupItem { Name = "to", Value = "Adventure Works", Index = 0 }, + new LookupItem { Name = "to", Value = "Nana Bule", Index = 0 } }); + xrmApp.ThinkTime(500); + + string toValue = xrmApp.Entity.GetValue(new LookupItem { Name = "to" }); + Assert.IsTrue(toValue.Contains("Adventure Works")); + Assert.IsFalse(toValue.Contains("adventure works")); + + Assert.IsTrue(toValue.Contains("Nana Bule")); + Assert.IsFalse(toValue.Contains("nana bule")); + } + } + [TestMethod] public void UCITestActivityPartyAddValues() {