Oct
26
2008
--

Difference between IE6 and IE7

This article will take you over various differences between Internet Explorer 6 (IE6) and Internet Explorer 7 (IE7). These difference would be from QTP automation perspective

Difference #1 - Alert dialog title

IE6 alert dialog title is “Microsoft Internet Explorer” and for IE7 the alert dialog title is “Windows Internet explorer”

IE7 Alert dialog

IE7 Alert dialog


IE6 Alert dialog

IE6 Alert dialog

Both windows can be easily supported at the same time in QTP by using regular expression “(Windows|Microsoft) Internet Explorer”. The statement is true whether we use object repository or descriptive programming.

Difference #2 - Multiple Tab windows

IE7 supports multiple tabs. QTP 9.2 supports IE7 but with tabs setting disabled, QTP 9.5 supports testing IE7 with tabs also. So is there any other difference because of these tabs? Because if IE7 tabs QTP now identifies the each tab as a Browser and not the whole window as a Browser. The statement would become clear when we look at the below code

Maximizing IE6 Browser

Dim hwndBrw
hwndBrw = Browser("Browser").GetROProperty("hwnd")
Window("hwnd:=" & hwndBrw).Maximize

But when we run the same code in IE7 QTP throws below error

The operation cannot be performed error

The operation cannot be performed error

The reason for this error is that the handle of the window that we receive is not the main browser window handle but the sub window handle (TAB) which cannot be maximized. To receive the main window handle we would need to use Windows API

Dim hwndBrw, hwndWindow
hwndBrw = Browser("Browser").GetROProperty("hwnd")
 
Const GA_ROOT = 2
'Declare Function GetAncestor Lib "user32.dll" (ByVal hwnd As Long, ByVal gaFlags As Long) As Long
Extern.Declare micLong, "GetMainWindow", "user32" ,"GetAncestor",micLong, micLong
 
'Get the main IE window handle
hwndWindow = Extern.GetMainWindow(hwndBrw, GA_ROOT)
Window("hwnd:=" & hwndWindow).Maximize

Note: Above code will work on IE6 as well

Difference #3 - Certificate Security error

The way IE7 present certificate error is completely different from way IE6 does it

IE6 Certificate security error

IE6 Certificate security error


IE7 Certificate security error

IE7 Certificate security error

Handling the IE7 security error is as easy as it gets

If Browser("KnowledgeInbox").Page("IE7").Link("text:=Continue to this website \(not recommended\)\.").Exist Then
     Browser("KnowledgeInbox").Page("IE7").Link("text:=Continue to this website \(not recommended\)\.").Click
End If

or

If Browser("KnowledgeInbox").Page("IE7").Link("html id:=overridelink").Exist Then
    Browser("KnowledgeInbox").Page("IE7").Link("html id:=overridelink").Click
End If

These are 3 key differences IMO which needs to taken care of in case both IE6 and IE7 needs to be supported by QTP scripts.

Rating: 0.0/10 (0 votes cast)
Oct
26
2008
--

How to generate random test data?

At times it is required that we use unique test data for every single run of an automation script. For Ex – for testing a user registration page we would need a username which already does not exists in the database. Though there are various ways to overcome this unique username issue but we will see one which is the simplest one. The idea behind this is to use current date and time to generate a no. which we know would be unique. The function given below can be used to convert date and time into the random number we need

'Author: Tarun Lalwani
'Website: www.KnowledgeInbox.com
'Description: Generate random number using date
Function GetRandomNumberByDate()
	Dim curDate
	'Get the current date
	curDate = Now 
	GetRandomNumberByDate = Hour(curDate) & _
				Minute(curDate) & _
				Second(curDate) & _
				Day(curDate) & _
				Month(curDate) & _
				Year(curDate)
End Function
 
'Usage
'Msgbox GetRandomNumberByDate()

Note: The function can still generate same random numbers in case used on multiple machines where time is not in sync or both scripts get the time using Now function at the same time (slimmest possible chance of that happening)

Rating: 0.0/10 (0 votes cast)
Oct
05
2008
--

Identifying controls using labels - Approach 1

Identifying objects correctly and robustly in an application is very important in Automation. In case you have automated any CRM application you might have noticed objects are recognized by a dynamic name

Browser("Browser").Page("Page").WebEdit("TS_EXTRA_FEILD40").Set "AAA"

Now after a build the code or object might change to

Browser("Browser").Page("Page").WebEdit("TS_EXTRA_FEILD42").Set "AAA"

These object changes are unpredictable and cause scripts to fail. Let’s assume the field name to be ‘Product Name:’ in the CRM application. Digging into the HTML code we can see the HTML code specific to the product code label and text box would look like below

<LABEL for="TS_EXTRA_FEILD40">Product Name:</LABEL>
<INPUT id="TS_EXTRA_FEILD40" name="TS_EXTRA_FEILD40" >

The HTML preview of the same is shown below

Product Name:

Using the general way of recording will produce a high maintenance effort scripts, as the object repository would need to be updated every time. Code below demonstrates how to get object using it’s label and not the actual HTML name

