Tuesday 24 April 2012

Bring your Test Data in QTP environment

This is continuation . . .

Okay,
Hear it goes

Well my Aim is to Bring an excel stored data into QTP Environment.

I hope you remember this figure . . .











Well this is the Screenshot of "GlobalData.xls", I have explained why did I named this excel as GlobalData.xls

Let's give this excel file an importance because whenever you script is going to start with execution, this file will play major role in term of Initializing your per-requisite of your Test.

Notice the column names "Key" and "Value", what I gonna tell you now, I think I gotcha!!!

I shall extract this data from excel using ADODB, then store that data into Dictionary Object and then make that Dictionary object as Environment Variable.


Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= & getGlobalDataxlsPath() & ";Extended Properties=""Excel 8.0;HDR=Yes;"";"
objRecordset.Open "Select * FROM [SheetName$]", objConnection


Now Since you've got the RecordSet, now it's time for Dictionary Object to come into picture

Set objDict = CreateObject("Scripting.Dictionary")
Do Until objRecordset.EOF
   objDict.Add objRecordset.Fields.Item("Key"),  objRecordset.Fields.Item("Value")
   objRecordset.MoveNext
Loop

Now let's make this Dictionary Object an Environment Variable.

Environment.Value("GlobalData") = objDict


From now on where ever you want you can use the Dictionary object stored in Environment, your reference code will be

strBasePath = Environment("GlobalData")("BasePath")

For more insight on referencing on Environment Variables click here

So folks,
I have shown you the code just for understanding the concept behind it, for codes google it out!!!


*getGlobalDataxlsPath()shall return the complete path of "GlobalData.xls" file, Since we need to achieve portability, the path shouldn't be the static one, I shall post later on the logic behind it.

Till Then Take Care . . .

-Pankaj Dhapola
Let's Think on it

Monday 23 April 2012

Automation Framework Architecture using QTP

Automation Framework Architecture using QTP

Every one knows about the different types of framework
I'm not going to explain you about these framework (Many Authors have done that), I would like to visualize you how you can start off with designing of your framework . . .
I'll try my best to share with clarity and understanding


Well first off all, you should make a mind map (or simply draw a DFD) of the structure of your framework, for example
1) The flow of input data from a storage into your application
2) How you will arrange the output of the application and display/store results?
3) How your execution of scripts would be arranged both locally and in QC?
4) How is your reporting and logger functionality will work?

All this questions definitely come after experience, but people with great Visualization would grasp it easily.

Now their are some aspects of any framework

1) Library files:- which is bundle of functions in .qfl, .vbs, and/or .txt files.
2) Test Data: - The required inputs in your application, which may be stored in excel(mostly), txt, CSV etc
3) Test Scripts: - A place where all Scripts are stored functional and sub functional wise.
4) Results:- A place where your application results/output will be generated. Note that this place can be different in QC and Local folder structure
5) Object Repository: - A place where Global OR is placed if any.
6) Recovery Scenario: - A place to store recovery scenario.
7) Re-Usable Actions: - A place to keep your re-usable actions, if any.

you may also have some other folder to include depending on project.

And now . . . Bundle these aspects under one roof, i.e your framework like below folder structure


Now the layout is ready, how do you let QTP know about these folder structure path, how will you keep this folder called "MyFramework" independent of a place, where-ever you put, it should run seamlessly, either in Company Shared Drive or your desktop, etc.

In short how will you make it Portable or keep integrity of relevant aspects intact.

I have a solution ("GlobalData.xls"), write down the path name of all this structure in an excel file.

See below screenshots.











The Cell formula for "BasePath" is
"=LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1)"

Now you might have question why did I Named this excel file as "GlobalData.xls"
I think I gotcha!!!

Put all your data which will be used across your script execution, the data which you would need persistent throughout your script execution like AUT URL, User-ID, Password, all function library file path, etc

See what is the advantage . . .
Put this folder wherever you want, your excel file keep the integrity of the Framework Structure path. I have seen some framework which have many configuration issues if it is migrated to another PC for execution, and time is lost while debugging.

I came up with this intact solution.

Up to me A framework should leverage Re-Usability and should be good in maintenance.

I will tell you how you will bring these data in your QTP "Environment" ;)

Taking about next thing . . . . .
LibraryFiles

What do you think about Managing Object Repository

What kind of Results/Logs do you Generate?

-Pankaj Dhapola