Skip to content

Commit

Permalink
GitHub issue #371 Updated SetValue for lookup. Added a WaitForTransac…
Browse files Browse the repository at this point in the history
…tion to ensure the page is loaded to prevent issue with SetValue executing when the load is still happening. Added sleeps to make sure the elements get hovered & clicked properly (#480)
  • Loading branch information
jlattimer authored and dtu11 committed May 17, 2019
1 parent 5369f58 commit d38f81d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Expand Up @@ -75,6 +75,8 @@ public static class Entity
public static string TextFieldLookup = "Entity_TextFieldLookup";
public static string TextFieldLookupMenu = "Entity_TextFieldLookupMenu";
public static string LookupFieldDeleteExistingValue = "Entity_LookupFieldDeleteExistingValue";
public static string LookupFieldNoRecordsText = "Entity_LookupFieldNoRecordsText";
public static string LookupFieldResultList = "Entity_LookupFieldResultList";
public static string LookupFieldHoverExistingValue = "Entity_LookupFieldHoverExistingValue";
public static string LookupResultsDropdown = "Entity_LookupResultsDropdown";
public static string TextFieldLookupFieldContainer = "Entity_TextFieldLookupFieldContainer";
Expand Down Expand Up @@ -291,6 +293,8 @@ public static class AppElements
{ "Entity_TextFieldLookup", "//*[contains(@id, \'systemuserview_id.fieldControl-LookupResultsDropdown')]" },
{ "Entity_TextFieldLookupMenu", "//div[contains(@data-id, '[NAME].fieldControl-LookupResultsDropdown_[NAME]') and contains(@data-id,'tabContainer')]" },
{ "Entity_LookupFieldDeleteExistingValue", "//*[contains(@data-id, \'[NAME].fieldControl-LookupResultsDropdown_[NAME]_selected_tag_delete')]" },
{ "Entity_LookupFieldNoRecordsText", "//*[@data-id=\'[NAME].fieldControl-LookupResultsDropdown_[NAME]_No_Records_Text']" },
{ "Entity_LookupFieldResultList", "//*[@data-id=\'[NAME].fieldControl-LookupResultsDropdown_[NAME]_tab']" },
{ "Entity_LookupFieldHoverExistingValue", "//*[contains(@data-id, \'[NAME].fieldControl-LookupResultsDropdown_[NAME]_SelectedRecordList')]" },
{ "Entity_TextFieldLookupFieldContainer", "//*[contains(@data-id, '[NAME].fieldControl-Lookup_[NAME]')]" },
{ "Entity_RecordSetNavigatorOpen", "//button[contains(@data-lp-id, 'recordset-navigator')]" },
Expand Down
11 changes: 10 additions & 1 deletion Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs
Expand Up @@ -3,6 +3,7 @@

using Microsoft.Dynamics365.UIAutomation.Browser;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
Expand Down Expand Up @@ -1627,15 +1628,19 @@ internal BrowserCommandResult<bool> SetValue(LookupItem control, int index = 0)
{
return this.Execute(GetOptions($"Set Lookup Value: {control.Name}"), driver =>
{
driver.WaitForTransaction(5);
var fieldContainer = driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Entity.TextFieldLookupFieldContainer].Replace("[NAME]", control.Name)));
if (fieldContainer.FindElements(By.TagName("input")).Count == 0)
{
var existingLookupValue = fieldContainer.FindElement(By.XPath(AppElements.Xpath[AppReference.Entity.LookupFieldHoverExistingValue].Replace("[NAME]", control.Name)));
existingLookupValue.Hover(driver);
Thread.Sleep(500);
var deleteExistingLookupValue = fieldContainer.FindElement(By.XPath(AppElements.Xpath[AppReference.Entity.LookupFieldDeleteExistingValue].Replace("[NAME]", control.Name)));
deleteExistingLookupValue.Click();
Thread.Sleep(500);
}
fieldContainer = driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Entity.TextFieldLookupFieldContainer].Replace("[NAME]", control.Name)));
Expand All @@ -1653,7 +1658,11 @@ internal BrowserCommandResult<bool> SetValue(LookupItem control, int index = 0)
if (control.Value != null && control.Value != "")
{
var flyoutDialog = driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Entity.TextFieldLookupMenu].Replace("[NAME]", control.Name)));
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(d => d.FindElement(By.XPath(AppElements.Xpath[AppReference.Entity.LookupFieldNoRecordsText].Replace("[NAME]", control.Name) + "|" +
AppElements.Xpath[AppReference.Entity.LookupFieldResultList].Replace("[NAME]", control.Name))));
var flyoutDialog = driver.FindElement(By.XPath(AppElements.Xpath[AppReference.Entity.TextFieldLookupMenu].Replace("[NAME]", control.Name)));
var dialogItems = OpenDialog(flyoutDialog).Value;
if (dialogItems.Count <= 0)
Expand Down

0 comments on commit d38f81d

Please sign in to comment.