/// <summary> /// Checks for an open error window and closes it. /// This may close the application. /// Also, set doAssert to true if this test should terminate on finding one. /// </summary> /// <param name="doAssert">false when the test should not fail as when another test caused the error window.</param> protected void CheckForErrorDialogs(bool doAssert) { // check for specific error dialogs // Try to get the ah for "An error has occurred" window // Log its info // Close the error window // Assert if directed to AccessibilityHelper ah = new AccessibilityHelper("An error has occurred"); // This constructor returns the top window if it can't find the // one with the title // Even though the ah is not null, sometimes it can't get the name string name = ""; if (ah != null && ah.Name == "An error has occurred") { // this is really bad! string color = "green"; m_log.paragraph("Window: " + name); GuiPath path = new GuiPath("button:Exit the application"); AccessibilityHelper ahExit = ah.SearchPath(path, null); if (ahExit == null) { color = "yellow"; // can continue path = new GuiPath("button:Ok"); ahExit = ah.SearchPath(path, null); } if (ahExit == null) color = "unknown"; if (color == "green") m_log.paragraph("Found a green error window!"); if (color == "yellow") m_log.paragraph("Found a yellow error window! Continuing..."); if (color == "unknown") m_log.paragraph("Found an unknown error window!"); // write the error text to the log path = new GuiPath("window:NAMELESS[2]"); AccessibilityHelper ahTextWin = ah.SearchPath(path, null); AccessibilityHelper ahText = null; if (ahTextWin != null) { path = new GuiPath("text:NAMELESS[2]"); ahText = ah.SearchPath(path, null); } if (ahText != null) m_log.paragraph(ahText.Value); else m_log.paragraph(@"Don't know where to get the message text from."); if (color == "green" || color == "yellow") ahExit.SimulateClickRelative(10,10); if (doAssert && color == "green") m_log.fail("Got an error window!"); if (color == "unknown" && Application != null) Application.SendKeys(@"{ESC}"); // exits error window but maybe not the app if (doAssert && color == "unknown") m_log.fail("Closed the unknown error window."); Thread.Sleep(20000); // if still alive, wait for things to calm down } }
// when all the instructions pass, do-once passes // otherwise it fails public override void Execute() { // Don't call the base execute method! - want control.. // base.Execute(); if (Number == -1) Number = TestState.getOnly().IncInstructionCount; m_log.mark(this); m_ExecuteTickCount = System.Environment.TickCount; PrepareChildren(); // base method to build child instructions // remove all wait times in this context, but only at the child level this.RemoveWaitTime(); foreach (Instruction ins in m_components) { ins.RemoveWaitTime(); } PassFailInContext(OnPass, OnFail, out m_onPass, out m_onFail); AccessibilityHelper m_ah = Accessibility; if (1 == m_logLevel) m_log.paragraph("Context is "" + m_ah.Role + ":" + m_ah.Name + """); if (m_waitingFor != null && m_waitingFor != "") m_waitingFor = Utilities.evalExpr(m_waitingFor); int startTick = System.Environment.TickCount; m_log.paragraph(image()); bool done = false; bool lastPass = false; // used to allow 1 last pass over instructions after time is up while (!done) { CheckForErrorDialogs(true); // see if there are any cmds not finished done = true; // start as if they're all done foreach (Instruction ins in m_components) { if (!ins.Finished) // not already finished { // Don't assert onFail until it's the last pass (time is up) ins.DeferAssert = !lastPass; ins.Execute(); if (!ins.Finished) // still not finished done = false; } } m_Result = done; AccessibilityHelper ah = null; string title = null; if (m_waitingFor != null && m_waitingFor != "") { m_Result = false; // fail if the window is not found IntPtr foundHwndPtr = FindWindow(null,m_waitingFor); if ((int)foundHwndPtr != 0) { ah = new AccessibilityHelper(foundHwndPtr); // The ah constructor gets the topWindow if our window isn't found // Don't want that // ah = new AccessibilityHelper(m_waitingFor); // get the title, the ah.Name can be different. GuiPath path = new GuiPath("titlebar:NAMELESS"); AccessibilityHelper ah1 = ah.SearchPath(path, null); if (ah1 != null) title = ah1.Value; } } if (ah != null) m_log.paragraph("do-once found window:"+ah.Name); if (title != null) m_log.paragraph("do-once found title:"+title); if (lastPass) done = true; if (title != null && title == m_waitingFor) { lastPass = true; // A window may appear a bit later m_Result = true; } // once time is up, allow finial pass over instructions allowing asserts as needed if (!lastPass) lastPass = Utilities.NumTicks(startTick, System.Environment.TickCount) > m_waitTicks; } // end of while loop Logger.getOnly().result(this); Finished = true; // tell do-once it's done if (m_onPass == "assert" && m_Result == true) fail("do-once accomplished its task(s) but was not supposed to."); if (m_onFail == "assert" && m_Result == false) fail("do-once did not accomplish all of its tasks."); }
/// <summary> /// ValueOrChild determines if the ah's value should be macthed or /// if a child should be matched. /// </summary> /// <param name="nextGP">The next path step beyond this ah</param> /// <param name="ah">The accessibility object currently considered</param> /// <param name="visitor">null or the object providing methods that are called when steps are found.</param> /// <returns>An AccessibilityHelper if checking for a value, otherwise null</returns> public AccessibilityHelper ValueOrChild(GuiPath nextGP, AccessibilityHelper ah, IPathVisitor visitor) { bool result = false; if (nextGP.Role == AccessibleRole.Alert) { // check if the name is a regular expression if (nextGP.Name != null && nextGP.Name.StartsWith("rexp#")) { Regex rx = new Regex(nextGP.Name.Substring(5)); result = rx.IsMatch(ah.Value); Logger.getOnly().paragraph("Path name reg exp " + nextGP.Name.Substring(5) + " on " + ah.Value + " was " + result.ToString()); } else result = nextGP.Name == ah.Value; // match the value to the next path's name if (!result) { // it didn't match, so the search failed if (visitor != null) visitor.notFound(nextGP); return null; } } if (result) return ah; return ah.SearchPath(nextGP, visitor); // continue on the path }