如何使用 C Sharp 自动化 Qtp

编程


大家好,

我正在开发一个应用程序,在其中下载 Qtp 脚本。 我需要将其传递给 Qtp 以自动执行,但我想以编程方式执行此操作。

我想用 C# 来做这个。 请建议我 Qtp API 是否可用或其他什么,通过它我可以自动化这个过程。

谢谢,
贾乔特

解决方案1

不能只用脚本作为临时文件来执行CScript吗?

您应该能够使用 Process.Start 来做到这一点

解决方案2

我想您想稍微浏览一下这个网站: http://qtp.blogspot.com/2008/11/qtp-apis-dlls-and-more.html[^]。
它包含大量信息,包括教程和示例。

干杯!

解决方案3

您可以将 QTP 与 C# dot net 集成,
QTP 提供了托管 dll,用于与 dot net 集成。

  • Mercury.QTP.CustomServer.dll(QTP为dot net提供的dll)
  • Janus.Windows.GridEX.v3.dll(Janus提供托管dll用于识别janus网格及其属性。)

    问候,
    穆纳·萨弗拉兹

  • 解决方案4

    在您的项目/解决方案中添加对 Interop.QuickTest.dll 的引用 – QTP 11,很可能是最后 2 个左右的版本

    下面的代码在生产环境中运行了好几个月

    C#
    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

    コメント

    タイトルとURLをコピーしました