'----------------------------------------------------------------
'Author: Tarun Lalwani
'Website: http://KnowledgeInbox.com
'Paremeters -
'@ParentObject - The parent object for which the control needs
'            to be retrieved
'@LabelName - Label for which you need to get the control
'@MicClass - Type of object (WebEdit, WebList etc...)
'----------------------------------------------------------------
Function ObjFromLabel(ByVal ParentObject, ByVal LabelName, ByVal MicClass)
   'Return Nothing in case of issue
  Set ObjFromLabel = Nothing
 
   Dim objLabel
   Set objLabel = ParentObject.WebElement("html tag:=LABEL","outertext:=" & LabelName)
 
    'Check if the label object exists
   If objLabel.Exist(0) Then
      Dim controlHTMLid
 
      'get the property specified in FOR atrribute of the tag
      'Test. Below works for IE
      controlHTMLid = objLabel.GetROProperty("attribute/htmlfor")
 
      'In case of firefox
      if controlHTMLid ="" then controlHTMLid = objLabel.GetROProperty("attribute/for")
 
      If controlHTMLid <> "" Then
         Execute "Set ObjFromLabel = ParentObject." & MicClass & "(""html id:=" & controlHTMLid & """)"
      End If
   End If
End Function
 
Dim oPg, oEdit
 
'The page object
Set oPg = Browser("Identifying controls using").Page("Identifying controls using")
 
'Get the webedit for 'Product Name:'
Set oEdit = ObjFromLabel(oPg ,"Product Name:","WebEdit")
 
'Set the value
oEdit.Set "Tarun Lalwani"

The approach discussed above uses descriptive programming to check for the label first and then gets the html id of the specific control mapped to it.

Rating: 9.3/10 (11 votes cast)
Sep
24
2008
--

General run error when clicking on button

General run error are hard to debug and any extra information available to fix the issue is always helpful. Sometimes QTP starts throwing General run error in click events of WebButton. Digging into the source of the issue using the technique mentioned in Debugging General run error we would see a “Element not found” error in the debug pane.

When you check exist on the button it would still return True but the click would throw a general run error. I have not been to formalize what causes this issue but there is a small dirty workaround to fix

Browser("Browser").Page("Page").WebButton("Login").Highlight
Browser("Browser").Page("Page").WebButton("Login").Click

Note: You should only use this workaround in case you are getting a general run error. This should never be used as a practice

Rating: 7.1/10 (7 votes cast)
Oct
26
2006
--

Review - Test Design Studio (TDS)

Test Design Studio (TDS) is enhanced IDE for WinRunner and QTP. It provides a Visual Studio style editor which provided enhanced code editing experience. This review will walk you through some of the key features of TDS

Solution
A solution allows you to group various types of files into one solution. This includes QTP, Winrunner, VBS, text, ini etc…

Expand/Collapse functions
The editor allows expanding and collapsing function into single lines.

Expand/Collapse function definition

Expand/Collapse function definition

Smart Indentation
The editor is smart to identify the indentation for current line. So if you are Typing “End Function” but are not at the same ident level as the function start then TDS will automatically decrease the indent level to match the function start.

Track Modification
Lines changed during current session can be tracked using the color code yellow(unsaved)/green(saved).

Split Windows
You split a window horizontally or vertically or both. This allows editing various parts of the file at the same time.

Vertically split window

Vertically split window

Enhanced Intellisense
TDS provides intellisense for almost everything. It provides intellisense for all QTP object even when the machine does not have QTP installed. This allows automation developers to easily code there scripts on any machine without being dependent on QTP. TDS also provides intellisense on COM libraries available to be used with the CreateObject function.

Lists COM Libraries available on the System

Lists COM Libraries available on the System

Using smart tags TDS allows you to quickly reference a library. Once reference is added to a library, intellisense is available for all objects present in the library

Reference Libraries using smart Tags

Reference Libraries using smart Tags

Intellisense for referenced libraries

Intellisense for referenced libraries

Other intellisense features:

  • Intellisense for QTP OR (only in case QTP 9.2 or higher installed on machine)
  • Intellisense for QTP OR using exported XML (QTP not required on the machine)
  • XML documentation for custom intellisense. This is really cool feature which makes coding even more fun.

Object Browser
Object Browser provides easy reference to all methods and properties available for a class/library in the current solution.

Object Browser

Object Browser

Quality Center Support

TDS allows adding different quality center servers. Once the server is added you can access any of the the projects to which you have access. TDS has following feature when working with QC

  • View/Modify the workflow scripts of project
  • View/Modify QTP, WinRunner, VBS, XML etc… files present in QC. Allows auto sync which updates the file on the QC server
  • Add reference to other file types which TDS does not support (excel files etc…)
  • Run multiple SQL Queries on project’s database tables and export results to excel
  • Active/Deactivate any project from within TDS (provided you have admin access) and few more admin related feature
  • Supports VCS (QC project should have VCS add-in installed)
  • Supports scripted Business Process Components
SQL Query on QC Project tables

SQL Query on QC Project tables

Inbuilt Browser
TDS provides an inbuilt tabbed browser window, which you can use browse websites

Why TDS and not QTP?
QTP IDE lacks many features and is no where near to being called a professional IDE for automation programmers. TDS helps bridge this gap and improve productivity of automation engineers. QTP licenses cost far more then a TDS licenses and most of the times not all QTP licenses are utilized simultaneously. Which gives a good reason to consider purchasing less licenses for QTP and investing in TDS licenses. Licensing information can be found here

Rating: 0.0/10 (0 votes cast)