Example #1
0
        public void UIAConditionMatcher_Match_Positive()
        {
            UIATestObject to = new UIATestObject();

            to.ControlName = "Clear";

            UIATestObject rootWindow = new UIATestObject();

            rootWindow.ControlName = "Calculator";

            UIATestObject targetTestObject = new UIATestObject();

            targetTestObject.ControlName = "Clear";

            rootWindow.AddChild(targetTestObject);

            AutomationElement element = targetTestObject.AutomationElement;

            Assert.IsNotNull(element, "Target element is not found, has Calculator.exe process launched?");

            UIAConditionMatcher matcher = new UIAConditionMatcher();

            //positive match
            bool matched = matcher.Match(to, element);

            Assert.AreEqual(true, matched);

            to.ControlName = "something else";

            matched = matcher.Match(to, element);

            Assert.AreEqual(false, matched);
        }
Example #2
0
        public static bool EditVirtualControls(UIATestObject testObject, Image image, ref VirtualTestObject[] virtualControls)
        {
            //TreeNode node = (TreeNode)_selectedNode;

            VirtualControlEditWindow editWindow = new VirtualControlEditWindow();

            //Get image and the virtual controls list of the test object
            editWindow.SetImage(image);
            editWindow.ParentObject = testObject;

            //get the current test object
            editWindow.VirtualControls = virtualControls;

            //Launch the edit window with the parameters
            DialogResult result = editWindow.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.Cancel)
            {
                return(false);
            }

            //get the virtual controls from the edit window
            VirtualTestObject[] controls = editWindow.VirtualControls;

            //TODO merge the controls to the tree
            Debug.WriteLine(DumpVirtualControls(controls));

            virtualControls = controls;
            return(true);
        }
