51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2640|回复: 1
打印 上一主题 下一主题

[转贴] Using QTP as a test suite controller

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2008-1-8 14:35:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
刚看到一篇不错的文章想推荐给大家,附件是作者的一个例子脚本,请大家可以看下它的一些思想,有的还是非常不错的!
    希望对大家有用!
This posting describes a technique for using a QTP test (in this example named: suiteControl) to control execution of X number of other tests. This posting should interest anyone who would prefer not to use the heavyweight TestDirector/QC solution simply for the purpose of implementing a suite of tests.

Attached is a ZIP file with all of the components and tests described below. You should be able to unzip these tests and libs in any directory and run them (they are suppose to all contain path relative references, but in you have a problems try running them in c:\qtp\scripts\suiteExample root directory).

Note that the attached example was done using QTP 9.2, so those who have QTP 8.2 will not be able to run the code, but hopefully will be able to view the QTP files using a standard text editor.

The Components

1. <rootdir>\testArray.vbs is the heart of this implementation and contains an array of data structures, where the array is actually a Dictionary object and the structures are simple custom objects—one for each test called by the suite controller test.

2. <rootdir>\suiteControl is the suite controller QTP test that calls X number of tests in the suite.

3. <rootdir>\test101 an example test case to be called.

4. <rootdir>\test520 an example test case to be called.

How The Components Interact

As you can see by reviewing the suiteControl test case, its job is to simply iterate through the testArray dictionary (defined in testArray.vbs) and call each test defined in each testStruct object found in the dictionary. Furthermore it logs pass/fail status for each test as they return.

Because the testArray dictionary and its objects are shared by the suite controller test and all of the called tests (they all include ..\testArray.vbs on their Test Settings Resource tab) each called test can communicate (i.e. pass data to and from) with the suite controller using its test-unique testStruct object in the dictionary.

Review either of the called test cases, test101 or 520. Note that they get a copy of their private testStruct from the testArray dictionary using the method call:
Code:
--------------------------------------------------------------------------------

Dim testNum : testNum=101Dim   ts    : Set  ts=testArray.getStruct(testNum, "test enter")

--------------------------------------------------------------------------------

Thereafter a test can determine if they have been invoked “standalone” or invoked via the suite controller test by evaluating the ts.bStandalone setting (if False they have been invoked by the suite controller). This allows for standalone execution and debugging stuff to be placed in the script that does not need to be commented out when invoked by the suite controller. (Review this test code and experiment…)

Setup Related Remarks

At this point you should probably have enough understanding to experiment and extend this design implementation to meet your unique needs—as I believe the code is simple and complete. But a few setup related issues and gothcas are worth mentioning:

1. testArray.vbs’s testArrayInit() function builds a dataStruct object for every test action being called. Of this initialization the one who’s syntax is most demainding is the one defining the action to call in a test, for example:

testStruct.sActionToCall = "main [Test101]"

The string must contain the exact syntax that QTP inserts in a call to the external action. (Note that I like to standardize on “main” as the entry Action to all of my tests, but this is not a requirement to using this implementation).

2. It would be a wonderful world in QTP land if you could place a “call to action blah” in your code, and then call it. If that was the case then the definition in step #1 above would be all we would have to do for setup. But alas, this is not the case with QTP. You must also, using the QTP IDE, perform an Insert:Call To Existing Action… interactive step in the suite controller test case (suiteControl in our example). This insertion should always be done using one of the path relative techniques described in the following posting:

http://www.sqaforums.com/showfla ... p;page=0#Post378894

3. Each called test returns its status via its private testStruct’s bPassed variable. By default a test is always invoked with this value set to False (i.e. test “failed” status), so a test which determines it has “passed” needs to set this testStruct value to True prior to returning the the suite controller. This should be done no matter how the test is invoked (to be on the safe side).

Beyond this simple example

This example code has been kept intentionally simple, so that the concepts and communication mechanisms are easy to see and understand. But the testStruct object can be enhanced and added to in any number of ways (say, adding X number of input fields and Y number of output fields) to meet more demanding test interface needs. This implementation also solves the problem, by using a user extensible testStruct object, to passing complex data to/from calling and called Actions.

-Hope this helps, Terry Horwath

[ 本帖最后由 lantianwei 于 2008-1-8 15:58 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2008-1-8 17:07:23 | 只看该作者
有点意思。不过感觉实用性不大。维护一个testStruct object挺麻烦的。
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-23 04:44 , Processed in 0.071323 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表