Пример #1
0
        //use this to show the properties in the adding properties window
        public UIACondition(AutomationElement element, string nodeName, string leftName = "", string rightName = "")
        {
            if (leftName != "")
            {
                _left = leftName;
            }

            if (rightName != "")
            {
                _right = rightName;
            }

            UIAUtility.InitProperties(nodeName, element, TestObject);

            try
            {
                if (element.Current.NativeWindowHandle != 0)
                {
                    _hwnd = (int)element.Current.NativeWindowHandle;
                }
            }
            catch { }

            try
            {
                if (element.Current.ProcessId > 0)
                {
                    _processId = element.Current.ProcessId;
                }
            }
            catch
            { }
        }
Пример #2
0
        public bool?LocateByRelation(ITestObject to, AutomationElement element)
        {
            IRelation relation = to.Relation;

            if (relation == null)
            {
                return(null);
            }

            ITestObject leftTO  = relation.Left;
            ITestObject rightTO = relation.Right;

            if (leftTO == null && rightTO == null)
            {
                return(null);
            }

            if (leftTO != null)
            {
                AutomationElement leftElement = UIAUtility.GetPreviousElement(element);
                if (!Match(leftTO, leftElement))
                {
                    return(false);
                }
            }
            if (rightTO != null)
            {
                AutomationElement rightElement = UIAUtility.GetNextElement(element);
                if (!Match(rightTO, rightElement))
                {
                    return(false);
                }
            }
            return(true);
        }
        private CreateAccountDriver(AutomationElement parentElement)
        {
            _parentElement = parentElement;
            _dialog        = UIAUtility.FindElementByIdWithTimeout(_parentElement, DialogId, AddinTestUtility.WebServiceResponsePopulateTimeout);

            _nameCtl = UIAUtility.FindElementById(_dialog,
                                                  "NameTextBox");
            _emailCtl = UIAUtility.FindElementById(_dialog,
                                                   "EmailTextBox");
            _passwordCtl = UIAUtility.FindElementById(_dialog,
                                                      "PasswordTextBox");
            _termsCtl = UIAUtility.FindElementById(_dialog,
                                                   "TermsCheckbox");
            _rememberMeCtl = UIAUtility.FindElementById(_dialog,
                                                        "RememberMeCheckbox");
            _registerCtl = UIAUtility.FindElementById(_dialog,
                                                      "OKButton");
            _cancelCtl = UIAUtility.FindElementById(_dialog,
                                                    "CancelButton");
            _genericServerErrorErrMsgCtl = UIAUtility.FindElementByIdChildByClassname(_dialog,
                                                                                      "GenericServerErrorErrorMessage", "TextBlock", TreeScope.Descendants);
            _closeIconCtl = UIAUtility.FindElementById(_dialog,
                                                       "Close", TreeScope.Descendants);

            WaitForDialogReady();
        }
Пример #4
0
        /// <summary>
        /// Select Publish button to close dialog - validate success by ensuring dialog closes
        /// </summary>
        /// <exception cref="TimeoutException">dialog did not close</exception>
        public void SelectPublishVerifySuccess()
        {
            EnsureDialogEventsFired();

            UIAUtility.WaitForElementEnabledWithTimeout(_publishCtl, AddinTestUtility.DialogControlEventStateUpdateTimeout);

            UIAUtility.PressButton(_publishCtl);

            UIAUtility.WaitForWindowToDisappearByIdWithTimeout(_parentElement, DialogId, AddinTestUtility.DialogCancelTimeout);
        }
Пример #5
0
        private static bool?Title_Validator(ITestObject to, AutomationElement element)
        {
            string name = UIAUtility.GetName(element);

            if (name != null)
            {
                return(to.Properties[ControlKeys.Title] == element.Current.Name);
            }

            return(null);
        }
Пример #6
0
        private static bool?String_Validator(ITestObject to, AutomationElement element, string key)
        {
            string name = UIAUtility.GetName(element);

            if (name != null)
            {
                return(to.Properties[key] == name);
            }

            return(null);
        }
Пример #7
0
        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);
        }
