Pages

Monday, March 16

File Handling in QTP - Part 1


Hello Friends!

In this post, we'll see how to handle files using vbscript in QTP.
We'll cover -

  • How to create new file and write data
  • How to open existing file and read data
  • How to open existing file and append data
  • How to delete an existing file

Okie... so lets talk about File System Object (FSO) first. Actually all these things will be done using FSO only!


What is File System Object (FSO)?

File System Object is used to -

1.  creation, manipulation and deletion of text files
2. create, move and Delete folders on hard disk


FSO is the short name for  File System Object.  The FSO Object Model has a rich set of properties, methods and events to process folders and files.

How to create a file?

yeah.. here we go!

Suppose you want to create a file called "myFile.txt" on C:\ drive

Dim objFSO, file_path
file_path = "C:\myFile.txt"

Function CreateFile(file_path)
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set CreateFile = objFSO.CreateTextFile(file_path, True)
End Function

Call CreateFile("C:\myFile.txt")

And it's done! Hunt your C:\ drive.... myFile.txt will be there!

Ggrayyyytt!!

Now, look at this part..

objFSO.CreateTextFile(file_path, True)
objFSO - is an object of type FileSystemObject
CreateTextFile - is a method of FSO
file_path - is the path/location of you file
True - true means - if the file is already there, it will be overwritten.

You can write False also. In that case if file is already there, it'll not be overwritten, and it'll give you following error.




To test this, follow these steps.... n picture'll be clear to you!
  • run the above code
  • open the file and write your name, save and close
  • run the above code again (same)
  • open the file and see- your name will not be there because it's overwritten
  • now change this line in above code and run again.
  • Set CreateFile = objFSO.CreateTextFile(file_path, False
  • this time you will get the error because file is already there and because of False, it will not be overwritten.


Tired?? 

No worries!! In next part of this post, we will reveal all the methods of FSO.

In case of any queries, please post your comments.

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