loho1968 发表于 2007-8-13 16:29:57

QTP中是否能够动态加载对象库

WR中可以通过代码实现,QTP中好像必须事先设置对TEST和Action使用的对象库。

hsjzfling 发表于 2007-8-13 16:52:27

用描述性编程可以很容易做到这一点,具体可参见论坛中关于描述性编程的帖子

yabest 发表于 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

bobile 发表于 2007-8-13 16:54:35

对的,上面的说的对.可以用描述性语言来解决

bobile 发表于 2007-8-13 16:55:23

但是要定义很多的object的话,看高手有没有其他更好的办法

loho1968 发表于 2007-8-13 17:32:35

原帖由 yabest 于 2007-8-13 16:52 发表 http://bbs.51testing.com/images/common/back.gif
当然可以了

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

//QTP9.x
Set App = CreateObject("QuickTest.Applicati ...
好像差app.open ...一样,不然,怎么知道是哪一个Test呢?

loho1968 发表于 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来执行,就可以成功。

yabest 发表于 2007-8-13 18:15:06

呵呵,我的代码是在QTP里运行的,所以App.Test固定指向自身的Test,App不用也不能再Open另一个Test的。

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

yabest 发表于 2007-8-13 18:19:20

原帖由 bobile 于 2007-8-13 16:54 发表 http://bbs.51testing.com/images/common/back.gif
对的,上面的说的对.可以用描述性语言来解决

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

loho1968 发表于 2007-8-13 20:57:31

原帖由 yabest 于 2007-8-13 18:15 发表 http://bbs.51testing.com/images/common/back.gif
呵呵,我的代码是在QTP里运行的,所以App.Test固定指向自身的Test,App不用也不能再Open另一个Test的。

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

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

yabest 发表于 2007-8-13 21:48:41

原帖由 loho1968 于 2007-8-13 20:57 发表 http://bbs.51testing.com/images/common/back.gif


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

save是可以的,但不能在Running时save,我一般是Running前做Save!

bobile 发表于 2007-8-14 09:20:34

不行的,必须先录制,把对象保存起来,或者用描述性定义也可以

bobile 发表于 2007-8-14 09:20:43

大家多支持哈

danmy 发表于 2007-8-14 09:46:25

好铁,顶一下

ivykkk 发表于 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]
查看完整版本: QTP中是否能够动态加载对象库