Example #3
0
        public void SpyHelper_DeleteSelectedProperties()
        {
            //TODO: need to update the unit test

            UIATestObject testObject = new UIATestObject(
                ObjectDescriptor.FromJson(@"{
              ""identifyProperties"": {
                ""title"": ""LAP (Running) - Microsoft Visual Studio"",
                ""helptext"": ""this is help text"",
                ""url"": ""this is url"",
                ""type"": ""Window""}
              }"));

            Assert.AreEqual(4, testObject.Properties.Count);

            DataGridView propertyGrid = GetAnEmptyPropertyGrid();

            SpyWindowHelper.FillPropertyGrid(propertyGrid, testObject);

            Assert.AreEqual(5, propertyGrid.Rows.Count, "Should have 5 properties before deletion");

            SpyWindowHelper.DeleteSelectedProperties(ControlKeys.Title, testObject);

            SpyWindowHelper.FillPropertyGrid(propertyGrid, testObject);

            string data = DumpPropertyGridRows(propertyGrid);

            Debug.Write(data);
            Assert.AreEqual(4, propertyGrid.Rows.Count, data);
        }
Example #4
0
        public void SpyHelper_AddSelectedProperty()
        {
            UIATestObject testObject = new UIATestObject(
                ObjectDescriptor.FromJson(@"{
              ""identifyProperties"": {
                ""title"": ""LAP (Running) - Microsoft Visual Studio"",
                ""helptext"": ""this is help text"",
                ""url"": ""this is url"",
                ""type"": ""Window""}
              }"));

            Assert.AreEqual(4, testObject.Properties.Count);

            DataGridView propertyGrid = GetAnEmptyPropertyGrid();

            SpyWindowHelper.FillPropertyGrid(propertyGrid, testObject);

            Assert.AreEqual(5, propertyGrid.Rows.Count, "Should have 4 properties before selection");

            propertyGrid.Rows[1].Selected = true;
            propertyGrid.Rows[2].Selected = true;

            UIATestObject newTestObject = new UIATestObject();

            Assert.AreEqual(0, newTestObject.Properties.Count);

            SpyWindowHelper.AddSelectedProperty(propertyGrid, newTestObject);

            Assert.AreEqual(2, newTestObject.Properties.Count);
        }
        public void CaptureSnapshot(TestObjectNurse nurseObject)
        {
            string token = null;

            UIATestObject testObject = nurseObject.TestObject as UIATestObject;

            if (testObject == null)
            {
                return;                     //not the UIA object
            }
            AutomationElement element = testObject.AutomationElement;

            if (SpySettings.CaptureSnapshots)
            {
                try
                {
                    //capture snapshot of clicked area
                    SnapshotHelper.CaptureTempSnapshot(element, out token);
                }
                catch (ElementNotAvailableException)
                {
                    MessageBox.Show(StringResources.LPSpy_SpyMainWindow_CannotFindObjectMsg);
                }
                catch (ApplicationException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            nurseObject.ImageFile = SnapshotHelper.GetCachedSnapshot(token, nurseObject.ImageFile);


            AppEnvironment.SetModelChanged(true);
        }
        // return the current object condtion array to string;
        public static UIATestObject GetTO(ITestObject parentTestObject, ControlType controlType, params string[] conditionStrings)
        {
            UIATestObject testObject = new UIATestObject();

            testObject.ControlType = controlType;

            foreach (string condition in conditionStrings)
            {
                if (!string.IsNullOrEmpty(condition))
                {
                    string[] values = condition.Split(new string[] { DescriptionString.AssignOperator }, StringSplitOptions.None);
                    if (values.Length == 1)
                    {
                        string name = values[0];
                        if (parentTestObject == null)
                        {
                            return((UIATestObject)AppModel.Current.GetTestObject(name));
                        }
                        else
                        {
                            return((UIATestObject)parentTestObject.FindRecursive(DescriptorKeys.NodeName, name));
                        }
                    }
                    else
                    {
                        testObject.AddProperty(values[0].Trim(), values[1].Trim());
                    }
                }
            }

            return(testObject);
        }
Example #7
0
        public void TestObjectNurse_AddChild_NurseObject()
        {
            UIATestObject   grandParentTestObject = new UIATestObject();
            TestObjectNurse grandParentNurse      = new TestObjectNurse(grandParentTestObject);

            TestObjectNurse parentNurse = new TestObjectNurse(_parentTestObject);

            grandParentNurse.AddChild(parentNurse);

            //Add the child test object to the tree,
            TestObjectNurse childNurse = new TestObjectNurse(_childTestObject);

            parentNurse.AddChild(childNurse);

            Assert.AreEqual(_childTestObject, childNurse.TestObject);

            //Assert hierarchy
            Assert.AreEqual(childNurse, parentNurse.Children[0]);
            Assert.AreEqual(parentNurse, childNurse.Parent);

            Assert.AreEqual(_parentTestObject, _childTestObject.Parent);
            Assert.AreEqual(_childTestObject, _parentTestObject.Children[0]);

            Assert.AreEqual(grandParentNurse.TreeNode, parentNurse.TreeNode.Parent);

            Assert.AreEqual(parentNurse.TreeNode, childNurse.TreeNode.Parent);
            Assert.AreEqual(childNurse.TreeNode, parentNurse.TreeNode.Nodes[0]);
        }
Example #8
0
        public void TestObjectNurse_Children()
        {
            //init test objects
            UIATestObject childTestObject2 = new UIATestObject();
            UIATestObject childTestObject3 = new UIATestObject();


            _childTestObject.AddChild(_grandChildTestObject);
            _parentTestObject.AddChild(_childTestObject);
            _parentTestObject.AddChild(childTestObject2);
            _parentTestObject.AddChild(childTestObject3);

            //initialize nurse objects
            TestObjectNurse parentNurse = new TestObjectNurse(_parentTestObject);

            TestObjectNurse childNurse  = parentNurse.AddChild(_childTestObject) as TestObjectNurse;
            TestObjectNurse childNurse2 = parentNurse.AddChild(childTestObject2) as TestObjectNurse;
            TestObjectNurse childNurse3 = parentNurse.AddChild(childTestObject3) as TestObjectNurse;

            Assert.AreEqual(3, parentNurse.Children.Count);

            Assert.AreEqual(_childTestObject, parentNurse[0].TestObject);
            Assert.AreEqual(childTestObject2, parentNurse[1].TestObject);
            Assert.AreEqual(childTestObject3, parentNurse[2].TestObject);
        }
Example #9
0
        public void AppModel_Add()
        {
            AppModel    model = new AppModel();
            ITestObject obj   = new UIATestObject();

            model.Add(obj);
        }
 private void HighlightObjectThread()
 {
     UIATestObject testObject = (UIATestObject)_condition.TestObject;
     if (!UIAHighlight.SearchAndHighlight(testObject))
     {
         MessageBox.Show(StringResources.LPSpy_SpyMainWindow_CannotFindObjectMsg);
     }
 }
        public void UIAHighlight_SearchandHighlight_UIA()
        {
            UIATestObject testObject = descriptor.GetObject() as UIATestObject;

            bool result = UIAHighlight.SearchAndHighlight(testObject);

            Assert.IsTrue(result);
        }
Example #12
0
        public void AppModel_Load()
        {
            AppModel    model = AppModelManager.Load("UnitTestObjectModel1.json");
            ITestObject obj   = new UIATestObject();

            model.Add(obj);
            Assert.IsTrue(true);
        }
        public void UIATestObject_ControlTypeInit()
        {
            UIATestObject testObject = new UIATestObject();

            testObject.AddProperty(ControlKeys.Type, ControlType.Slider.ControlTypeToString());

            Assert.AreEqual(1, testObject.Properties.Count);
            Assert.AreEqual(ControlType.Slider, testObject.ControlType);
        }
Example #14
0
        private void ConditionSelectorWindow_Load(object sender, EventArgs e)
        {
            Debug.Assert(this.Tag != null);

            TestObjectNurse nurseObject = TestObjectNurse.FromTreeNode((TreeNode)this.Tag);
            UIATestObject   testObject  = new UIATestObject();

            FillListView(testObject);
        }
Example #15
0
        public void PrepareTree()
        {
            _treeView = new TreeView();

            _rootTestObject       = new UIATestObject();
            _parentTestObject     = new UIATestObject();
            _childTestObject      = new UIATestObject();
            _grandChildTestObject = new VirtualTestObject();
        }
Example #16
0
        public void UIAEdit_Text()
        {
            ObjectDescriptor descriptor   = ObjectDescriptor.FromJson(calcJsonString);
            ITestObject      parentObject = descriptor.GetObject();

            UIATestObject button1Object = (UIATestObject)parentObject.FindRecursive(DescriptorKeys.NodeName, "1");
            UIATestObject resultObject  = (UIATestObject)parentObject.FindRecursive(DescriptorKeys.NodeName, "1");

            UIAEdit uiaEdit = new UIAEdit(new UIACondition(resultObject));
        }
        public void VirtualControlHelper_MergeVirtualControls()
        {
            UIATestObject testObject = new UIATestObject();

            testObject.AddChild(new VirtualTestObject());
            testObject.AddChild(new VirtualTestObject());
            testObject.AddChild(new VirtualTestObject());
            testObject.AddChild(new VirtualTestObject());
            testObject.AddChild(new UIATestObject());
        }
Example #18
0
        public static TestObjectNurse ConvertSubtree(UIATestObject topTestObject)
        {
            TestObjectNurse nurse = new TestObjectNurse(topTestObject);

            foreach (ITestObject childTestObject in topTestObject.Children)
            {
                nurse.AddDecendants(childTestObject);
            }
            return(nurse);
        }
Example #19
0
        public void TestObjectNurse_NodeName()
        {
            UIATestObject testObject = new UIATestObject();

            testObject.ControlType = ControlType.ComboBox;

            TestObjectNurse nurse = new TestObjectNurse(testObject);

            nurse.NodeName = "HelloWorld";
            Assert.AreEqual("ComboBox: HelloWorld", nurse.TreeNode.Text);
        }
        public void UIATestObject_ControlTypeAssign()
        {
            UIATestObject testObject = new UIATestObject();

            Assert.AreEqual(0, testObject.Properties.Count);
            testObject.ControlType = ControlType.Window;

            Assert.AreEqual("Window", testObject.ControlTypeString);

            Assert.AreEqual(1, testObject.Properties.Count);
        }
        private static TestObjectNurse BuildTestObjectsHierarchy(List <AutomationElement> ancestorElements,
                                                                 BreadcrumbControl breadcrumbControl,
                                                                 LAPListViewControl listView,
                                                                 Bitmap bmpDeskTop
                                                                 )
        {
            int ancestorCount            = ancestorElements.Count;
            int breadcrumbCount          = breadcrumbControl.Count;
            int indexOfAutomationElement = 0;

            UIATestObject   topTestObject      = UIAUtility.CreateTestObject(ancestorElements[0]);
            TestObjectNurse topNurseObject     = new TestObjectNurse(topTestObject);
            TestObjectNurse currentNurseObject = topNurseObject;

            if (ancestorCount > breadcrumbCount)
            {
                for (indexOfAutomationElement = 1; indexOfAutomationElement < ancestorCount && breadcrumbCount < ancestorCount - indexOfAutomationElement; ++indexOfAutomationElement)
                {
                    AutomationElement element = ancestorElements[indexOfAutomationElement];
                    if (!string.IsNullOrEmpty(element.Current.Name))
                    {
                        UIATestObject childTestObject = UIAUtility.CreateTestObject(element);
                        currentNurseObject = (TestObjectNurse)currentNurseObject.AddChild(childTestObject);
                    }
                }
            }

            Breadcrumb[] breadcrumbs = breadcrumbControl.GetItems();
            foreach (Breadcrumb breadcrumb in breadcrumbs)
            {
                if (breadcrumb.Checked)
                {
                    UIATestObject childTestObject = UIAUtility.CreateTestObject((breadcrumb.Tag as ElementProperties).AutomationElement);
                    currentNurseObject = (TestObjectNurse)currentNurseObject.AddChild(childTestObject);
                }
            }

            ListView.CheckedListViewItemCollection selectedItems = listView.CheckedItems;

            foreach (ListViewItem item in selectedItems)
            {
                if (null == item.Tag)
                {
                    continue;
                }
                ElementProperties ep       = item.Tag as ElementProperties;
                TestObjectNurse   subNurse = ep.ToNurseObject();

                subNurse.ImageFile = SnapshotHelper.SnapshotFileFromBitmap(subNurse.TestObject, bmpDeskTop);
                currentNurseObject.AddChild(subNurse);
            }
            return(topNurseObject);
        }
        public void UIATestObject_FindRecursive()
        {
            AppModel.Initialize("UnitTestObjectModel1.json");
            UIATestObject parentObject = (UIATestObject)AppModel.Current.GetTestObject("LAP (Running) - Microsoft Visual Studio");

            UIATestObject testObject = (UIATestObject)parentObject.FindRecursive(DescriptorKeys.NodeName, "Search");

            Assert.IsNotNull(testObject, "Should find the test object in the model");

            testObject = (UIATestObject)parentObject.FindRecursive(DescriptorKeys.NodeName, "NotExistObject");
            Assert.IsNull(testObject, "Should not the test object with a random name");
        }
Example #23
0
        public void TestObjectNurse_ContainsKeyword()
        {
            UIATestObject testObject = new UIATestObject("Hello World", ControlType.Button, null);

            TestObjectNurse nurse = new TestObjectNurse(testObject);

            Assert.IsTrue(nurse.ContainsKeyword("Hello"));
            Assert.IsTrue(nurse.ContainsKeyword("WORLD"));

            Assert.IsFalse(nurse.ContainsKeyword("HelloWorld"));

            Assert.IsTrue(nurse.ContainsKeyword("BUTTON"));
        }
        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
        }
        public void UIATestObject_GetContext()
        {
            UIATestObject testObject = new UIATestObject();

            testObject.SetContext(new MockContextClass()
            {
                ContextName = "MockContext1"
            });

            MockContextClass context = testObject.GetContext <MockContextClass>();

            Assert.AreEqual("MockContext1", context.ContextName);
        }
        public static UIACondition GetCondition(UIACondition parentCondition, ControlType controlType, params string[] conditionStrings)
        {
            UIATestObject testObject = GetTO(parentCondition.TestObject, controlType, conditionStrings);

            //UIACondition currentCondition = parentCondition.CheckUIAConditionExists(testObject, controlType);

            //TODO, handle more conditionStrings
            return(UIACondition.GetCondition(testObject));

            //if (currentCondition != null)
            //    return currentCondition;

            //return GetCondition(parentCondition, testObject, controlType);
        }
Example #27
0
        public void UIAFinder_Identify1()
        {
            ObjectDescriptor parentDescriptor = ObjectDescriptor.FromJson(@"
                {""ntype"": ""uia"", identifyProperties: {name: ""Calculator""}}
                ");

            /*
             * ObjectDescriptor parentDescriptor = ObjectDescriptor.FromJson(@"
             *  {
             *    ""ntype"": ""uia"",
             *    ""nname"": ""LAP (Running) - Microsoft Visual Studio"",
             *    ""description"": null,
             *    ""identifyProperties"": {
             *      ""type"": ""Window"",
             *      ""title"": ""LAP (Running) - Microsoft Visual Studio""
             *    }
             *  }
             * ");
             *
             * ObjectDescriptor childDescriptor = ObjectDescriptor.FromJson(@"
             *  {
             *    ""ntype"": ""uia"",
             *    ""nname"": ""ToolBarDockTop"",
             *    ""description"": null,
             *    ""identifyProperties"": {
             *      ""type"": ""Pane"",
             *      ""name"": ""ToolBarDockTop""
             *    }
             *  }
             * ");*/
            ObjectDescriptor childDescriptor = ObjectDescriptor.FromJson(@"
                {ntype:""uia"",identifyProperties: {name: ""1""}}
                ", parentDescriptor);

            parentDescriptor.Children.Add(childDescriptor);

            UIATestObject parentTestObject = (UIATestObject)parentDescriptor.GetObject();
            UIATestObject testObject       = (UIATestObject)parentTestObject.Children[0];

            List <AutomationElement> elements = UIAFinder.FindAll(parentTestObject);

            TestUtility.DumpAutomationElements(elements);

            Assert.AreEqual(1, elements.Count, "only 1 parent element");

            elements = UIAFinder.FindAll(testObject);
            TestUtility.DumpAutomationElements(elements);

            Assert.AreEqual(1, elements.Count, "only 1 child element");
        }
Example #28
0
 // check the object and type already exists in our container(Window,Pane, AntsAutomation) list.
 public UIACondition CheckUIAConditionExists(UIATestObject testObject, ControlType controlType)
 {
     foreach (UIACondition uiaCondition in Children)
     {
         //TODO need to create the match logic
         if (uiaCondition._testObject.Equals(testObject) &&
             uiaCondition.ParentCondition == this &&
             uiaCondition.ControlType == controlType)
         {
             return(uiaCondition);
         }
     }
     return(null);
 }
Example #29
0
        public AutomationElement GetFunctionButton(ITestObject control)
        {
            AutomationElement functionButton = UIATestObject.ToAutomationObject(control);

            //AutomationElement functionButton = _calculatorAutomationElement.FindFirst(TreeScope.Descendants,
            //    new PropertyCondition(AutomationElement.NameProperty, functionName));

            if (functionButton == null)
            {
                throw new InvalidOperationException("No function button found with descriptor: " + control.ToString());
            }

            return(functionButton);
        }
        public void AppEnvironment_DumpRecyclingBin()
        {
            string modelFilePath = "TempModelFile.json";

            try
            {
                AppEnvironment.CurrentModelFile = AppModelFile.Create(modelFilePath);

                //init test objects
                UIATestObject     _parentTestObject     = new UIATestObject();
                UIATestObject     _childTestObject      = new UIATestObject();
                UIATestObject     childTestObject2      = new UIATestObject();
                VirtualTestObject _grandChildTestObject = new VirtualTestObject();

                CreatePicture(AppEnvironment.CurrentModelFile);


                //initialize nurse objects
                TestObjectNurse parentNurse = new TestObjectNurse(_parentTestObject);

                TestObjectNurse childNurse      = parentNurse.AddChild(_childTestObject) as TestObjectNurse;
                TestObjectNurse childNurse2     = parentNurse.AddChild(childTestObject2) as TestObjectNurse;
                TestObjectNurse grandChildNurse = childNurse.AddChild(_grandChildTestObject) as TestObjectNurse;

                string imagePath1 = AppEnvironment.GetModelResourceFilePath("TestObjectNurseTest.png");
                string imagePath2 = AppEnvironment.GetModelResourceFilePath("TestObjectNurseTest1.png");

                Assert.IsTrue(File.Exists(imagePath1));
                Assert.IsTrue(File.Exists(imagePath2));

                childNurse2.ImageFile     = "TestObjectNurseTest.png";
                grandChildNurse.ImageFile = "TestObjectNurseTest1.png";

                parentNurse.RemoveChild(childNurse);
                Assert.IsTrue(File.Exists(imagePath1));
                parentNurse.RemoveChild(childNurse2);
                Assert.IsTrue(File.Exists(imagePath2));

                AppEnvironment.DumpRecyclingBin(parentNurse);

                Assert.IsFalse(File.Exists(imagePath1));
                Assert.IsFalse(File.Exists(imagePath2));
            }
            finally
            {
                File.Delete("TestObjectNurseTest.png");
                File.Delete("TestObjectNurseTest1.png");
            }
        }