Пример #8
0
        private static bool?Hyperlink_Validator(ITestObject to, AutomationElement element)
        {
            if (to.ControlTypeString == ControlType.Hyperlink.ControlTypeToString())
            {
                string name = UIAUtility.GetName(element);

                if (!String.IsNullOrEmpty(name))
                {
                    return(to.Properties[ControlKeys.Url] == name);
                }
            }

            return(null);
        }
Пример #9
0
        private MessageBoxDriver(AutomationElement parentElement)
        {
            _parentElement = parentElement;

            _dialog = UIAUtility.FindModalDialogWithTimeout(_parentElement, AddinTestUtility.WebServiceResponsePopulateTimeout);

            _okCtl = UIAUtility.FindElementById(_dialog,
                                                "1");

            _closeIconCtl = UIAUtility.FindElementById(_dialog,
                                                       "Close", TreeScope.Descendants);

            WaitForDialogReady();
        }
Пример #10
0
        public void ControlSearcher_GetTOTest()
        {
            string condition1 = "name := button1";
            string condition2 = "index := 0";

            ITestObject testObject = ControlSearcher.GetTO(null, ControlType.Button, condition1, condition2);

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

            Assert.AreEqual(3, testObject.Properties.Count, UIAUtility.DumpTestObject(testObject));

            Assert.AreEqual("button1", testObject.Properties["name"]);
            Assert.AreEqual("0", testObject.Properties["index"]);
        }
Пример #11
0
        public void CheckWindowHandle(AutomationElement hostae)
        {
            _HostAutoElement = hostae;
            if (_webDriver.WindowHandles.Count == 1)
            {
                return;
            }
            AutomationElement browserWindow = UIAUtility.GetParentElement(hostae);
            string            currentWindow = _webDriver.CurrentWindowHandle;
            string            currTitle     = _webDriver.Title;

            do
            {
                //search the chrome window
                if (browserWindow.Current.ClassName.Equals(_ChromeClassName))
                {
                    //get Title
                    string title = browserWindow.Current.Name;
                    if (title.EndsWith(" - Google Chrome"))
                    {
                        title = title.Remove(title.LastIndexOf(" - Google Chrome"));
                    }
                    //compare the title of browser with the current window handle
                    //if equal, it is the correct current window then return
                    if (title.Equals(_webDriver.Title))
                    {
                        break;
                    }

                    //loop to find out the correct current window
                    foreach (string handle in _webDriver.WindowHandles)
                    {
                        //current window doesn't need to check
                        if (!handle.Equals(currentWindow))
                        {
                            //switch
                            _webDriver.SwitchTo().Window(handle);
                            if (_webDriver.Title.IndexOf(title) >= 0)
                            {
                                return;
                            }
                        }
                    }
                    //not found switch back
                    _webDriver.SwitchTo().Window(currentWindow);
                    break;
                }
            }while(AutomationElement.RootElement != (browserWindow = UIAUtility.GetParentElement(browserWindow)));
        }
Пример #12
0
        private CreateItemDriver(AutomationElement parentElement)
        {
            _parentElement = parentElement;
            _dialog        = UIAUtility.FindElementByIdWithTimeout(_parentElement, DialogId, AddinTestUtility.WebServiceResponsePopulateTimeout);

            _nameCtl = UIAUtility.FindElementById(_dialog,
                                                  "NameTextBox");
            _descCtl = UIAUtility.FindElementById(_dialog,
                                                  "DescTextBox");
            _createCtl = UIAUtility.FindElementById(_dialog,
                                                    "OKButton");
            _cancelCtl = UIAUtility.FindElementById(_dialog,
                                                    "CancelButton");

            WaitForDialogReady();
        }
