Exemple #1
0
        public virtual bool PerformAll(string[][] details, bool bypassIfNotPresented = false)
        {
            WaitUntilVisible();
            int length = details[0].Length;

            if (details[1].Length != length)
            {
                throw new ArgumentException("string[2][] details should contain two array of the same size!");
            }
            for (int i = 0; i < length; i++)
            {
                string     controlName = details[0][i];
                string     value       = details[1][i];
                IUIControl iuiControl  = ControlFromName(controlName);
                if (iuiControl == null || !iuiControl.WaitUntilVisible(bypassIfNotPresented ? 3000 : 10 * 1000))
                {
                    if (bypassIfNotPresented)
                    {
                        continue;
                    }
                    return(false);
                }

                try
                {
                    if (UIControl.AssureShowControlBeforeOperation && !iuiControl.Show())
                    {
                        Logger.W("{0} is still not displayed!", iuiControl);
                    }

                    iuiControl.Perform(value);
                    Logger.D("{0} => {1}", controlName, value);
                    Thread.Sleep(300);
                }
                catch (StaleElementReferenceException)
                {
                    Logger.W("StaleElement of {0}.", iuiControl);
                    UIControl.DiscardLastInstance();
                    iuiControl.Perform(value);
                }
                if (WaitPageReadyAfterPerforming)
                {
                    WebDriverManager.WaitPageReady();
                }
            }
            return(true);
        }
Exemple #2
0
        protected void enterDetails(Dictionary <string, string> details)
        {
            PropertyInfo[] properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            properties = properties.Where(p => htmlControlType.IsAssignableFrom(p.GetMethod.ReturnType)).ToArray();
            PropertyInfo[] declaringProperties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
                                                 .Where(p => htmlControlType.IsAssignableFrom(p.GetMethod.ReturnType)).ToArray();
            string[] declaringPropertyNames = declaringProperties.Select(p => p.Name).ToArray();
            IEnumerable <PropertyInfo> baseOnlyProperties = properties.Except(declaringProperties).Where(p => !declaringPropertyNames.Contains(p.Name));

            List <PropertyInfo> orderedProperties = new List <PropertyInfo>(baseOnlyProperties);

            orderedProperties.AddRange(declaringProperties);
            string[] accessorNames = orderedProperties.Select(p => p.Name).ToArray();

            for (int i = 0; i < accessorNames.Count(); i++)
            {
                string name    = accessorNames[i];
                string onclick = null;

                if (details.ContainsKey(name))
                {
                    if (WaitPageReadyBeforePerforming)
                    {
                        WebDriverManager.WaitPageReady();
                    }

                    IUIControl iuiControl = orderedProperties[i].GetMethod.Invoke(this, null) as IUIControl;
                    if (iuiControl == null || !iuiControl.IsVisible)
                    {
                        continue;
                    }
                    iuiControl.Perform(details[name]);
                    if (iuiControl.Element.TryGetAttribute("onclick", out onclick) && !string.IsNullOrEmpty(onclick))
                    {
                        Thread.Sleep(1000);
                    }
                    else if (iuiControl.Element.TryGetAttribute("onchange", out onclick) && !string.IsNullOrEmpty(onclick))
                    {
                        Thread.Sleep(1000);
                    }

                    if (WaitPageReadyAfterPerforming)
                    {
                        WebDriverManager.WaitPageReady();
                    }
                }
            }
        }