Buildup and reference of objects in HP UFT

≯℡__Kan透↙ 提交于 2019-12-12 03:28:36

问题


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

I have the following code:

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

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.

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 :/)


回答1:


Ok, well, your syntax is incorrect...

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.

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)...

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

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.

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.

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...

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

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 :)



来源:https://stackoverflow.com/questions/36789693/buildup-and-reference-of-objects-in-hp-uft

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!