public void LaunchFileInBrowser(string file, string browserName = null, IDictionary <string, string> browserArgs = null) { file = FileProbe.GenerateFileUrl(file); var browserAppPath = BrowserPathHelper.GetBrowserPath(browserName); var startInfo = new ProcessStartInfo(); if (!string.IsNullOrEmpty(browserAppPath)) { startInfo.UseShellExecute = true; startInfo.FileName = browserAppPath; startInfo.Arguments = GetArguments(browserName ?? Path.GetFileNameWithoutExtension(browserAppPath), file, browserArgs); } else { startInfo.UseShellExecute = true; startInfo.Verb = "Open"; startInfo.FileName = file; } Process.Start(startInfo); }
public void LaunchTest(TestContext testContext) { var file = testContext.TestHarnessPath; file = urlBuilder.GenerateFileUrl(testContext, file, fullyQualified: true); // Start IE. ProcessStartInfo startInfo = new ProcessStartInfo() { UseShellExecute = true, FileName = BrowserPathHelper.GetBrowserPath("ie"), Arguments = string.Format("-noframemerging -suspended -debug {0}", file) // -noframemerging // This is what VS does when launching the script debugger. // Unsure whether strictly necessary. // -suspended // This is what VS does when launching the script debugger. // Seems to cause IE to suspend all threads which is what we want. // -debug // This is what VS does when launching the script debugger. // Not sure exactly what it does. }; Process ieMainProcess = Process.Start(startInfo); // Get child 'tab' process spawned by IE. // We need to wait a few ms for IE to open the process. Process ieTabProcess = null; for (int i = 0;; ++i) { System.Threading.Thread.Sleep(10); ieTabProcess = ProcessExtensions.FindFirstChildProcessOf(ieMainProcess.Id); if (ieTabProcess != null) { break; } if (i > 400) // 400 * 10 = 4s timeout { throw new InvalidOperationException("Timeout waiting for Internet Explorer child process to start."); } } // Debug the script in that tab process. DteHelpers.DebugAttachToProcess(ieTabProcess.Id, "script"); // Resume the threads in the IE process which where started off suspended. ieTabProcess.Resume(); }
public void LaunchFileInBrowser(string file, string browserName = null) { file = FileProbe.GenerateFileUrl(file); var browserAppPath = BrowserPathHelper.GetBrowserPath(browserName); var startInfo = new ProcessStartInfo(); if (!string.IsNullOrEmpty(browserAppPath)) { startInfo.UseShellExecute = true; startInfo.FileName = browserAppPath; startInfo.Arguments = file; } else { startInfo.UseShellExecute = true; startInfo.Verb = "Open"; startInfo.FileName = file; } Process.Start(startInfo); }
private void ExecuteTestContexts( TestOptions options, TestExecutionMode testExecutionMode, ITestMethodRunnerCallback callback, ConcurrentBag <TestContext> testContexts, ParallelOptions parallelOptions, string headlessBrowserPath, ConcurrentQueue <TestFileSummary> testFileSummaries, TestCaseSummary overallSummary) { Parallel.ForEach( testContexts, parallelOptions, testContext => { ChutzpahTracer.TraceInformation("Start test run for {0} in {1} mode", testContext.FirstInputTestFile, testExecutionMode); try { try { testHarnessBuilder.CreateTestHarness(testContext, options); } catch (IOException) { // Mark this creation failed so we do not try to clean it up later // This is to work around a bug in TestExplorer that runs chutzpah in parallel on // the same files // TODO(mmanela): Re-evalute if this is needed once they fix that bug testContext.TestHarnessCreationFailed = true; ChutzpahTracer.TraceWarning("Marking test harness creation failed for harness {0} and test file {1}", testContext.TestHarnessPath, testContext.FirstInputTestFile); throw; } if (options.TestLaunchMode == TestLaunchMode.FullBrowser) { ChutzpahTracer.TraceInformation( "Launching test harness '{0}' for file '{1}' in a browser", testContext.TestHarnessPath, testContext.FirstInputTestFile); // Allow override from command line. var browserArgs = testContext.TestFileSettings.BrowserArguments; if (!string.IsNullOrWhiteSpace(options.BrowserArgs)) { var path = BrowserPathHelper.GetBrowserPath(options.BrowserName); browserArgs = new Dictionary <string, string> { { Path.GetFileNameWithoutExtension(path), options.BrowserArgs } }; } process.LaunchFileInBrowser(testContext.TestHarnessPath, options.BrowserName, browserArgs); } else if (options.TestLaunchMode == TestLaunchMode.HeadlessBrowser) { ChutzpahTracer.TraceInformation( "Invoking headless browser on test harness '{0}' for file '{1}'", testContext.TestHarnessPath, testContext.FirstInputTestFile); var testSummaries = InvokeTestRunner( headlessBrowserPath, options, testContext, testExecutionMode, callback); foreach (var testSummary in testSummaries) { ChutzpahTracer.TraceInformation( "Test harness '{0}' for file '{1}' finished with {2} passed, {3} failed and {4} errors", testContext.TestHarnessPath, testSummary.Path, testSummary.PassedCount, testSummary.FailedCount, testSummary.Errors.Count); ChutzpahTracer.TraceInformation( "Finished running headless browser on test harness '{0}' for file '{1}'", testContext.TestHarnessPath, testSummary.Path); testFileSummaries.Enqueue(testSummary); } } else if (options.TestLaunchMode == TestLaunchMode.Custom) { if (options.CustomTestLauncher == null) { throw new ArgumentNullException("TestOptions.CustomTestLauncher"); } ChutzpahTracer.TraceInformation( "Launching custom test on test harness '{0}' for file '{1}'", testContext.TestHarnessPath, testContext.FirstInputTestFile); options.CustomTestLauncher.LaunchTest(testContext); } else { Debug.Assert(false); } } catch (Exception e) { var error = new TestError { InputTestFile = testContext.InputTestFiles.FirstOrDefault(), Message = e.ToString() }; overallSummary.Errors.Add(error); callback.FileError(error); ChutzpahTracer.TraceError(e, "Error during test execution of {0}", testContext.FirstInputTestFile); } finally { ChutzpahTracer.TraceInformation("Finished test run for {0} in {1} mode", testContext.FirstInputTestFile, testExecutionMode); } }); // Clean up test context foreach (var testContext in testContexts) { // Don't clean up context if in debug mode if (!m_debugEnabled && !testContext.TestHarnessCreationFailed && options.TestLaunchMode != TestLaunchMode.FullBrowser && options.TestLaunchMode != TestLaunchMode.Custom) { try { ChutzpahTracer.TraceInformation("Cleaning up test context for {0}", testContext.FirstInputTestFile); testContextBuilder.CleanupContext(testContext); } catch (Exception e) { ChutzpahTracer.TraceError(e, "Error cleaning up test context for {0}", testContext.FirstInputTestFile); } } } }