示例#1
0
        /// -------------------------------------------------------------------
        /// <summary>
        /// This will test that the menu and it's menu names are as defined in the Xml tree
        /// </summary>
        /// -------------------------------------------------------------------
        private void TS_VerifyXmlToTree(XmlNode xmlNode, TestMenu menu)
        {
            // If they are both null, we are at the end...just return then
            if (xmlNode == null && menu == null)
            {
                return;
            }

            // Make sure both are either null, or something
            if ((xmlNode == null && menu != null) || (xmlNode != null && menu == null))
            {
                ThrowMe(CheckType.Verification, "Mismatch1!");
            }

            string curName = menu.AutomationElement.GetCurrentPropertyValue(AutomationElement.NameProperty) as string;
            string expName = new StringBuilder(xmlNode.Name).Replace("_", " ").ToString();

            // Verify that the NameProperty returned something valid
            if (String.IsNullOrEmpty(curName))
            {
                ThrowMe(CheckType.Verification, "AutomationElement.NameProperty is empty or null");
            }

            // Everything looks good, so tell the user what we are doing
            Comment("Comparing expected name(" + expName + ") with actual name(" + curName + ")");

            if (expName != curName)
            {
                ThrowMe(CheckType.Verification, "Expected element with name of " + expName + ", yet it was " + curName);
            }

            // MenuItems need to be expanded to get to the children.  Menu's don't since they are only containers that are
            // already opened.
            if (menu.Expandable)
            {
                menu.Expand();
            }

            // Recurse the children and siblings
            if (xmlNode.FirstChild != null)
            {
                TS_VerifyXmlToTree(xmlNode.FirstChild, menu.GetFirstSubMenu());
            }

            if (xmlNode.NextSibling != null)
            {
                TS_VerifyXmlToTree(xmlNode.NextSibling, menu.GetNextSiblingMenu());
            }
        }