Пример #1
0
        private static bool? LeftRightCheck(UIACondition selfCondition, AutomationElement leftExpected, 
            AutomationElement rightExpected, AutomationElement element)
        {
            // if the same count is big than 0, will return the object.
            bool? found = null;

            if (rightExpected != null)
            {
                AutomationElement rightElement = UIAUtility.GetNextElement(element);
                if (UIAUtility.AreEqual2(rightExpected, rightElement))
                    found = true;
                else
                    return false;
            }

            if (leftExpected != null)
            {
                AutomationElement leftElement = UIAUtility.GetPreviousElement(element);
                if (UIAUtility.AreEqual2(leftExpected, leftElement))
                    found = true;
                else
                    return false;
            }

            return found;
        }
Пример #2
0
        void NormalizeCachedProperties(UIACondition uiaCondition)
        {
            ITestObject testObject = uiaCondition.TestObject;

            foreach (KeyValuePair <string, string> pair in testObject.Properties)
            {
                uiaCondition.CachedProperties.Remove(pair.Key);
            }
        }
Пример #3
0
        public void UIACondition_NormalizeCachedProperties()
        {
            UIACondition uiaCondition = new UIACondition(new UIATestObject());

            uiaCondition.TestObject.AddProperty("property1", "value1");
            uiaCondition.TestObject.AddProperty("property2", "value2");
            uiaCondition.TestObject.AddProperty("property3", "value3");

            NormalizeCachedProperties(uiaCondition);
        }
        public void ConditionSelector_Test()
        {
            ConditionSelectorWindow window       = new ConditionSelectorWindow();
            UIACondition            uiaCondition = new UIACondition(new UIATestObject());
            TreeNode treeNode = new TreeNode();

            treeNode.Tag = uiaCondition;

            window.Tag = treeNode;
            window.ShowDialog();
        }
Пример #5
0
        public void AppModelManager_LoadFull()
        {
            AppModel       model;
            ModelLoadLevel loadLevel = ModelLoadLevel.Full;

            model = AppModelManager.Load("CalcAppModel.json", loadLevel);
            UIATestObject testObject = (UIATestObject)model.FindFirst(DescriptorKeys.NodeName, "result");

            Assert.AreNotEqual(null, testObject);
            UIACondition condition = testObject.GetContext <UIACondition>();

            //TODO validate the content
        }
Пример #6
0
        public AutomationElement IndexLocator(UIACondition selfCondition, AutomationElementCollection matchedElements)
        {

            if (matchedElements.Count - 1 < selfCondition.Index)
            {
                return null;
            }
            else
            {
                Highlight.HighlightThread(matchedElements[selfCondition.Index]);
                selfCondition.AutomationElement = matchedElements[selfCondition.Index];
                return selfCondition.AutomationElement;
            }
            
        }
Пример #7
0
        public bool? LeftRightLocator(UIACondition selfCondition, out AutomationElement element)
        {
            AutomationElement leftElement = null, rightElement = null;
            //check if the left or right condtion exist            
            //get the left and right element            
            if (selfCondition.Right != "")
            {
                ITestObject rightTO;
                
                if (selfCondition.Right.IndexOf(DescriptionString.LeftRightQtpString) >= 0)
                {
                    //format Right==something
                    rightTO = UIAHelper.ConvertStringToTestObject(selfCondition.Right); 
                }
                else
                {
                    //selfCondition.Right is the name, then use the name to extract descriptor
                    rightTO = UIAJsonPersister.LoadData(selfCondition.Right, selfCondition.ParentCondition.TestObject);
                }

                UIACondition rightCondition = new UIACondition(rightTO);

                rightCondition.ParentCondition = selfCondition.ParentCondition;
                rightElement = Find(rightCondition);
            }

            if (selfCondition.Left != "")
            {
                ITestObject leftDescriptor = null;
                if (selfCondition.Left.IndexOf(DescriptionString.LeftRightQtpString) >= 0)
                {
                    leftDescriptor = UIAHelper.ConvertStringToTestObject(selfCondition.Left);
                }
                else
                {
                    leftDescriptor = UIAJsonPersister.LoadData(selfCondition.Left, selfCondition.ParentCondition.TestObject);
                }
                UIACondition leftCondition = new UIACondition(leftDescriptor);
                leftCondition.ParentCondition = selfCondition.ParentCondition;
                leftElement = Find(leftCondition);
            }

            int sameCount = 0;
            bool? found = LeftRightCheck(selfCondition, leftElement, rightElement, element);

            return found;
        }
