开发者

What is the complete structure of the browser object in QTP?

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").Navig开发者_C百科ate("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".


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)

  1. Call a method of the test object. The list of methods supported by the test object can be found in QTP's documentation.
  2. A child of the test object from the object repository (or descriptive programming). This is the case in your sample. The children of Browser are almost always Page but Window or other objects can appear (depending on the application you're testing).

The Page test object represents the top level HTML document displayed in the Browser.

BTW, The code snippet you wrote is wrong. Page does not support the Navigate method, Browser does.


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.


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:

Browser("website")

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:

Browser("website").Page("Logon Page")

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:

Amazon.com
  Login Page
  Music Page
  Books Page
  Checkout Page
StackOverFlow.Com
  Login Page
    username field
    password field
  Questions Page
  Jobs Page
  Tags Page
  Users Page
  Badges page
etc etc...

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

  1. Browser and Page objects are part of QTP. QTP is providing this API to you, and you (touch it/use it/manipulate it) using VBScript. The Browser and Page classes to not exist outside of QTP.
  2. You can get the complete list of methods and properties available for the 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