public override void Execute(TestState ts) { AppHandle app = Application; app.Exit(false); Assertion.AssertNull("Non-null process", app.Process); }
/// <summary> /// Execute the context instructions /// </summary> public override void Execute() { Wait(); m_Rest = 0; // don't wait later when base.Execute is invoked string failed = null; m_path = Utilities.evalExpr(m_path); m_exeName = Utilities.evalExpr(m_exeName); m_title = Utilities.evalExpr(m_title); if (m_args != null) { m_args = Utilities.evalExpr(m_args); } if (m_work != null) { m_work = Utilities.evalExpr(m_work); } string fullPath = m_path + @"\" + m_exeName; // Read and load the top-level variables from the model // as child instructions of this context. // Some may replace previously defined vars. ReadModelVars(); // make "shells" for the child instructions. // start-up is needed when the app is launched. base.PrepareChildren(true); // add more children bool found = false; if ("top" == m_run) { // get the top window as the application context m_ah = new AccessibilityHelper(); isNotNull(m_ah, "Top window is not accessible"); Process proc = Process.GetCurrentProcess(); isNotNull(proc, "Top window is not the current process"); m_title = proc.MainWindowTitle; m_app = new AppHandle(null, proc, m_ah); isNotNull(m_app, "Lost top window application handle for window with title" + m_title); found = true; } // Is the app running already? if (found == false) { found = FindApp(1000); } string contextPass, contextFail; PassFailInContext(OnPass, OnFail, out contextPass, out contextFail); // out m_onPass, out m_onFail); if ("no" == m_run && !found) { if (m_title != null) { failed = "Application '" + m_title + "' not found."; } else if (m_exeName != null) { failed = "Application '" + m_exeName + "' not found."; } else { failed = "Application not found."; } } if ("yes" == m_run && found) { m_app.Exit(false); // close all app windows m_app = null; found = false; } if (!found && failed == null && "no" != m_run) { if (!LaunchApp()) { failed = "Application '" + fullPath + "' not launched."; } } if (contextFail == "assert" && failed != null && failed != "") { fail(failed); } if (contextPass == "assert" && failed == null) { fail("run='" + m_run + "' exe='" + m_exeName + "' passed"); } if (failed != null && failed != "") { // OK to fail, but should note it m_log.paragraph(failed); } else { base.Execute(); if (m_close) { m_app.Exit(false); // close all app windows } m_finished = true; resultImage(); } // return focus back to the previous application if there was one AppHandle aph = base.Application; if (aph != null) { isNotNull(aph.Process, "Parent application lost its process"); aph.Process.WaitForInputIdle(); Win32.SetForegroundWindow(aph.Process.MainWindowHandle); } }