QTP中浏览器对象的完整结构是怎样的?
我知道这可能是一个非常基本的问题,但我最近开始使用 QTP 并且仍在学习一些东西。在过去的几个小时里,我一直在寻找这个问题的答案,但到目前为止还没有运气。
我的问题:
在QTP代码中我们通常这样写:
Browser("x").Page("y").Navigate("url")
我想了解这个Browser对象来自哪里以及x和y到底是什么。
1)它是VBScript的一部分还是QTP的一部分?
2)另外,我在哪里可以获得有关此对象结构的完整详细信息?我想知道除了“页面”和“导航”之外我还能写什么。
I know this might be a very basic question but I've recently started using QTP and am still picking up a few things. For the last couple of hours I've been searching for an answer to this but no luck so far.
My question:
In QTP code we usually write:
Browser("x").Page("y").Navigate("url")
I want to understand where this Browser object is coming from and what exactly are x and y.
1) Is it part of VBScript or is it part of QTP?
2) Also, where can I get complete details about this object structure? I would like to know what else I can write besides "page" and besides "navigate".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的示例中,“x”和“y”指的是对象存储库中的逻辑名称。因此,回答问题#1,这是 QTP 的一部分,而不是 VBScript。对象存储库是一个中间人,它将 VBScript 代码中的逻辑名称与运行时识别对象的实际细节进行映射。这只是一个抽象。
一般来说,我建议接受一些关于该工具的正式培训。培训将回答您关于此类事情的大部分问题。网络上也有大量教程。最后,帮助指南将引导您完成许多基础知识。
In your example, "x" and "y" refer to the logical name in the Object Repository. So to answer question #1, this is part of QTP, not VBScript. The Object Repository is a go-between which maps logical names in your VBScript code from the actual details of identifying an object at runtime. It's just an abstraction.
In general, I suggest getting some formal training on the tool. Training will answer most of your questions regarding this sort of thing. There are also numerous tutorials on the web as well. Lastly, the help guide will walk you through a lot of the basics.
实际上,Browser 对象代表当前打开的所有浏览器窗口和选项卡的集合。您可以通过名称或描述来指定特定的一个,如下所示:
其中“网站”可以是对象存储库中的命名“浏览器对象”,也可以是描述您想要访问的特定窗口/选项卡的描述(字符串或对象)。与. 一起工作。
Page 对象表示上述浏览器可能已加载的所有可能页面的集合。集合中的实例对应于对象存储库中命名的“页面对象”。您可以通过名称或描述来指定特定的页面,如下所示:
这个概念可能非常令人困惑,特别是考虑到任何给定的实际浏览器窗口/选项卡在任何给定时刻只能加载一个实际页面。换句话说,如果您迭代 Browser("website") 的实时子对象,则始终只有一个。
思考浏览器/页面关系的最佳方法是使用正确的隐喻。当我第一次开始使用 QTP 编程时,我认为最好将浏览器对象视为 IE、Chrome、Firefox 等,并且我尝试以这种方式管理我的对象存储库对象,但它弄得一团糟。
我现在明白,在对象存储库中组织浏览器对象的最佳方法是这样:
将存储库中的浏览器对象视为单个网站对象。 Amazon.Com MSN.Com StackOverflow.Com LifeHacker.Com 等等。
将存储库中的页面对象视为网站对象的单个明显唯一的页面。对于网站可能显示的每个不同页面(其上有不同的控件),您应该在浏览器对象下创建一个单独的 Page 对象。您的存储库可能看起来像这样:
这里的想法是创建逻辑页面来包含仅出现在这些页面上的控制对象。
现在是棘手的事情......
为了使这项工作正常进行,我们必须确保浏览器和页面对象在它们应该存在的时候实际上“存在”。对于浏览器对象,只要在任何浏览器选项卡中加载其任何页面,它就应该“存在”。对于页面对象,仅当加载该网站的页面并且其特定控件位于屏幕上时,它才应“存在”。
这意味着我们需要仔细编辑浏览器对象的标识属性,以便无论当前加载网站的哪个页面,它始终能够正确地将网站标识为该浏览器对象。
这是一个例子......在我的工作中,我有一个名为“贸易”的网站。通常可以通过
"name:=Trade"
可靠地找到浏览器...但登录页面有点不同 - 它的名称是“Welcome to Trade”...因此要使网站对象工作中,我在标识属性中使用正则表达式,如下所示:“name:=(?:Welcome to Trade|Trade)”
。这样,当找到任一名称时,相同的浏览器对象就会说它“存在”。通过这种方式,我可以将登录页面作为整个网站对象的一部分,而不必使用仅包含登录页面的浏览器对象来弄乱对象存储库。这使得稍后阅读代码变得更加烦人,并且使WITH块的使用变得复杂)另一个问题是Page对象通常很难区分。它们加载的 URL 可以是动态的,并且页面标题可能根本不会从一个页面更改为另一页面。为了解决这个问题,我向对象存储库中的页面对象添加了额外的标识属性...例如,我可以手动添加 URL 属性,然后使用正则表达式来监视 URL 中的特定标记,如下所示:
"URL:=https://TradeTools-(?:SIT|UAT).*userLogin.*"
这将是对强制标题属性的补充(切勿删除强制属性,否则记录引擎将无法正确记录)所以,更直接地回答这个问题...
对您来说,您使用 VBScript(触摸它/使用它/操纵它)。这
浏览器和页面类不存在于 QTP 之外。
QTP/UFT 帮助文件中的浏览器和页面对象。另外,您还可以阅读以下内容:http://community.hpe.com/t5/All-About-the-Apps/Understanding-the-web-test-object-model-in-HP-Unified-Functional/ba-p/ 6168133#.Vvp0V-IrK03
我希望这会有所帮助。一旦我将我对浏览器/页面的理解转变为我在这里描述的比喻,它就大大提高了我使用 QTP 的能力。
Actually, the Browser object represents a collection of all browser windows and tabs that are currently open. You specify a specific one by name or description like this:
where "website" is either a named "browser object" in the object repository, or alternately, a description (string or object) that describes a specific window/tab that you want to work with.
The Page object represents a collection of all possible pages that the above mentioned browser might have loaded. Instances in the collection correspond to named "Page objects" in the object repository. You specify a specific one by name or description like this:
This concept can be very confusing, especially considering the fact that any given actual browser window/tab can only have ONE actual Page loaded at any given moment. In other words, if you iterate over the realtime child objects of Browser("website"), there will always be only one.
The best way to think of this Browser/Page relationship is to use the right metaphor. When I first started programming with QTP, I thought it was best to think of the browser object as either IE, Chrome, Firefox, etc, and I tried to manage my object repository objects that way, and it made a huge mess.
I now understand that the best way to organize browser objects in the Object repository is this way:
Think of a browser object in the repository as a single website object. Amazon.Com MSN.Com StackOverflow.Com LifeHacker.Com etc etc.
Think of a page object in the repository as a single clearly unique page of the website object. For each different page the website might display (with different controls on it), you should create a separate Page object under the browser object. Your repository might look something like this:
The idea here is to create logical pages to contain the control objects that occur only on those pages.
Now for the tricky stuff...
In order to make this work, we have to make sure the browser and page objects actually "exist" when they should. For a browser object, it should "exist" whenever ANY of it's pages are loaded in any browser tab. For a page object, it should "exist" only when that page of that website is loaded, and it's specific controls are on the screen.
This means we need to carefully edit the identification properties for browser objects such that no matter which page of the website is currently loaded, it will always properly identify the website as that browser object.
Here's an example... At my work, I have a website called "Trade". The browser can ususally reliably be found with
"name:=Trade"
... but the login page is a little different - it's name is "Welcome to Trade"... so to make the website object work, I use a Regular Expression in the identification properties like this:"name:=(?:Welcome to Trade|Trade)"
. This way, the same browser objects says that it "exists" when either name is found. In this way, I can contain the login page as part of the whole website object instead of having to clutter up the object repository with a browser object that only contains a login page. which makes reading the code later more annoying, and complicates use of WITH blocks)Another problem is that Page objects are often difficult to tell apart. The URL's that they are loaded with can be dynamic, and the page titles might not change from one page to another at all. To resolve this, I ADD additional identification properties to my page objects in the object repository... For example, I might manually add the URL property, and then use a regex to watch for a specific tag within the URL like this:
"URL:=https://TradeTools-(?:SIT|UAT).*userLogin.*"
This would be in addition to the mandatory title property (never remove a mandatory property, or the recording engine will fail to record properly)So, to more directly answer this question...
to you, and you (touch it/use it/manipulate it) using VBScript. The
Browser and Page classes to not exist outside of QTP.
browser and page objects in the QTP/UFT help files. Also, you can read this: http://community.hpe.com/t5/All-About-the-Apps/Understanding-the-web-test-object-model-in-HP-Unified-Functional/ba-p/6168133#.Vvp0V-IrK03
I hope this helps. Once I switched my understanding of browsers/pages to the metaphor I've described here, it has greatly increased my capabilities with QTP.
Browser
测试对象代表选项卡式浏览器中的单个选项卡。当调用
Browser
函数时,QTP返回一个测试对象,通常这是来自关联对象存储库的具有该名称的浏览器(与您的“x”
示例一样),但它可能使用描述性编程创建新的测试对象。当调用
浏览器
的子元素时,您有两个选择(与所有测试对象一样):Browser
的子级几乎总是Page
,但可以出现Window
或其他对象(具体取决于您正在测试的应用程序)。Page
测试对象表示浏览器
中显示的顶级 HTML 文档。顺便说一句,您编写的代码片段是错误的。
Page
不支持Navigate
方法,Browser
支持。The
Browser
test object represents a single tab in a tabbed browser.When calling the
Browser
function QTP returns a test object, usually this is the Browser with that name from an associated object repository (as with your"x"
example) but it may use descriptive programming to create a new test object.When calling a subelement of the
Browser
you have two options (as with all test objects)Browser
are almost alwaysPage
butWindow
or other objects can appear (depending on the application you're testing).The
Page
test object represents the top level HTML document displayed in theBrowser
.BTW, The code snippet you wrote is wrong.
Page
does not support theNavigate
method,Browser
does.