HP UFT中对象的建立和引用 [英] Buildup and reference of objects in HP UFT

查看:96
本文介绍了HP UFT中对象的建立和引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何通过控制台/手表访问属性/方法.

I'm wondering how I can access properties/methods via console/watch.

我有以下代码:

Dim page 
page = Browser("Welcome: Mercury Tours").Page

现在,我想获取此页面的标题.由于我使用Object Spy检查了Page对象,并且看到它具有title属性.

Now I want to obtain the title of this Page. Since I inspected the Page object with Object Spy and I saw it has a title property.

但是,当我在手表中输入page.title时,它告诉我该页面不包含该属性.
1.正确的语法是什么?
2.为什么这不起作用?我以为手表正在检查VBScript对象属性而不是TestObject属性? (我有一个编程背景,我发现让VBObjects和TestObjects遍历同一个文件感到非常困惑.这有点像黑匣子:/)

When I enter page.title in my watch however, it tells me that page does not contain the property.
1. What is the correct syntax?
2. Why is this not working? I presume that the watch is checking for VBScript object properties instead of TestObject properties? (I have a programming background and I find it very confusing that I have VBObjects and TestObjects simply walking through the same file. It kind of feels like a black box :/)

推荐答案

好吧,您的语法不正确...

Ok, well, your syntax is incorrect...

您似乎正在尝试将某些内容放到名为"page"的变量中,但是我不确定是否可以弄清您的意图.

It appears that you're trying to put something into a variable called "page", but I'm not sure if I can figure out your intention.

如果试图将页面对象放入var"page"中,则需要使用set语句(向vbscript表示它将保留一个对象,而不仅仅是单个数据).

If you are trying to put the page object into the var "page", you would need to use a set statement (to indicate to vbscript that it's going to hold an object, not just a single piece of data)...

无论如何,您用于指定Page的语法是错误的.

Regardless of that, your syntax for specifying the Page is wrong.

在您的示例中,您从存储库中指定了一个名为"Welcome:Mercury Tours"的浏览器测试对象...但是您放了.Page-这就是语法错误所在.

In your example, you're specifying a browser test object called "Welcome: Mercury Tours" from the repository... but then you put .Page - and that's where your syntax error is.

它有助于了解测试对象和实时对象之间的区别-因为您需要指定页面测试对象".您可以通过在对象库中指定页面对象来做到这一点,也可以通过描述性的方式来做到这一点.

It helps to understand the difference between Test Objects and Realtime Objects - because you need to specify a page Test Object. You can do that by specifying a page object from the Object Repository, or you can do it descriptively.

测试对象是QTP试图找到的真实对象的描述.如果成功找到与描述相匹配的真实对象,则(实际上)附加到"真实对象的测试对象"类型……然后,您可以使用该测试对象来查询与其相关的真实对象的真实属性.附加到.

Test Objects are descriptions of real objects that QTP tries to find. If it successfully finds a real object that matches the description, then the Test Object kind of (virtually) "attaches to" the real object... then, you can use the test object to query the real attributes of the real object that it attached to.

不要紧,您显然正在完成本教程,您的对象存储库可能在层次结构中的浏览器对象下面有一个Page测试对象...(并且,如果您让Intellisense帮忙,它将显示一个页面列表供您选择)从您输入时开始...).如果是这样,则可以这样指定页面对象:

Sincel you're clearly doing the tutorial, your object repository probably has a Page test object in the heiarchy under the browser object... (and if you had let Intellisense help, it would show you a list of pages to choose from while you type...). If so, you would specify the page object like this:

Browser("Welcome: Mercury Tours").Page("PageObjectNameHere")

如果您更喜欢使用描述性编程,则可以输入以下内容:

If you would prefer to use descriptive programming, you could instead type something like:

Browser("Welcome: Mercury Tours").Page("Title:=Welcome: Mercury Tours")

将语法更改为任何一种构造,都可以使您继续解决问题的下一部分-如何从页面中获取一些数据...

Changing your syntax to either of those constructs would let you proceed with the next part of solving your question - how to get some data from the page...

因此,一旦正确地找到了页面测试对象,就可以指定一种从中获取信息的方法,例如.GetROProperty()

So, once you have address the page test object correctly, then you can specify a method to get information from it... such as .GetROProperty()

您可以从页面的许多属性中进行选择...如果使用GUISPY检查页面,它几乎为您提供了可供查询的属性列表...例如,如果您要检查显示的页面,您可以指定

You can choose from many properties for a page... If you examine a page using GUISPY, it pretty much gives you a list of the properties available to query... For example, if you want to check the URL of the page that's displayed, you could specify

Browser("Welcome: Mercury Tours").Page("Title:=Welcome: Mercury Tours").GetROProperty("url")

这当然会返回一个值,所以您要使用它来做某事...就像将其分配给一个变量

This, of course returns a value, so you want to do something with it... like assign it to a variable

result = Browser("Welcome: Mercury Tours").Page("Title:=Welcome: Mercury Tours").GetROProperty("url")

(如果执行此操作,则可以将变量结果"添加到监视列表中……这将回答您的问题.)

(If you do this, you can then add the variable "result" to the watch list... which answers your question.)

或直接在您的代码中对其进行检查

or examine it directly in your code

if Browser("Welcome: Mercury Tours").Page("Title:=Welcome: Mercury Tours").GetROProperty("url") = url_to_compare then DoSomething()

我希望这有助于清除您的理解:)

I hope this helps to clear up your understanding :)

这篇关于HP UFT中对象的建立和引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