bitmulticoder
Добавить ссылку на Interop.QuickTest.dll в вашем проекте/решении - QTP 11, и, скорее всего, последние 2 или около того версии
Приведенный ниже код работает в течение многих месяцев в производственной среде
qtApp = new QuickTest.Application(); // reference to QTP Application
qtApp.Launch(); // Launch QTP
qtApp.Visible = true; // or false - set visible state
qtApp.Options.Run.RunMode = "Normal"; // Run Mode
qtApp.Options.Run.StepExecutionDelay = 250; // Delay between execution of steps
qtApp.Options.Run.ViewResults = false; // Do not view results at end of test
string scriptPath = uncPathToScript; // UNC path to script, or and other drive/location that the application invoking QTP has access to
qtApp.Open(scriptPath, true, false); // Open the script, read only, do not save changes
// Get a reference to the test object
QuickTest.Test qtTest = qtApp.Test; // Get reference to test object opened/created by application
qtTest.Settings.Run.OnError = "NextStep"; // Stop
// Get a reference to the Results Object for test results location
QuickTest.RunResultsOptions qtRRO = new QuickTest.RunResultsOptions(); // This is just here because, possible not necessary
string dt = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
dt = dt.Replace("/", "-");
dt = dt.Replace(":", "-");
dt = dt.Replace(" ", "-");
string reportDirectory = uncPathToScript.Substring(uncPathToScript.LastIndexOf("\\") + 1);
reportFilePath = uncPathToScript + "\\" + reportDirectory + "_" + dt;
// Create the report directory under the test itself with a date time stamp
System.IO.Directory.CreateDirectory(reportFilePath); // Create the report directory as a subdirectory of the script to run
qtRRO.ResultsLocation = reportFilePath; // Set results location to newly created path (folder)
// Run the test
qtTest.Run(qtRRO, true, null); // run the test
qtTest.Close(); // Close the test
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(qtTest); // Cleanly release COM object
qtTest = null; // set object to null
qtApp.Quit(); // Quit QTP
GC.Collect(); // Garbage collect
GC.WaitForPendingFinalizers(); // Wait for GC
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(qtApp); // Cleanly release COM Object
qtApp = null; // set to null