我可以使用VBScript以外的语言以编程方式执行QTP测试吗?

我有VBScript代码,它启动QuickTest Professional,执行一系列QTP测试,并通过电子邮件发送结果。 这很好用,但我更喜欢使用具有更好工具支持的语言(例如一个好的IDE)。 我目前正在从启动脚本调用.Net库,所以我想知道是否可以使用像C#这样的语言来完成相同的任务。 如果是这样,有什么好的资源可以解决这个问题吗? 我可以通过谷歌找到关于这个主题的很少的内容,似乎没有关于这个主题的任何其他问题。

为清楚起见,我已经包含了执行大部分工作的例程的代码。 这不包括.Net声明,但failedTestsListallTestsListSystem.ArrayList实例。

编辑 :所有QTP文档示例都使用VBScript,但正如您所看到的,代码只是创建QTP对象。 我认为这些可以从支持创建这些对象的另一种语言调用。 我的谷歌失败似乎没有人这样做。

 Sub ExecuteQTPTest(name) Dim App, resultsPath Dim testPath, testResults testPath = name allTestsList.Add(name) Set App = CreateObject("QuickTest.Application") App.Launch App.Visible = False App.Open testPath SetQTPTestOptions(App) SetQTPRunOptions(App) SetQTPWebOptions(App) App.Folders.RemoveAll Dim qtpTest, qtpResultsOpt Set qtpTest = App.Test Set qtpResultsOpt = CreateObject("QuickTest.RunResultsOptions") resultsPath = testPath & "\RES1" qtpResultsOpt.ResultsLocation = resultsPath qtpTest.Run qtpResultsOpt ''// Run the test testResults = "Test Status: " & qtpTest.LastRunResults.Status & vbCrLf & _ "Last Error: " & qtpTest.LastRunResults.LastError & vbCrLf & _ "Detailed Results located at " & qtpTest.LastRunResults.Path & _ " can be viewed with the QTP Results Viewer Tool " & vbCrLf If qtpTest.LastRunResults.Status  "Passed" Then g_testRunPassed = False failureCount = failureCount + 1 failedTestsList.Add(name) LogResults testResults, name End If qtpTest.Close Set qtpResultsOpt = Nothing Set qtpTest = Nothing App.Quit Set App = Nothing End Sub 

道歉,但我没有时间将您的完整样本转换为C#。 我把一个简单的演示组合在一起,可以让你前进。 这只是用C#打开一个QTP实例:

 using System; using QTObjectModelLib; namespace QtpDemo { class QtpDriver { [STAThread] static void Main(string[] args) { Application app = new Application(); app.Launch(); app.Visible = true; } } } 

你需要编译它链接到C:\ Program Files \ Mercury Interactive \ QuickTest Professional \ bin \ QTObjectModelLib.dll(这是QTObjectModel.dll的.NET互操作库)并在你的app目录中有它和QTObjectModel.dll当你运行它。

从这里开始,将任何对象声明和函数调用从VBScript转换为C#都不应该那么难。 请问是否有任何不清楚的地方。

关于互联网上样本的另一点 – 有很多人用QTP和QC做更高级的东西,但我认为任何非常聪明的解决方案都不会被共享。 例如,我可能会被禁止通过我的雇佣合同分享这些东西,但我同意你的意见 – 那里缺乏良好的QTP API样本,至少在Google上是这样。 话虽如此,我衷心推荐SQA论坛,以满足您的QTP和QC需求。

丰富

是的,你可以使用任何可以“做”COM的东西,包括C#。 当然也是VB.NET。

和Perl,Python,Javascript等。

在谷歌没有帮助的情况下,您将不得不关注如何处理界面,但是当您拥有现有示例时并不难。 理想情况下,您的供应商也会为您记录COM接口。

如果这对你来说仍然很重要… QTP 11允许你在C#中编写脚本

请参阅以下答案,因为它将为您提供将C#应用程序与QTP / UFT连接的确切信息:

https://stackoverflow.com/a/19887866/2794121