Пример #13
0
        /// <summary>
        /// Select Insert button to invoke insert item - validate success by ensuring dialog closes
        /// </summary>
        /// <exception cref="ApplicationException">Insert item failed</exception>
        public void SelectInsertVerifySuccess()
        {
            EnsureDialogEventsFired();

            UIAUtility.WaitForElementEnabledWithTimeout(_insertCtl, AddinTestUtility.DialogControlEventStateUpdateTimeout);

            UIAUtility.PressButton(_insertCtl);

            try
            {
                UIAUtility.WaitForWindowToDisappearByIdWithTimeout(_parentElement, DialogId, AddinTestUtility.WebServiceResponsePopulateTimeout);
            }
            catch (TimeoutException)
            {
                throw new ApplicationException("Insert item failed for item '" + GetPropBagValue("selecteditem") + "'");
            }
        }
Пример #14
0
        /*
         * // use this to create condition in Repository, if the AutomationElement exists.
         * public UIACondition(TreeNode treeNode, string nodeName, string leftName = "", string rightName = "")
         * {
         *  AutomationElement element = ((UIACondition)treeNode.Tag).AutomationElement;
         *
         *  if (leftName != "")
         *  {
         *      _left = leftName;
         *  }
         *
         *  if (rightName != "")
         *  {
         *      _right = rightName;
         *  }
         *
         *  UIAUtility.InitProperties(nodeName, element, TestObject);
         *
         *  InitNode(treeNode, element);
         * }*/

        // use this to create condition in Add object window
        public UIACondition(AutomationElement element)
        {
            TestObject = UIAUtility.CreateTestObject(element);

            /* try to avoid using NativeWindowHandle
             * if (_conditionCount == 0)
             * {
             *  try
             *  {
             *      if (element.Current.NativeWindowHandle != 0)
             *      {
             *          _hwnd = (int)element.Current.NativeWindowHandle;
             *          return;
             *      }
             *  }
             *  catch { }
             * }*/
        }
        private EditDetailsDriver(AutomationElement parentElement)
        {
            _parentElement = parentElement;
            _dialog        = UIAUtility.FindElementByIdWithTimeout(_parentElement, DialogId, AddinTestUtility.WebServiceResponsePopulateTimeout);

            _nameCtl = UIAUtility.FindElementById(_dialog,
                                                  "NameTextBox");
            _descCtl = UIAUtility.FindElementById(_dialog,
                                                  "DescTextBox");
            _okCtl = UIAUtility.FindElementById(_dialog,
                                                "OKButton");
            _cancelCtl = UIAUtility.FindElementById(_dialog,
                                                    "CancelButton");
            _closeIconCtl = UIAUtility.FindElementById(_dialog,
                                                       "Close", TreeScope.Descendants);


            WaitForDialogReady();
        }
Пример #16
0
        public void PointToElements(Point point)
        {
            AutomationElementCollection aeCollection = null;
            AutomationElement           menuAe       = null;

            using (_generalCacheReq.Activate())
            {
                _element = AutomationElement.FromPoint(point);
                UIAHighlight.HighlightThread_Spy(_element);

                if (_element.Current.ControlType == ControlType.MenuItem)
                {
                    if (UIAUtility.ExpandMenuItem(_element) && _element.FindFirst(TreeScope.Children, _propertyMenuItemCondition) == null)
                    {
                        menuAe = RetrieveMenuElement(_element);
                    }
                }

                if (menuAe == null)
                {
                    if (_element.FindFirst(TreeScope.Children, Condition.TrueCondition) == null)
                    {
                        _element = TreeWalker.ControlViewWalker.GetParent(_element);
                    }
                    aeCollection = _element.FindAll(TreeScope.Children, Condition.TrueCondition);
                }
                else
                {
                    aeCollection = menuAe.FindAll(TreeScope.Descendants, _menuCondition);
                }
                _ancestorElements.Clear();
                _ancestorElements = UIAUtility.GetAutomationElementsLine(_element);
                _childElements.Clear();
                _childElements = aeCollection.Cast <AutomationElement>().ToList();
            }
            Console.WriteLine("childrenelement count {0}, ancestorelement count {1}", _childElements.Count, _ancestorElements.Count);
            if (null != afterPointToElementsEventHander)
            {
                ElementsBuilderEventArgs e = new ElementsBuilderEventArgs(this, _ancestorElements, _childElements, _element);
                afterPointToElementsEventHander(this, e);
            }
        }