Пример #8
0
        public AutomationElement Find(UIACondition selfCondition)
        {
           
            AutomationElementCollection matchedElements =
                ConditionLocator(selfCondition);

            if (matchedElements.Count == 0)
            {
                Logger.WriteWarning("Can not find child in the parent container:" + selfCondition.ControlName);
                return null;
            }
            else
            {
                Logger.WriteDebug("Objects Count:" + matchedElements.Count);
            }

                        //if using index only, return the object
            if (selfCondition.IsIndexOnly)
            {
                return IndexLocator(selfCondition, matchedElements);
            }

            AutomationElement element;

            bool? result = LeftRightLocator(selfCondition, out element); 
            if (result != null) 
            {
                return element;
            }

            // if window, just check the caption, 60% match will be recognized.
            if (selfCondition.IsWindow)
            {
                element = TopWindowLocator(selfCondition, matchedElements);

                return element;
            }

            return FindInMatchedCollection(selfCondition, matchedElements);
        }
Пример #9
0
        public void UIACondition_CachedProperties()
        {
            ObjectDescriptor descriptor = ObjectDescriptor.FromJson(
                @"
                 {
			        ntype: ""uia"",
			        nname: ""button1"",
			        identifyProperties:{""name"": ""1""},
                    cachedProperties:{""className"": ""QWidget""},
			        description: ""button""
		        }"        );

            UIATestObject testObject = UIATestObject.ToTestObject(descriptor);

            CachedPropertyGroup cachedGroup = testObject.GetContext <CachedPropertyGroup>();

            Assert.AreNotEqual(null, cachedGroup);

            UIACondition condition = new UIACondition(testObject);

            Assert.AreEqual(1, condition.CachedProperties.Count);
        }
Пример #10
0
        private AutomationElement TopWindowLocator(UIACondition selfCondition, AutomationElementCollection matchedElements)
        {
            int matchIndex = 0;

            foreach (AutomationElement element in matchedElements)
            {
                string caption = element.Current.Name;
                if (Utility.StringSimiliarityCompare(selfCondition.Text, caption, 50))
                {
                    if (selfCondition.Index == matchIndex)
                    {
                        Highlight.HighlightThread(element);
                        selfCondition.AutomationElement = element;
                        return selfCondition.AutomationElement;
                    }
                    else
                    {
                        matchIndex++;
                    }
                }
            }
            return null;
        }
Пример #11
0
        public AutomationElementCollection ConditionLocator(UIACondition selfCondition)
        {
            AutomationElementCollection matchedElements = null;
            Logger.WriteLog("Start to find the UIAObject by condition");

            if (selfCondition.Condition != null)
            {
                Retry3Times(() =>
                {
                    matchedElements = UIAUtility.FindDescendantElements(selfCondition.ParentCondition.AutomationElement, selfCondition.Condition);
                    return matchedElements.Count > 0;
                });
            }
            else
            {
                Retry3Times(() =>
                {
                    matchedElements = UIAUtility.FindDescendantElements(selfCondition.ParentCondition.AutomationElement, TreeWalker.ControlViewWalker.Condition);
                    return matchedElements.Count > 0;
                });
            }

            return matchedElements;
        }
Пример #12
0
        private AutomationElement FindInMatchedCollection(UIACondition selfCondition, AutomationElementCollection matchedElements)
        {
            int matchIndex = 0;

            //check all of the element which match the type condition and attached text
            foreach (AutomationElement element in matchedElements)
            {
                int sameCount = 0;
                //LeftRightCheck(selfCondition, leftElement, rightElement, ref sameCount, element);


                // object match 80% will be return.
                if (selfCondition.Text != "")
                {
                    string aName = "";
                    try
                    {
                        aName = ((TextPattern)element.GetCurrentPattern(TextPattern.Pattern)).DocumentRange.GetText(-1);
                    }
                    catch { }

                    try
                    {
                        aName = ((ValuePattern)element.GetCurrentPattern(ValuePattern.Pattern)).Current.Value;
                    }
                    catch { }

                    try
                    {

                        aName = (string)element.GetCurrentPropertyValue(LegacyIAccessiblePattern.ValueProperty);
                    }
                    catch { }

                    if (aName == null || aName == "")
                    {
                        aName = element.Current.Name;
                    }
                    if (aName != "")
                    {
                        if (Utility.StringSimiliarityCompare(selfCondition.Text, aName, 80))
                        {
                            sameCount++;
                        }
                    }
                }

                //find object by attached text;
                if (selfCondition.AttachedText != "")
                {
                    AutomationElement attachedElement = (AutomationElement)element.Current.LabeledBy;
                    if (attachedElement != null)
                    {
                        string labelName = attachedElement.Current.Name;
                        if (selfCondition.AttachedText == labelName)
                        {
                            sameCount++;
                        }
                    }
                }

                // if count number bigger than 2, will return the object
                if ((sameCount / selfCondition.ConditionCount) >= 0.5)
                {
                    if (selfCondition.Index == matchIndex)
                    {
                        Highlight.HighlightThread(element);
                        selfCondition.AutomationElement = element;
                        return selfCondition.AutomationElement;
                    }
                    else
                    {
                        matchIndex++;
                    }
                }
            }
        }