Exemplo n.º 1
0
        /// <summary>
        /// Clears the value of a Lookup on a QuickCreate form
        /// </summary>
        /// <param name="control">The lookup field name, value or index of the lookup.</param>
        /// <example>xrmBrowser.QuickCreate.ClearValue(new Lookup { Name = "prrimarycontactid", Value = "Rene Valdes (sample)" });</example>
        public BrowserCommandResult <bool> ClearValue(LookupItem control)
        {
            return(this.Execute(GetOptions($"Clear QuickCreate Lookup Value: {control.Name}"), driver =>
            {
                if (driver.HasElement(By.XPath(Elements.Xpath[Reference.Entity.LookupFieldContainer].Replace("[NAME]", control.Name.ToLower()))))
                {
                    var fieldElement = driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Entity.LookupFieldContainer].Replace("[NAME]", control.Name.ToLower())));

                    if (fieldElement.Text != "")
                    {
                        fieldElement.Hover(driver, true);

                        if (fieldElement.FindElement(By.XPath(Elements.Xpath[Reference.Entity.GetLookupSearchIcon].Replace("[NAME]", control.Name.ToLower()))) == null)
                        {
                            throw new InvalidOperationException($"Field: {control.Name} is not Lookup control");
                        }

                        driver.Manage().Window.Maximize();
                        var lookupSearch = driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Entity.GetLookupSearchIcon].Replace("[NAME]", control.Name.ToLower())));

                        if (!lookupSearch.Displayed)
                        {
                            driver.Manage().Window.Minimize();
                            driver.Manage().Window.Maximize();
                            fieldElement.Hover(driver, true);
                            lookupSearch = driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Entity.GetLookupSearchIcon].Replace("[NAME]", control.Name.ToLower())));
                        }

                        lookupSearch.Click(true);

                        var dialogName = $"Dialog_{control.Name}_IMenu";
                        var dialog = driver.WaitUntilAvailable(By.Id(dialogName));

                        var dialogItems = OpenDialog(dialog).Value;

                        if (dialogItems.Any())
                        {
                            var dialogItem = dialogItems.Last();
                            dialogItem.Element.Click();
                        }

                        SwitchToDialog();

                        driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.LookUp.Remove])).Click(true);
                    }
                }
                else
                {
                    throw new InvalidOperationException($"Unable to locate Lookup '{control.Name}' on the QuickCreate form. Please verify the Lookup exists and try again.");
                }

                return true;
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the value of a Lookup on a QuickCreate form.
        /// </summary>
        /// <param name="control">The lookup field name, value or index of the lookup.</param>
        /// <example>xrmBrowser.QuickCreate.SetValue(new Lookup { Name = "primarycontactid", Value = "Rene Valdes (sample)" });</example>
        public new BrowserCommandResult <bool> SetValue(LookupItem control)
        {
            return(this.Execute(GetOptions($"Set QuickCreate Lookup Value: {control.Name}"), driver =>
            {
                if (driver.HasElement(By.Id(control.Name)))
                {
                    driver.WaitUntilVisible(By.Id(control.Name));

                    var input = driver.ClickWhenAvailable(By.Id(control.Name));

                    if (input.FindElement(By.ClassName(Elements.CssClass[Reference.SetValue.LookupRenderClass])) == null)
                    {
                        throw new InvalidOperationException($"Field: {control.Name} is not lookup");
                    }

                    input.FindElement(By.ClassName(Elements.CssClass[Reference.SetValue.LookupRenderClass])).Click();

                    var dialogName = $"Dialog_{control.Name}_IMenu";
                    var dialog = driver.WaitUntilAvailable(By.Id(dialogName));

                    var dialogItems = OpenDialog(dialog).Value;


                    if (control.Value != null)
                    {
                        if (!dialogItems.Exists(x => x.Title == control.Value))
                        {
                            throw new InvalidOperationException($"List does not have {control.Value}.");
                        }

                        var dialogItem = dialogItems.Where(x => x.Title == control.Value).First();
                        dialogItem.Element.Click();
                    }
                    else
                    {
                        if (dialogItems.Count < control.Index)
                        {
                            throw new InvalidOperationException($"List does not have {control.Index + 1} items.");
                        }

                        var dialogItem = dialogItems[control.Index];
                        dialogItem.Element.Click();
                    }
                }
                else
                {
                    throw new InvalidOperationException($"Unable to locate the Lookup field '{control.Name}' on the QuickCreate form. Please verify the Lookup field exists and try again.");
                }

                return true;
            }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set Lookup Value for the field
        /// </summary>
        /// <param name="field">The Field</param>
        /// <param name="openLookupPage">The Open Lookup Page</param>
        /// <param name="clearFieldValue">Remove Existing Field Value, if present. False = Click the existing value</param>
        public new BrowserCommandResult <bool> SelectLookup(LookupItem field, bool clearFieldValue = true, bool openLookupPage = true)
        {
            return(this.Execute(GetOptions($"Select QuickCreate Lookup for: {field.Name}"), driver =>
            {
                if (driver.HasElement(By.Id(field.Name)))
                {
                    var fieldContainer = driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Entity.FieldContainer].Replace("[NAME]", field.Name)));

                    if (fieldContainer.Text != "" && clearFieldValue)
                    {
                        fieldContainer.SendKeys(Keys.Clear);
                    }
                    else if (fieldContainer.Text != "" && !clearFieldValue)
                    {
                        fieldContainer.Click();
                        return true;
                    }

                    var input = driver.ClickWhenAvailable(By.Id(field.Name));

                    if (input.FindElement(By.ClassName(Elements.CssClass[Reference.SetValue.LookupRenderClass])) == null)
                    {
                        throw new InvalidOperationException($"Field: {field.Name} is not lookup");
                    }

                    input.FindElement(By.ClassName(Elements.CssClass[Reference.SetValue.LookupRenderClass])).Click();

                    Browser.ThinkTime(1000);
                    var dialogName = $"Dialog_{field.Name}_IMenu";
                    var dialog = driver.WaitUntilAvailable(By.Id(dialogName));

                    var dialogItems = OpenDialog(dialog).Value;

                    if (dialogItems.Any())
                    {
                        var dialogItem = dialogItems.Last();
                        dialogItem.Element.Click();
                    }
                }
                else
                {
                    throw new InvalidOperationException($"Field: {field.Name} Does not exist");
                }

                return true;
            }));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the value of a Lookup on a QuickCreate form.
        /// </summary>
        /// <param name="control">The lookup field name, value or index of the lookup.</param>
        /// <example>xrmBrowser.QuickCreate.GetValue(new Lookup { Name = "primarycontactid" });</example>
        public BrowserCommandResult <string> GetValue(LookupItem control)
        {
            return(this.Execute($"Get QuickCreate Lookup Value: {control.Name}", driver =>
            {
                driver.WaitUntilVisible(By.Id(control.Name));

                string lookupValue = string.Empty;
                if (driver.HasElement(By.Id(control.Name)))
                {
                    var input = driver.FindElement(By.Id(control.Name));
                    lookupValue = input.Text;
                }
                else
                {
                    throw new InvalidOperationException($"Field: {control.Name} Does not exist");
                }

                return lookupValue;
            }));
        }