public void FindChild()
        {
            // Not enough accessibility to get to the menu reliably - too many NAMELESS

            /*AccessibilityHelper child = m_ah.FindChild("~MainMenu~", AccessibleRole.Window);
             * Assert.IsNotNull(child,"null child");
             * Assert.AreEqual("~MainMenu~", child.Name);
             * Assert.AreEqual(AccessibleRole.Window, child.Role);
             *
             * child = child.FindChild("mnuFormat", AccessibleRole.MenuItem);
             * Assert.IsNotNull(child,"null child");
             * Assert.AreEqual("mnuFormat", child.Name);
             * Assert.AreEqual(AccessibleRole.MenuItem, child.Role);*/

            AccessibilityHelper child = m_ah.FindChild(null, AccessibleRole.Client);

            Assert.IsNotNull(child, "null child");
            Assert.AreEqual("Kalaba (TestLangProj) - Translation Editor", child.Name);
            Assert.AreEqual(AccessibleRole.Client, child.Role);

            child = m_ah.FindChild("System", AccessibleRole.MenuBar);
            Assert.IsNotNull(child, "null child");
            Assert.AreEqual("System", child.Name);
            Assert.AreEqual(AccessibleRole.MenuBar, child.Role);

            child = m_ah.FindChild("NotExistantChild", AccessibleRole.None);
            Assert.IsNull(child, "non-null child");

            child = m_ah.FindChild(null, AccessibleRole.None);
            Assert.IsNull(child, "non-null child");
        }
Пример #2
0
        public void OverviewPage()
        {
            Assert.IsNotNull(m_dialog, "Didn't get an Import dialog");

            AccessibilityHelper overviewWnd = m_dialog.FindChild("Overview",
                                                                 AccessibleRole.Window);

            // make sure the step that contains the overview is visible
            AccessibilityHelper step = overviewWnd.Parent;

            Assert.IsTrue((step.States & AccessibleStates.Invisible) != AccessibleStates.Invisible,
                          "Overview step is not visible");

            // make sure it displays the language project name
            bool fFoundLangProjName = false;

            foreach (AccessibilityHelper child in step)
            {
                if ((child.States & AccessibleStates.Invisible) == AccessibleStates.Invisible)
                {
                    continue;
                }

                if (child.Value.IndexOf("DEB-Debug") > -1)
                {
                    fFoundLangProjName = true;
                }
            }

            Assert.IsTrue(fFoundLangProjName, "Can't see Language Project name on dialog");

            // make sure there are no other controls in the step except text boxes
            AccessibleRole[] roles =
                new AccessibleRole[] { AccessibleRole.Text,
                                       AccessibleRole.Client, AccessibleRole.Window,
                                       AccessibleRole.StaticText };
            Array.Sort(roles);

            Assert.IsTrue(CheckControls(step, roles), "Overview page contains unexpected controls");
        }
Пример #3
0
        public void OpenUsesLastClosedSettings()
        {
            m_app.GoToDraftView();
            m_app.SendKeys("{PGDN}");
            m_app.SendKeys("{PGDN}");
            m_app.SendKeys("{PGDN}");
            m_app.SendKeys("{PGDN}");

            string firstWindowInfo = m_app.InfoBarValue;

            // now open duplicate window
            m_app.SendKeys("%WN");             // Window/New Window

            // go to a different section, than a different view
            m_app.SendKeys("^{HOME}");
            m_app.GoToConcordanceView();

            // switch to first window
            m_app.SendKeys("%{TAB}");

            AccessibilityHelper parent = m_app.MainAccessibilityHelper.Parent;
            int nWhich = 2;
            AccessibilityHelper secondWindow = parent.FindNthChild("Translation Editor",
                                                                   AccessibleRole.None, ref nWhich, 0);
            AccessibilityHelper infoBar =
                secondWindow.FindChild("InfoBarLabel", AccessibleRole.None);

            string secondWindowInfo = infoBar.Value;

            // close first window
            m_app.SendKeys("%{F4}");

            // then close second window
            m_app.Exit(true);

            m_app.Start();

            // Now compare view
            Assert.AreEqual(secondWindowInfo, m_app.InfoBarValue);
        }
