Beispiel #1
0
        protected AutomationElement FindUIAControl(XmlNode control)
        {
            string controlName = GetAttributeValue(control, "name", "");

            AutomationElement rootAutomationElement = this.RootAutomationElement;

            if (control != null)
            {
                System.Windows.Automation.Condition condition = null;
                int          result       = 1;
                int          num2         = 1;
                XmlAttribute xmlAttribute = UIAHelperMethods.GetXmlAttribute(control, "StartFromDesktop");
                if ((xmlAttribute != null) && (xmlAttribute.Value != null))
                {
                    bool flag = true;
                    if (xmlAttribute.Value == flag.ToString())
                    {
                        rootAutomationElement = AutomationElement.RootElement;
                    }
                }
                XmlNode xnPropCondition = control.SelectSingleNode("UIObject");
                if (xnPropCondition == null)
                {
                    return(rootAutomationElement);
                }
                do
                {
                    XmlAttribute attribute2 = UIAHelperMethods.GetXmlAttribute(xnPropCondition, "MatchCount");
                    if ((attribute2 != null) && (attribute2.Value != null))
                    {
                        int.TryParse(attribute2.Value, out result);
                    }
                    condition = this.BuildSearchCondition(xnPropCondition);
                    if (result == 1)
                    {
                        rootAutomationElement = rootAutomationElement.FindFirst(TreeScope.Children, condition);
                    }
                    else
                    {
                        AutomationElementCollection elements = rootAutomationElement.FindAll(TreeScope.Children, condition);
                        if ((result <= elements.Count) && (result > 0))
                        {
                            rootAutomationElement = elements[result - 1];
                        }
                        else
                        {
                            throw new DataDrivenAdapterException(OperationType.FindControl, controlName, "DDA0400_UNABLE_TO_FIND_CONTROL_ON_UI" + string.Format(CultureInfo.CurrentUICulture, "FIND_ERROR_LEVEL", new object[] { num2.ToString(CultureInfo.InvariantCulture) }));
                        }
                    }
                    if (rootAutomationElement == null)
                    {
                        throw new DataDrivenAdapterException(OperationType.FindControl, controlName, "DDA0400_UNABLE_TO_FIND_CONTROL_ON_UI" + string.Format(CultureInfo.CurrentUICulture, "FIND_ERROR_LEVEL", new object[] { num2.ToString(CultureInfo.InvariantCulture) }));
                    }
                    xnPropCondition = xnPropCondition.SelectSingleNode("UIObject");
                    num2++;
                }while (xnPropCondition != null);
            }
            return(rootAutomationElement);
        }
Beispiel #2
0
        public UIAutomation(IntPtr _rootWindow, string _ApplicationName, AgentDesktopSession _localSession, TraceLogger _LogWriter)
        {
            localSession    = _localSession;
            LogWriter       = _LogWriter;
            ApplicationName = _ApplicationName;
            rootWindow      = _rootWindow;

            //    this.IsWebApp = false;
            this.MainWindowHandle = (IntPtr)_rootWindow;
            RootAutomationElement = AutomationElement.FromHandle(this.MainWindowHandle);
            AutomationProperties  = UIAHelperMethods.GetAutomationElementIdentifiers();
            UIAHelperMethods.UpdateControlTypeNames();
            AutomationPropReturnTypes = UIAHelperMethods.GetAutomationReturnTypes();
            AutomationEventList       = UIAHelperMethods.GetAutomationEventList();
        }
Beispiel #3
0
        private System.Windows.Automation.Condition BuildPropertyCondition(XmlNode xnPropCondition)
        {
            System.Windows.Automation.Condition condition = null;
            PropertyConditionFlags none = PropertyConditionFlags.None;
            string str = string.Empty;

            if (xnPropCondition.InnerText == null)
            {
                return(condition);
            }
            str = UIAHelperMethods.GetXmlAttribute(xnPropCondition, "Name").Value;
            Type type = AutomationPropReturnTypes[str];

            if (type.Equals(typeof(string)))
            {
                none = PropertyConditionFlags.IgnoreCase;
            }
            return(new PropertyCondition(AutomationProperties[str], this.ConvertStringtoObject(xnPropCondition.InnerText, AutomationPropReturnTypes[str]), none));
        }
Beispiel #4
0
        protected virtual object ConvertStringtoObject(string BindingText, Type type)
        {
            object obj2     = null;
            string fullName = type.FullName;

            if (fullName == null)
            {
                return(obj2);
            }
            if (fullName != "System.Boolean")
            {
                if (fullName != "System.String")
                {
                    if (fullName == "System.Windows.Rect")
                    {
                        return(UIAHelperMethods.GetRect(BindingText));
                    }
                    if (fullName == "System.Windows.Point")
                    {
                        return(UIAHelperMethods.GetPoint(BindingText));
                    }
                    if (fullName == "System.Windows.Automation.OrientationType")
                    {
                        OrientationType none = OrientationType.None;
                        Enum.TryParse <OrientationType>(BindingText, out none);
                        return(none);
                    }
                    if (fullName != "System.Windows.Automation.ControlType")
                    {
                        return(obj2);
                    }
                    return(UIAHelperMethods.GetControlType(BindingText));
                }
            }
            else
            {
                bool result = false;
                bool.TryParse(BindingText, out result);
                return(result);
            }
            return(UIAHelperMethods.UnEscapeXml(BindingText));
        }