// Tests classes call this from their ClassInitialize methods to init our Application instance
        // and launching the application if necessary.
        public static void Initialize(TestContext testContext, TestApplicationInfo testAppInfo)
        {
            TestContext = testContext;

            IsLogVerbose      = TestContext.Properties.Contains("LogVerbose");
            IsLogSuperVerbose = TestContext.Properties.Contains("LogSuperVerbose");

            if (TestContext.Properties.Contains("WaitForDebugger"))
            {
                var processId = Process.GetCurrentProcess().Id;
                while (!Debugger.IsAttached)
                {
                    Log.Comment(string.Format("Waiting for a debugger to attach (processId = {0})...", processId));
                    Thread.Sleep(1000);
                }

                Debugger.Break();
            }

            Application = CreateApplication(testAppInfo);

            // Initialize relies on TestEnvironment.Application to be set, so we'll call this method
            // outside of the constructor.
#if USING_TAEF
            Application.Initialize(true, TestContext.TestDeploymentDir);
#else
            Application.Initialize(true);
#endif
        }
Esempio n. 2
0
 private static Application CreateApplication(TestApplicationInfo info)
 {
     return(new Application(
                info.TestAppPackageName,
                info.TestAppPackageFamilyName,
                info.TestAppName,
                info.TestAppMainWindowTitle,
                info.ProcessName,
                info.InstallerName,
                info.CertSerialNumber,
                info.BaseAppxDir));
 }
        public static void AssemblyCleanupWorker(TestApplicationInfo testAppInfo)
        {
            // This executed in a different context from the tests, so it doesn't have a reference
            // to Application object created by them, so just create a local one (configured to not launch the
            // app) so that we can close it.
            var app = CreateApplication(testAppInfo);

            app.Close();

            Log.Comment("Killing processes we might have inadvertently started...");
            var killList = new string[] { "microsoft.photos", "HxAccounts", "HxCalendarAppImm", "HxOutlook", "HxTsr" };

            foreach (var process in Process.GetProcesses().Where(p => killList.Contains(p.ProcessName.ToLower())))
            {
                Log.Comment("Killing process '{0}' ({1}).", process.ProcessName, process.Id);
                process.Kill();
                process.WaitForExit();
            }
        }