Пример #4
0
        private AccessibilityHelper findFromPath(AccessibilityHelper ancestor, string path)
        {
            // break the path into typed tokens of the form type:name[#]
            AccessibilityHelper ah          = ancestor;
            ArrayList           typedTokens = SplitPath(path);

            foreach (string typedToken in typedTokens)
            {
                string name, type;
                int    duplicate;
                SplitTypedToken(typedToken, out name, out type, out duplicate);
                AccessibleRole role = TypeToRole(type);
                if (duplicate == 1)
                {
                    ah = ah.FindChild(name, role);
                }
                else
                {
                    ah = ah.FindNthChild(name, role, duplicate, 10);
                }
            }
            return(ah);
        }
Пример #5
0
        // look for the expected dialog to appear. If it does, make an accessibilty
        // helper for it.
        public override void Execute()
        {
            // base.Execute(ts); // can't call this yet as it executes the children
            Wait();             // do call this but make sure Rest is reset to zero!
            Rest = 0;           // reset to zero so there is no delay after the dialog is found.
            // number is needed in diagnostics for the log
            if (Number == -1)
            {
                Number = TestState.getOnly().IncInstructionCount;
            }

            Process proc = Application.Process;

            /// If present, use the selected dialog model title
            Context con = (Context)Ancestor(typeof(Context));

            if (m_select != null && m_select != "")
            {              // make a new model context node and move dialog's children to it
                XmlDocument doc    = m_elt.OwnerDocument;
                XmlElement  modElt = doc.CreateElement("model");
                modElt.SetAttribute("select", m_select);
                XmlNodeList children = m_elt.ChildNodes;
                int         count    = children.Count;
                while (count > 0)
                {                                     // move dialog children to model
                    XmlNode child = children.Item(0); //get the first child
                    modElt.AppendChild(child);        // automatically removed from m_elt!!
                    count = children.Count;
                }
                m_elt.AppendChild(modElt);
                // set the title to look for
                // can only have one text node
                XmlNodeList pathNodes = XmlInstructionBuilder.selectNodes(this, m_select, makeName());
                m_log.isNotNull(pathNodes, "dialog " + this.Id + " select='" + m_select + "' returned no model");
                m_log.isTrue(pathNodes.Count > 0, "dialog " + this.Id + " select='" + m_select + "' returned no model nodes");
                // This is the model node
                XmlNode modNode = pathNodes.Item(0);
                m_title  = XmlFiler.getAttribute(modNode, "title");
                m_name   = XmlFiler.getAttribute(modNode, "name");
                m_select = null;                 // can only do this one time in do-once or model
            }
            if (m_title != null && m_title != "")
            {
                m_title = Utilities.evalExpr(m_title);
            }
            if (m_name != null && m_name != "")
            {
                m_name = Utilities.evalExpr(m_name);
            }

            m_log.paragraph(image());

            // Give the window m_Rest seconds to show up
            int    startTick = System.Environment.TickCount;
            IntPtr foundHwndPtr;
            string name = null;

            while (!m_found)
            {               // If there is a regular expression, try it.
                if (m_title != null && m_title.StartsWith("rexp#"))
                {           // match the window title via the regular expression
                    Process[] allProcs = Process.GetProcesses();
                    Regex     rx       = null;
                    try { rx = new Regex(m_title.Substring(5)); }
                    catch (ArgumentException e)
                    {
                        m_log.paragraph("on-dialog title from rexp# " + m_title.Substring(5)
                                        + " error: " + e.Message);
                        break;
                    }
                    for (int p = 0; p < allProcs.Length; p++)
                    {
                        Process             pro = allProcs[p];
                        AccessibilityHelper ah  = new AccessibilityHelper(pro.Handle);
                        if (rx.IsMatch(ah.Name))
                        {
                            m_ah    = ah;
                            m_found = true;
                            break;
                        }
                    }
                }
                else
                {                   // get the window handle for windows with the right name
                    // unfortuneately, other windows, or partially formed windows
                    // seem to be obtained too.
                    foundHwndPtr = FindWindow(null, m_title);
                    if ((int)foundHwndPtr != 0)
                    {                       // is this the window? Is it completely formed?
                        m_ah = new AccessibilityHelper(foundHwndPtr);
                        if (m_ah == null)
                        {
                            m_log.paragraph("Obtained window with no Accessibiilty!");
                        }
                        else                        // this window has accessibility - hope it's fully built
                        {                           // is this or one of its children the window?
                            name = m_ah.Name;       //when name1 = "", m_ah is probably bad - i.e. not an object
                            if (name == "")
                            {
                            }                               // do nothing, keep looking
                            else if (name.Equals(m_title) || name.Equals(this.m_name))
                            {                               // this is likely it
                                m_found = true;
                            }
                            else                            // m_ah might be the ah for the main app or dialog window
                            {                               // Maybe one of its children is the window we want
                                m_ah = m_ah.FindChild(m_title, AccessibleRole.Dialog);
                                if (m_ah != null)
                                {                                 // is this the window?
                                    name = m_ah.Name;             // name1 can't be null
                                    if (name == "")
                                    {
                                    }                                       // do nothing, keep looking
                                    else if (name.Equals(m_title) || name.Equals(this.m_name))
                                    {                                       // this might be it
                                        m_found = true;
                                    }
                                }
                            }
                        }
                    }
                }

                if (Utilities.NumTicks(startTick, System.Environment.TickCount) > m_until)
                {
                    break;                      // time is up
                }
                System.Threading.Thread.Sleep(100);
            }

            m_Rest = 0;             // don't wait later when base.Execute is invoked

            if (m_found)
            {
                m_DlgHwndStack.Push(m_ah.HWnd);
            }
            else
            {               // Didn't find the window
                m_ah = null;
            }

            string contextPass, contextFail;

            PassFailInContext(OnPass, OnFail, out contextPass, out contextFail);                //  out m_onPass, out m_onFail);
            m_log.paragraph("on-dialog: passIn=" + OnPass + " failIn=" + OnFail + " pass="******" fail=" + contextFail);
            if (!m_found && contextFail == "skip")
            {
                return;                 // quietly exit
            }
            isTrue(m_found, "Dialog '" + m_title + @"' was not created or not accessible");
            if (name == null)
            {
                m_log.paragraph("Wierd: ah exists but name was null - should NEVER happen!!");
                name = "";
            }
            if (contextPass == "assert")
            {
                fail("Dialog '" + m_title + "' was not supposed to display.");
            }

            base.Execute();
            m_log.result(this);
            base.Finished = true;               // finished processing this dialog context
            m_DlgHwndStack.Pop();

            if (m_DlgHwndStack.Count > 0)
            {
                int hwnd = (int)m_DlgHwndStack.Peek();
                SIL.FieldWorks.Common.Utils.Win32.SendMessage((IntPtr)hwnd,
                                                              (int)SIL.FieldWorks.Common.Utils.Win32.WinMsgs.WM_SETFOCUS, 0, 0);
                m_log.paragraph("Sent Focus message to containing context object");
                //	m_ah.Parent.SendWindowMessage((int)SIL.FieldWorks.Common.Utils.Win32.WinMsgs.WM_SETFOCUS,0,0);
            }
        }
