Understanding windowstyle and windowextendedstyle properties in Uft/QTP

Hello Friends,

In this post, we will discuss about the two most unused window identification properties – windowStyle and WindowExtendedstyle.

Introduction
While automating Windows based applications, uft’s object spy will show two properties windowstyle and windowextendedstyle. Often when we don’t have any values for the properties like name or class or if we are not able to identify objects uniquely, we think about using these two properties. In my case, I really never used them before, because I have an habit of understanding things first. I searched Internet couple of times but I was unable to find anything.

Couple of years back I tried creating a framework for automating Windows based applications completely in C#.Net and while reading operating system structures I found two structures which are style and exstyle. I called the function on the window under test and got one value, next thing I did was to compare that value from the values obtained from uft’s object spy. It was 100 percent match. Good news is that i was able to complete the basic set of framework and these two properties played an very important role in that.

ObjectSypSnapShotForWindowStyleNWindowExtendedStyle

One of the important question is, why windowstyle property is available for all object types, and not just only for windows ? and the answer is, in terms of windows operating system, every object drawn or exist and running within the system is a window, with different properties and appearance, some are visible and some are not, and that’s the reason why we get window style property for check boxes, radio buttons or for different controls. In this post, i will refer all objects as windows.

What is style property?
As the name of the property suggests, it holds the bit level information about how an window will be displayed on the screen. The following information can be retrieved from style object.

1. window has border or not?
2. window is a child window?
3. window is disabled?
4. Can it overlap other windows while drawing?
5. Window is first control of group?
6. Is window maximized when initially loaded?
7. Is window a popup window?
8. Is window having a vertical or horizontal scroll bar?
9. Window has Maximize/Minimize Button?
10. Window has Menu?
11. Window can receive Focus?

Remember Window refer’s to all types of objects.

What is Extended Style property?
Extended style property will hold the bit level information about the following things

1.  Window accepts drag and drop?
2. Window title bar is having help button?
3. Window Reading order is left to right?
4. Is Window an MDI child?
5. Is Window Topmost window?

There are other interesting information which can be obtained using styles. Google for “Window styles and exstyles”

How to retrieve values from UFT’s windowstyle and windowextendedstyle properties?
The information is stored in bit level and hence we have to know, which bit is storing the information about what style,

Below is the table for the styles and their formal names, you can Google for a particular style with their formal name to get more information

Constants for WindowStyle

Constant name Constant Value Description
WS_BORDER 0x00800000L Window has border
WS_CAPTION 0x00C00000L Window has caption
WS_CHILD 0x40000000L Window is a child window
WS_DISABLED 0x08000000L Window is disabled
WS_HSCROLL 0x00100000L Window has Horizontal scroll bar
WS_VSCROLL 0x00200000L Window has vertical scroll bar
WS_ICONIC 0x20000000L Window was initially minimized
WS_MAXIMIZE 0x01000000L Window was initially maximized
WS_MAXIMIZEBOX 0x00010000L window has maximize button
WS_MINIMIZEBOX 0x00020000L Window has Minimize Button
WS_POPUP 0x80000000L Window is a popup window
WS_SIZEBOX 0x00040000L Window has a size box
WS_TABSTOP 0x00010000L Window can accept focus
WS_VISIBLE 0x10000000L Window was initially visible

 

Constants for Windowextendedstyle

Constant name Constant Value Description
WS_EX_ACCEPTFILES 0x00000010L The window accepts drag-drop files.
WS_EX_CONTEXTHELP 0x00000400L Windows title bar has question mark
WS_EX_LTRREADING 0x00000000L Windows test has Left to right reading order
WS_EX_RTLREADING 0x00002000L Windows test has right to left reading order
WS_EX_MDICHILD 0x00000040L Window is an MDI child window


Note:
The above constant values are in Hexadecimal, UFT will show long values, convert appropriately before performing operations.

Now, we have the information about the constants, we can use the constants like this,

For identifying if window accepts Focus or Tab stop is set

if WindowstylePropertyValueHere And WS_TABSTOP <> 0 then

Bitwise And operator will only return an non zero number if the particular bit is set.

Implementation
Open UFT and copy paste the following code in a new test

'Constant to check if the window has borders
Const WS_BORDER = &H00800000
'Will return Zero as Desktop does not have borders
Msgbox (Window("text:=Program Manager").GetROProperty("windowstyle") AND WS_BORDER)
'Will return a non zero value, because notepad will have borders
Msgbox (Window("text:=Untitled - Notepad").GetROProperty("windowstyle") AND WS_BORDER)

Now, open an new notepad, title of the notepad should be “Untitled – Notepad”, otherwise change the title in the code.

Run the code, it should display two message boxes, first with zero as it will not be able to find border around desktop and second non zero as code will be able to find border around Notepad window.

Now, you have an understanding about these two properties and how to use them, lets discuss a little about, when we can use these properties.

When to use?
When to use these properties is purely the decision of the test case developers, but there are few scenarios where you can utilize these properties,

1) WindowStyle property value can be used as it is when we know that actual programmers will not change any of the properties in future about the window appearance.
2) If, you cannot identify window uniquely, but there is a specific property within style or windowstyle properties which can be utilized, then you can use it to identify the correct window.

One last important thing is Some of the properties are available already within UFT like “hasborder” property for which i have demonstrated the code above, only few of them are not included, So use these properties when its absolutely necessary.

Let me know, if you have any questions.

Thanks,
Sumeet Singh Kushwah

Advertisements

5 responses to “Understanding windowstyle and windowextendedstyle properties in Uft/QTP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s