Пример #17
0
        private InsertItemDriver(AutomationElement parentElement)
        {
            _parentElement = parentElement;
            _dialog        = UIAUtility.FindElementByIdWithTimeout(_parentElement, DialogId, AddinTestUtility.WebServiceResponsePopulateTimeout);

            _searchBoxCtl = UIAUtility.FindElementById(_dialog,
                                                       "SearchTextBox", TreeScope.Descendants);
            _itemDataGridCtl = UIAUtility.FindElementById(_dialog,
                                                          "FindListView");
            _allowPublishCheckboxCtl = UIAUtility.FindElementById(_dialog,
                                                                  "AsOutputCheckBox");
            _insertCtl = UIAUtility.FindElementById(_dialog,
                                                    "InsertButton");
            _cancelCtl = UIAUtility.FindElementById(_dialog,
                                                    "CancelButton");
            _closeIconCtl = UIAUtility.FindElementById(_dialog,
                                                       "Close", TreeScope.Descendants);

            WaitForDialogReady();
        }
Пример #18
0
        private ManageItemsDriver(AutomationElement parentElement)
        {
            _parentElement = parentElement;
            _dialog        = UIAUtility.FindElementByIdWithTimeout(_parentElement, DialogId, AddinTestUtility.WebServiceResponsePopulateTimeout);

            _itemDataGridCtl = UIAUtility.FindElementById(_dialog,
                                                          "ItemListView");

            _refreshCtl = UIAUtility.FindElementById(_dialog,
                                                     "RefreshButton");
            _editCtl = UIAUtility.FindElementById(_dialog,
                                                  "EditButton");
            _unlinkCtl = UIAUtility.FindElementById(_dialog,
                                                    "UnlinkButton");
            _closeCtl = UIAUtility.FindElementById(_dialog,
                                                   "CloseButton");
            _closeIconCtl = UIAUtility.FindElementById(_dialog,
                                                       "Close", TreeScope.Descendants);

            WaitForDialogReady();
        }
Пример #19
0
        private void ConstructLeftAndRightNode(TreeView objectTree, AutomationElement clickedElement)
        {
            TreeNode parentNode = null, leafNode;

            leafNode = objectTree.Nodes[0];

            while (leafNode.Nodes.Count > 0)
            {
                parentNode = leafNode;
                leafNode   = leafNode.Nodes[0];
            }

            AutomationElement leftElement  = UIAUtility.GetPreviousElement(clickedElement);
            AutomationElement rightElement = UIAUtility.GetNextElement(clickedElement);

            TreeNode tempNode = null;

            if (parentNode == null)
            {
                return;
            }

            //TreeNodeCollection nodes = (parentNode == null) ? objectTree.Nodes : parentNode.Nodes;
            if (leftElement != null)
            {
                _leftElement = new ElementProperties(leftElement);
                tempNode     = parentNode.Nodes.Insert(0, "left", StringResources.LPSpy_AddObjectsWindow_LeftObject + _leftElement.DerivedName);
                _leftElement.SetContext(tempNode);
                tempNode.Tag = new ElementProperties(leftElement);
            }

            if (rightElement != null)
            {
                _rightElement = new ElementProperties(rightElement);
                tempNode      = parentNode.Nodes.Add("right", StringResources.LPSpy_AddObjectsWindow_RightObject + _rightElement.DerivedName);
                _rightElement.SetContext(tempNode);
                tempNode.Tag = new ElementProperties(rightElement);
            }
        }
Пример #20
0
        private void ConstructElementsTree(AutomationElement clickedElement)
        {
            this.objectTree.Nodes.Clear();

            if (clickedElement == null)
            {
                return;
            }

            UIAHighlight.HighlightThread_Spy(clickedElement);

            List <AutomationElement> elements = UIAUtility.GetAutomationElementsLine(clickedElement);

            TreeNodesFromAutomationElements(elements);

            if (_modeType == AddObjWndModeType.Normal)
            {
                ConstructLeftAndRightNode(objectTree, clickedElement);
            }

            this.objectTree.ExpandAll();
        }