Пример #6
0
        // look for the expected dialog to appear. If it does, make an accessibilty
        // helper for it.
        public override void Execute()
        {
            // base.Execute(ts); // can't call this yet as it executes the children
            WaitMsec();           // do call this but make sure Wait is reset to zero!
            Wait = 0;             // reset to zero so there is no delay after the dialog is found.
            // number is needed in diagnostics for the log
            if (Number == -1)
            {
                Number = TestState.getOnly().IncInstructionCount;
            }

            /// If present, use the selected dialog model title
            Context con = (Context)Ancestor(typeof(Context));

            if (m_select != null && m_select != "")
            {              // make a new model context node and move dialog's children to it
                m_select = Utilities.evalExpr(m_select);
                XmlDocument doc    = m_elt.OwnerDocument;
                XmlElement  modElt = doc.CreateElement("model");
                modElt.SetAttribute("select", m_select);
                XmlNodeList children = m_elt.ChildNodes;
                int         count    = children.Count;
                while (count > 0)
                {                                     // move dialog children to model
                    XmlNode child = children.Item(0); //get the first child
                    modElt.AppendChild(child);        // automatically removed from m_elt!!
                    count = children.Count;
                }
                m_elt.AppendChild(modElt);
                // set the title to look for
                // can only have one text node
                XmlNodeList pathNodes = Instructionator.selectNodes(this, m_select, makeName());
                m_log.isNotNull(pathNodes, makeNameTag() + " select='" + m_select + "' returned no model");
                m_log.isTrue(pathNodes.Count > 0, makeNameTag() + " select='" + m_select + "' returned no model nodes");
                // This is the model node
                XmlNode modNode = pathNodes.Item(0);
                if (m_title == null || m_title == "")
                {                  // no title override, so set the title from the model
                    string titleCheck = XmlFiler.getAttribute(modNode, "title");
                    if (titleCheck != null)
                    {
                        m_title = titleCheck;
                        m_log.paragraph("on-dialog title set from selected model " + titleCheck);
                    }
                }
                else
                {
                    m_log.paragraph("on-dialog title set from @title " + m_title);
                }
                string nameCheck = XmlFiler.getAttribute(modNode, "name");
                if (nameCheck != null)
                {
                    m_name = nameCheck;
                    m_log.paragraph("on-dialog name set from selected model " + nameCheck);
                }
                m_select = null;                 // can only do this one time in do-once or model
            }
            // if no name, try title
            if (m_title != null && m_title != "" && (m_name == null || m_name == ""))
            {
                m_name = m_title;
            }

            m_log.isNotNull(m_title, makeNameTag() + " No @title in script or model for this dialog.");
            m_log.isFalse(m_title == "", makeNameTag() + " @title in script or model is blank.");
            m_log.isFalse(m_name == null && !m_title.StartsWith("rexp#"), makeNameTag() + " No @name step in script or model for this dialog.");
            m_log.isFalse(m_name == "" && !m_title.StartsWith("rexp#"), makeNameTag() + " @name step in script or model is blank.");
            //if (m_title != null && m_title != "") m_title = Utilities.evalExpr(m_title);
            //if (m_name != null && m_name != "") m_name = Utilities.evalExpr(m_name);
            m_title = Utilities.evalExpr(m_title);
            m_name  = Utilities.evalExpr(m_name);

            m_log.paragraph(image());

            if (Application != null)
            {
                try { Application.Process.WaitForInputIdle(); }
                catch (Win32Exception e)
                { m_log.paragraph(makeNameTag() + " WaitForInputIdle: " + e.Message); }
            }
            // Give the window m_Rest seconds to show up
            int    startTick = System.Environment.TickCount;
            IntPtr foundHwndPtr;
            string name = null;
            Regex  rx   = null;

            if (m_title != null && m_title.StartsWith("rexp#"))
            {               // Create a regular expression object
                try { rx = new Regex(m_title.Substring(5)); }
                catch (ArgumentException e)
                {
                    m_log.fail(makeNameTag() + " title from rexp# [" + m_title.Substring(5)
                               + "] error: " + e.Message);
                }
            }

            while (!m_found)
            {               // If there is a regular expression, try it.
                if (rx != null)
                {           // try the main window name then other windows it may own via the regular expression
                    m_log.paragraph("Searching all processes");
                    Process[] allProcs = Process.GetProcesses();
                    for (int p = 0; p < allProcs.Length; p++)
                    {
                        Process pro = allProcs[p];
                        try {
                            if (rx.IsMatch(pro.MainWindowTitle))
                            {
                                m_found = true;
                                m_ah    = new AccessibilityHelper(pro.Handle);
                                break;
                            }
                        }
                        catch (Exception e) {
                            m_log.paragraph(makeNameTag() + " main title from rexp# [" + m_title.Substring(5)
                                            + "] process error: " + e.Message);
                        }
                        #region Attempt to explore process threads - useful?
                        // try the windows that belong to this process

                        /*try {
                         *      foreach (ProcessThread pt in pro.Threads)
                         *      {
                         *
                         *              string para = "on-dialog matching proc [" + pro.ProcessName + ":";
                         *              if (pt.Site != null) para += pt.Site.Name + "]";
                         *              else                 para += "]";
                         *              m_log.paragraph(para);
                         *              if (pt.Site != null && rx.IsMatch(pt.Site.Name)) {
                         *                      m_found = true;
                         *                      m_ah = new AccessibilityHelper(pro.Handle);
                         *                      break;
                         *              }
                         *      }
                         * }
                         * catch (Exception e)
                         * {
                         *      m_log.paragraph("on-dialog title from rexp# [" + m_title.Substring(5)
                         + "] process error: " + e.Message);
                         + } */
                        #endregion
                    }
                }
                if (!m_found)
                {                   // get the window handle for windows with the right name
                    // unfortuneately, other windows, or partially formed windows
                    // seem to be obtained too.
                    m_log.paragraph("Searching the desktop for a window via FindWindow");
                    if (rx != null)
                    {
                        foundHwndPtr = FindWindow(null, null);
                    }
                    else
                    {
                        foundHwndPtr = FindWindow(null, m_title);
                    }
                    if ((int)foundHwndPtr != 0)
                    {                       // is this the window? Is it completely formed?
                        m_ah = new AccessibilityHelper(foundHwndPtr);
                        if (m_ah == null)
                        {
                            m_log.paragraph(makeNameTag() + " Obtained window with no Accessibiilty!");
                        }
                        else                        // this window has accessibility - hope it's fully built
                        {                           // is this or one of its children the window?
                            name = m_ah.Name;       //when name1 = "", m_ah is probably bad - i.e. not an object
                            if (name == "")
                            {
                            }                               // do nothing, keep looking
                            else if (name.Equals(m_title) || name.Equals(this.m_name))
                            {                               // this is likely it
                                m_found = true;
                            }
                            else                            // m_ah might be the ah for the main app or dialog window
                            {                               // Maybe one of its children is the window we want
                                m_log.paragraph("Searching for a child window");
                                m_ah = m_ah.FindChild(m_title, AccessibleRole.Dialog);
                                if (m_ah != null)
                                {                                 // is this the window?
                                    name = m_ah.Name;             // name1 can't be null
                                    if (name == "")
                                    {
                                    }                                       // do nothing, keep looking
                                    else if (name.Equals(m_title) || name.Equals(this.m_name))
                                    {                                       // this might be it
                                        m_found = true;
                                    }
                                }
                            }
                        }
                    }
                }

                if (Utilities.NumTicks(startTick, System.Environment.TickCount) > m_until)
                {
                    break;                      // time is up
                }
                System.Threading.Thread.Sleep(100);
            }

            m_Rest = 0;             // don't wait later when base.Execute is invoked

            if (m_found)
            {
                m_DlgHwndStack.Push(m_ah.HWnd);
            }
            else
            {               // Didn't find the window
                m_ah = null;
            }

            string contextPass, contextFail;
            PassFailInContext(OnPass, OnFail, out contextPass, out contextFail);                //  out m_onPass, out m_onFail);
            m_log.paragraph(makeNameTag() + " passIn=" + OnPass + " failIn=" + OnFail + " pass="******" fail=" + contextFail);
            if (!m_found && contextFail == "skip")
            {
                return;                 // quietly exit
            }
            m_log.isTrue(m_found, makeNameTag() + m_title + @"' was not created or not accessible");
            if (name == null)
            {
                m_log.paragraph(makeNameTag() + " Wierd: ah exists but name was null - should NEVER happen!!");
                name = "";
            }
            if (contextPass == "assert")
            {
                m_log.fail(makeNameTag() + m_title + " was not supposed to display.");
            }

            base.Execute();
            m_log.result(this);
            base.Finished = true;               // finished processing this dialog context
            m_DlgHwndStack.Pop();

            if (m_DlgHwndStack.Count > 0)
            {
                int hwnd = (int)m_DlgHwndStack.Peek();
                SendMessage((IntPtr)hwnd,
                            (int)Msg.WM_SETFOCUS, 0, 0);
                m_log.paragraph(makeNameTag() + " Sent Focus message to containing context object");
                //	m_ah.Parent.SendWindowMessage((int)SIL.FieldWorks.Common.Utils.Win32.WinMsgs.WM_SETFOCUS,0,0);
            }
        }