问题描述
我为QTP 10测试构建了许多功能,其中许多功能依赖于其他相关功能。我想让我的功能导入他们需要的任何其他功能。目前,我必须通过我的每个函数,并手动关联每个依赖项。
虽然我知道 ExecuteFileC :\Functions\SampleFunction.vbs
可以工作,但缺点是QTP无法显示任何刚刚导入的代码。这意味着调试代码是一个噩梦,因为QTP将显示与实际运行的代码不相对应的线上的黄色调试指针。长话短说,这种方法是一团糟。
是否有任何其他命令会在运行时将其他.vbs文件导入到QTP中,因此我可以将这些函数导入他们需要的其他功能?
我发现Anish Pillai的一篇文章称为4种不同的方式将功能库与QTP脚本相关联,这有一些有用的信息。 (请参阅此处的原始帖子:)
方法1 是将函数与测试关联的常用方法;
方法2 使用AOM(自动化对象模型)
我尝试了许多不同的变体,但它们似乎都是从QTP之外启动特定测试的脚本,而不是为运行测试添加功能。
这里是他们的代码,以防万一它证明有用:
$ p $ '打开QTP
Set objQTP = CreateObject( QuickTest.Application)
objQTP.Launch
objQTP.Visible = True
'打开一个测试并将一个函数库关联到测试
objQTP.OpenC :\Automation\SampleTest,False,False
Set objLib = objQTP.Test.Settings.Resources.Libraries
'如果库尚未与测试用例关联,则关联它.. ..
如果objLib.Find(C:\SampleFunctionLibrary.vbs)= -1然后'如果库尚未添加
objLib.AddC:\SampleFunctionLibrary.vbs, 1'将库关联到测试用例
End
方法#3 使用ExecuteFile方法
与我在问题中提到的相同。可能很有用,但在QTP 10中调试是非常糟糕的。
方法4 使用LoadFunctionLibrary方法
这是最有前途的做法。它看起来完全符合我们的需求:在测试运行时加载vbscript函数库。唯一的收获? 它仅仅是QTP 11+ 。我不能保证这种方法,因为我没有QTP 11,但它看起来像是一种完美的方法。
LoadFunctionLibrary C:\ YouFunctionLibrary_1.vbs'关联一个函数库
LoadFunctionLibraryC:\FuncLib_1.vbs,C:\FuncLib_2.vbs'关联多个函数库
I've built many functions for my QTP 10 tests, and many of those functions rely on other, related functions. I would like to have my functions import any other functions that they require. Currently, I have to go through each of my functions and associate each of their dependencies by hand.
While I'm aware that ExecuteFile "C:\Functions\SampleFunction.vbs"
would work, the downside is that QTP is unable to display any of the code it just imported. That means that debugging the code is a nightmare, since QTP will show that yellow debugging pointer on lines that don't correspond to the code actually being run. Long story short, that approach is a mess.
Is there any other command that will import other .vbs files into QTP during runtime, so I can have the functions import the other functions they require?
I found a post by Anish Pillai called "4 Different Ways to Associate Function Libraries to your QTP Scripts", that has some useful info. (See the original post here: http://www.automationrepository.com/2011/09/associate-function-library-to-qtp-script/ )
Method #1 is the usual way to associate functions with a test; nothing new there.
Method #2 Using AOM (Automation Object Model)
I've tried many different variations, but all of them seem to be scripts for launching a specific test from outside of QTP, not for adding a function to a running test.Here's their code in case it proves useful:
'Open QTP
Set objQTP = CreateObject("QuickTest.Application")
objQTP.Launch
objQTP.Visible = True
'Open a test and associate a function library to the test
objQTP.Open "C:\Automation\SampleTest", False, False
Set objLib = objQTP.Test.Settings.Resources.Libraries
'If the library is not already associated with the test case, associate it..
If objLib.Find("C:\SampleFunctionLibrary.vbs") = -1 Then ' If library is not already added
objLib.Add "C:\SampleFunctionLibrary.vbs", 1 ' Associate the library to the test case
End
Method #3 Using ExecuteFile MethodHas the same downfalls that I brought up in the question. Could be useful, but it's horrible for debugging within QTP 10.
Method #4 Using LoadFunctionLibrary MethodThis is the most promising approach. It appears to do exactly what we need it to: load vbscript function libraries while the test is running. The only catch? It appears to be QTP 11+ only. I can't vouch for this method since I don't have QTP 11, but it looks like the perfect approach.
LoadFunctionLibrary "C:\YourFunctionLibrary_1.vbs" 'Associate a single function library
LoadFunctionLibrary "C:\FuncLib_1.vbs", "C:\FuncLib_2.vbs" 'Associate more than 1 function libraries
这篇关于如何在运行时将函数导入到我的QTP测试中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!