Wednesday, September 3

Why use Descriptive Programming (DP) in QTP

Isn't it a very frequently asked question in qtp - "why use DP over object repository"?

Here we will look into few scenarios where Descriptive Programming (DP) is more suitable to use then OR.

Scenario 1. - you need to count how many search result are returned when you search a particular search criteria. For example, you want to see how many
qtp/selenium/agile/java jobs are posted on a job portal in last 2 days! you then want to select all and apply.

Because you dont know in advance how many checkboxs will be there on search result, you cant use object repository.

Using DP (childobject), you can easily handle this scenario.

Scenario 2. - you are working on automation of an application where latest code is not deployed yet. To use OR, you must wait untill application is up and running. But if know the object descriptions, you can continue to create you automation scripts using DP.

Scenario 3. - your application is having 10 pages and every page has 2 same button i.e. "Previous Page" and "Next Page". So if use OR, it will add 2 objects for each page i.e. total 20 object for 10 pages. Instead of having 20 duplicate objects and making our OR unnecessarily 'bulky, we can simply write 2 DP objects.

Scenario 4. - Descriptive Programming is very useful for tricky objects like blotter grids, auto-hiding menus and embeded/nested objects and advanced string manipulations.

Scenario 5. - It might not sound a great example but suppose your qtp server is crashed and you can not open/access qtp OR for a while (1-2 days). If you use OR, you have wait until server is back, but you can continue to work if you use DP (advanced users).

Hope above are enough reasons to answer why to use DP at all!!

Click here to learn descriptive programming.

Please share your scenarios/views on this.

Friday, February 7

What are Object Models, COM, DOM, AOM, TOM in QTP - Part-1

Hello friends,

I am sure many of you must be having some questions/doubts about COM, DOM, AOM and TOM in QTP (like me!) .

Here in this post we will try to understand what are COM, DOM, AOM and TOM in QTP and how to use these to make our life easy (or may be tough!!).

Okay, so firstly what they stand for, just to quickly refresh.. :)

COM - Component Object Model
(examples:- Excel objects, FSO objects)

DOM - Document Object Model
(examples:- Browser("").Page("").object.getElementsByTagName)

AOM - Automation Object Model
(examples:- Createobject("quicktest.application"))

TOM - Test Object Model 
(examples:- concept how qtp manage AUT objects)

Above examples should give you a high-level idea of what exactly there are. Have you noticed that "Object Model" is common in all!
So let's look into this first before going forward.

As you know, whole concept of QTP and automation roam around objects and properties.

Object model, as the name suggests, is a model around the objects of various types. Conceptually it's like an API which provides a capability to perform operations using a set of properties and methods into the model. 

We are going to discuss 4 types of models in this post as mentioned above.

To be continued..

Thursday, January 9

How to download a file from a url using vbscript/QTP

Hello Friends!!

In this post, we will see how to download a file from url/internet to your local drive.

' Path of the file you want to download

strFileUrl = ""

'Local drive's path where you want to save the file
strSaveFileTo = "C:\xxxxxxx\yyyyyyyyy\\"

' create a XMLHTTP object

Set oHTTP = CreateObject("MSXML2.XMLHTTP") "GET", strFileUrl, False

'create FSO object
Set oFSO = CreateObject("Scripting.FileSystemObject")

'If  strSaveFileTo file already exist, delete it
If oFSO.FileExists(strSaveFileTo) Then
End If

If oHTTP.Status = 200 Then
  Dim oADOStream
  Set oADOStream = CreateObject("ADODB.Stream")
  With oADOStream
    .Type = 1
    .Write oHTTP.ResponseBody
    .SaveToFile strSaveFileTo
  End With
  set oADOStream = Nothing
End If

If oFSO.FileExists(strSaveFileTo) Then
  Print "File has been downloaded successfully and save to  " & strSaveFileTo
End If

Above code will save any file to your loacal drive at the given path. Now if the file is a ZIP file, you will need to extract it.

Below code will help you to pick any file from local and extract it's content to given folder

'Local drive's path where you want to Extract the file (in case file is a ZIP file)


'If tstrExtractFileTo path does not exist on local drive, create it
Set oFSO = CreateObject("Scripting.FileSystemObject")

If NOT oFSO.FolderExists(strExtractFileTo) Then
End If

'Extract the contants of the zip file.

Set oShell = CreateObject("Shell.Application")
Set strZIPFiles=oShell.NameSpace(strSaveFileTo).items

'release objects
Set oFSO = Nothing
Set oShell = Nothing