我可以使用 VBScript 以外的语言以编程方式执行 QTP 测试吗?
我有 VBScript 代码,可以启动 QuickTest Professional、执行一系列 QTP 测试并通过电子邮件发送结果。 这很有效,但我更喜欢使用具有更好工具支持的语言(例如一个好的 IDE)。 我目前正在从启动脚本调用 .Net 库,因此我想知道是否可以使用 C# 等语言来完成相同的任务。 如果是这样,有什么好的资源可以解决这个问题吗? 我通过谷歌几乎找不到关于这个主题的信息,而且似乎没有关于这个主题的任何其他问题。
为了清楚起见,我已经包含了完成大部分工作的例程的代码。 这不包括 .Net 声明,但 failedTestsList
和 allTestsList
是 System.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
I have VBScript code which launches QuickTest Professional, executes a series of QTP tests, and emails the results. This works well, but I would prefer to use a language with better tools support (a good IDE for example). I am currently calling .Net libraries from the launch script, so I was wondering if it was possible to use a language like C# to accomplish the same task. If so, are there any good resources which address this? I could find very little on this topic via Google and there do not seem to be any other questions on SO about this topic.
For clarity, I have included the code for the routine that does the bulk of the work. This does not include the .Net declarations, but failedTestsList
and allTestsList
are instances of System.ArrayList
.
EDIT: All the QTP documentation examples use VBScript, but as you can see, the code is just creating the QTP objects. I would assume these would be callable from another language which supported creation of these objects. It just seems from my Google failures that no one is doing it.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
抱歉,我没有时间将您的完整示例转换为 C#。 我整理了一个简单的演示,应该可以帮助您上手。 这仅使用 C# 打开 QTP 实例:
您需要编译链接到 C:\Program Files\Mercury Interactive\QuickTest Professional\bin\QTObjectModelLib.dll(这是 QTObjectModel.dll 的 .NET 互操作库)并且当您运行它时,将其和 QTObjectModel.dll 放在您的应用程序目录中。
从这里开始,将任何对象声明和函数调用从 VBScript 转换为 C# 应该不难。 有什么不清楚的地方请追问。
关于互联网上的示例的另一点 - 有很多人使用 QTP 和 QC 做更高级的事情,但我认为任何真正聪明的解决方案都没有共享。 例如,我的雇佣合同可能会禁止我分享此类内容,但我同意你的观点——那里缺乏好的 QTP API 示例,至少在 Google 上是这样。 话虽如此,我衷心推荐SQA 论坛来满足您的 QTP 和 QC 需求。
富有的
Apologies, but I don't have time to convert your full sample over to C#. I've thrown together a simple demo that should get you going. This just uses C# to open a QTP instance:
You'll need to compile it linking to C:\Program Files\Mercury Interactive\QuickTest Professional\bin\QTObjectModelLib.dll (which is the .NET interop library for QTObjectModel.dll) and have that and QTObjectModel.dll in your app directory when you run it.
It shouldn't be that hard from here for you to convert any object declarations and function calls from VBScript to C#. Please ask if anything's unclear.
To your other point about samples on the internet - there are plenty of people out there doing more advanced stuff with QTP and QC, but I think any really clever solutions aren't shared. I, for example, would probably be prohibited from sharing such things by my employment contract, but I agree with you - there is a dearth of good QTP API samples out there, at least on Google. Having said that, I heartily recommend the SQA Forums for your QTP and QC needs.
Rich
是的,您可以使用任何可以“执行”COM 的东西,包括 C#。
当然还有VB.NET。
以及 Perl、Python、Javascript 等。
在没有谷歌帮助的情况下,你将不得不跟随你的鼻子,如何处理界面,但当你有现有的例子时,这并不困难。 理想情况下,您的供应商也会为您记录 COM 接口。
YES, you can use anything that can "do" COM, and that includes C#.
Also VB.NET of course.
and Perl, Python, Javascript, and others.
With no help from google, you will have to follow your nose, on how to deal with the interface, but it's not that difficult when you have the existing example. Also your vendor, ideally, will have documented the COM interface for you.
如果这对您来说仍然很重要...QTP 11 允许您使用 C# 编写脚本
if this still matters to you... QTP 11 allows you to script in C#
请参阅以下答案,因为它将为您提供将 C# 应用程序与 QTP/UFT 连接所需的确切信息:
https:// /stackoverflow.com/a/19887866/2794121
Please see the following answer as it will give you the exact information you are looking for to connect a C# application with QTP/UFT:
https://stackoverflow.com/a/19887866/2794121