Skip to content

Commit

Permalink
Merge pull request #772 from AngelRodriguez8008/users/angel/fixGetLoo…
Browse files Browse the repository at this point in the history
…kupValue

Bug Fix: Returning Lookup Values in Lower Case
  • Loading branch information
TYLEROL authored Feb 20, 2020
2 parents 535245d + 0a52ce5 commit f078634
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
10 changes: 6 additions & 4 deletions Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1904,13 +1904,13 @@ internal BrowserCommandResult<bool> 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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -2891,7 +2893,7 @@ internal BrowserCommandResult<bool> SetHeaderValue(LookupItem[] controls, bool c
if (clearFirst)
TryRemoveLookupValue(driver, container, control);

TryToSetValue(container, controls);
TryToSetValue(driver, container, controls);
return true;
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
Expand Down
34 changes: 33 additions & 1 deletion Microsoft.Dynamics365.UIAutomation.Sample/UCI/SetValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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()
{
Expand Down

0 comments on commit f078634

Please sign in to comment.