51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 4152|回复: 14
打印 上一主题 下一主题

[原创] QTP中是否能够动态加载对象库

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2007-8-13 16:29:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
WR中可以通过代码实现,QTP中好像必须事先设置对TEST和Action使用的对象库。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2007-8-13 16:52:27 | 只看该作者
用描述性编程可以很容易做到这一点,具体可参见论坛中关于描述性编程的帖子
回复 支持 反对

使用道具 举报

该用户从未签到

3#
发表于 2007-8-13 16:52:48 | 只看该作者

回复 #1 loho1968 的帖子

当然可以了

//QTP8.x
Set App = CreateObject("QuickTest.Application")
App.Test.Settings.Resources.ObjectRepositoryPath = RepositoryFile

//QTP9.x
Set App = CreateObject("QuickTest.Application")
Set qtRepositories = App.Test.Actions("YourActionName").ObjectRepositories
qtRepositories.RemoveAll
qtRepositories.Add RepositoryFile, 1
回复 支持 反对

使用道具 举报

该用户从未签到

4#
发表于 2007-8-13 16:54:35 | 只看该作者
对的,上面的说的对.可以用描述性语言来解决
回复 支持 反对

使用道具 举报

该用户从未签到

5#
发表于 2007-8-13 16:55:23 | 只看该作者
但是要定义很多的object的话,看高手有没有其他更好的办法
回复 支持 反对

使用道具 举报

该用户从未签到

6#
 楼主| 发表于 2007-8-13 17:32:35 | 只看该作者
原帖由 yabest 于 2007-8-13 16:52 发表
当然可以了

//QTP8.x
Set App = CreateObject("QuickTest.Application")
App.Test.Settings.Resources.ObjectRepositoryPath = RepositoryFile

//QTP9.x
Set App = CreateObject("QuickTest.Applicati ...

好像差app.open ...一样,不然,怎么知道是哪一个Test呢?
回复 支持 反对

使用道具 举报

该用户从未签到

7#
 楼主| 发表于 2007-8-13 17:57:30 | 只看该作者
'************************************************************************************************************************

'Description:

'

'This example opens a test, configures an action's object repositories collection

'and saves the test.

'

'Assumptions:

'There is no unsaved test currently open in QuickTest.

'For more information, see the example for the Test.SaveAs method.

'************************************************************************************************************************



Dim qtApp 'As QuickTest.Application ' Declare the Application object variable

Dim qtRepositories 'As QuickTest.ObjectRepositories ' Declare an action's object repositories collection variable

Dim lngPosition



' Open QuickTest

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object

qtApp.Launch ' Launch QuickTest

qtApp.Visible = True ' Set QuickTest to be visible



' Open a test and get the "Login" action's object repositories collection

qtApp.Open "C:\Tests\Test1", False, False ' Open a test

Set qtRepositories = qtApp.Test.Actions("Login").ObjectRepositories ' Get the object repositories collection object of the "Login" action



' Add MainApp.tsr if it's not already in the collection

If qtRepositories.Find("C:\MainApp.tsr") = -1 Then ' If the repository cannot be found in the collection

    qtRepositories.Add "C:\MainApp.tsr", 1 ' Add the repository to the collection

End If



' If InnerWnd.tsr is moved down the list - place it back at position 1

If qtRepositories.Count > 1 And qtRepositories.Item(2) = "C:\InnerWnd.tsr" Then ' If there's more than one object repository and InnerWnd.tsr is in position 2

    qtRepositories.MoveToPos 1, 2 ' Switch between the first two object repositories

End If



' If Debug.tsr is in the collection - remove it

lngPosition = qtRepositories.Find("C:\Debug.tsr") ' Try finding the Debug.tsr object repository

If lngPosition <> -1 Then ' If the object repository was found in the collection

    qtRepositories.Remove lngPosition ' Remove it

End If



' Set the new object repository configuration as the default for all new actions

qtRepositories.SetAsDefault ' Set object repositories associated with the "Login" action as the default for all new actions



'Save the test and close QuickTest

qtApp.Test.Save ' Save the test

qtApp.Quit ' Quit QuickTest



Set qtRepositories = Nothing ' Release the action's shared repositories collection

Set qtApp = Nothing ' Release the Application object

上面是QTP帮助中的示例,在QTP中不能执行成功,如果使用VB来执行,就可以成功。
回复 支持 反对

使用道具 举报

该用户从未签到

8#
发表于 2007-8-13 18:15:06 | 只看该作者
呵呵,我的代码是在QTP里运行的,所以App.Test固定指向自身的Test,App不用也不能再Open另一个Test的。

如果是在外部VBS脚本运行和启动QTP,那就要Open一个Test。
回复 支持 反对

使用道具 举报

该用户从未签到

9#
发表于 2007-8-13 18:19:20 | 只看该作者
原帖由 bobile 于 2007-8-13 16:54 发表
对的,上面的说的对.可以用描述性语言来解决


这不是描述性编程,描述性编程是指在脚本里描述对象的属性特征,而不在对象库里描述对象的属性特征。
回复 支持 反对

使用道具 举报

该用户从未签到

10#
 楼主| 发表于 2007-8-13 20:57:31 | 只看该作者
原帖由 yabest 于 2007-8-13 18:15 发表
呵呵,我的代码是在QTP里运行的,所以App.Test固定指向自身的Test,App不用也不能再Open另一个Test的。

如果是在外部VBS脚本运行和启动QTP,那就要Open一个Test。


谢谢,我试验成功了,但不能执行qtapp.test.save
回复 支持 反对

使用道具 举报

该用户从未签到

11#
发表于 2007-8-13 21:48:41 | 只看该作者
原帖由 loho1968 于 2007-8-13 20:57 发表


谢谢,我试验成功了,但不能执行qtapp.test.save


save是可以的,但不能在Running时save,我一般是Running前做Save!
回复 支持 反对

使用道具 举报

该用户从未签到

12#
发表于 2007-8-14 09:20:34 | 只看该作者
不行的,必须先录制,把对象保存起来,或者用描述性定义也可以
回复 支持 反对

使用道具 举报

该用户从未签到

13#
发表于 2007-8-14 09:20:43 | 只看该作者
大家多支持哈
回复 支持 反对

使用道具 举报

该用户从未签到

14#
发表于 2007-8-14 09:46:25 | 只看该作者
好铁,顶一下
回复 支持 反对

使用道具 举报

该用户从未签到

15#
发表于 2010-10-13 10:08:29 | 只看该作者
回复 7# loho1968


    虽然事隔多年,但仍想问个问题:
' If InnerWnd.tsr is moved down the list - place it back at position 1

If qtRepositories.Count > 1 And qtRepositories.Item(2) = "C:\InnerWnd.tsr" Then ' If there's more than one object repository and InnerWnd.tsr is in position 2

    qtRepositories.MoveToPos 1, 2 ' Switch between the first two object repositories

End If
这里使用的InnerWnd.tsr 及转换其位置有什么意义?
回复 支持 反对

使用道具 举报

本版积分规则

关闭

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

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

GMT+8, 2024-9-21 05:38 , Processed in 0.075196 second(s), 25 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

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