C# 我可以使用 VBScript 以外的语言以编程方式执行 QTP 测试吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/895342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I use a language other than VBScript to programmatically execute QTP Tests?
提问by ssakl
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.
我有 VBScript 代码,可以启动 QuickTest Professional,执行一系列 QTP 测试,并通过电子邮件发送结果。这很有效,但我更喜欢使用具有更好工具支持的语言(例如一个好的 IDE)。我目前正在从启动脚本调用 .Net 库,所以我想知道是否可以使用像 C# 这样的语言来完成相同的任务。如果是这样,是否有任何好的资源可以解决这个问题?我可以通过谷歌在这个主题上找到很少的东西,而且似乎没有关于这个主题的任何其他问题。
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
.
为清楚起见,我包含了执行大部分工作的例程的代码。这不包括净声明,但failedTestsList
并allTestsList
是实例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.
编辑:所有 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
采纳答案by Xiaofu
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:
抱歉,我没有时间将您的完整示例转换为 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;
}
}
}
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.
你需要编译它链接到 C:\Program Files\Mercury Interactive\QuickTest Professional\bin\QTObjectModelLib.dll(这是 QTObjectModel.dll 的 .NET 互操作库),并在你的应用程序目录中有它和 QTObjectModel.dll当你运行它时。
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.
从这里开始,将任何对象声明和函数调用从 VBScript 转换为 C# 应该不难。请问有什么不清楚的。
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 Forumsfor your QTP and QC needs.
关于互联网上的样本的另一点 - 有很多人在用 QTP 和 QC 做更高级的事情,但我认为任何真正聪明的解决方案都没有共享。例如,我的雇佣合同可能会禁止我分享这些东西,但我同意你的看法 - 那里缺乏好的 QTP API 示例,至少在 Google 上是这样。话虽如此,我衷心推荐SQA 论坛以满足您的 QTP 和 QC 需求。
Rich
富有的
回答by Cheeso
YES, you can use anything that can "do" COM, and that includes C#. Also VB.NET of course.
是的,你可以使用任何可以“做”COM 的东西,包括 C#。当然还有VB.NET。
and Perl, Python, Javascript, and others.
和 Perl、Python、Javascript 等。
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.
在没有谷歌帮助的情况下,你将不得不跟随你的鼻子,了解如何处理界面,但当你有现有的例子时,这并不难。理想情况下,您的供应商也会为您记录 COM 接口。
回答by Buddha
if this still matters to you... QTP 11 allows you to script in C#
如果这对您仍然很重要... QTP 11 允许您在 C# 中编写脚本
回答by cREcker
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:
请参阅以下答案,因为它将为您提供使用 QTP/UFT 连接 C# 应用程序所需的确切信息: