Friday, March 14, 2014

QTP: Recording To Descriptive Programing Converter


The “Descriptive Programming Converter” utility as the name suggests , converts the recorded code into Descriptive Programming code.

It also gives you a proper commenting for each line of the recorded code and that too at click of a button.

Interesting....... ??

Find out how to do that:

It consist of two parts:


1. QTP script (This script is to be kept on C:\Converter of the machine : Currently Hard-coded , you may change it)
This script parses the recorded code and converts it into descriptive programming.

2. Initiate.Vbs (This file could be kept anywhere. It’s better to keep it on the Quick launch)
User is supposed to run this file after recording and script in QTP.
It will automatically ‘Print’ the recorded steps in descriptive programming.

Setup:

QTP Script
''''' Save the following script at C:\Converter with name Rec2Des using QTP

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Const ForReading = 1 
Set objFile = objFSO.OpenTextFile ("C:\Converter\Script.mts", ForReading) 

Quote  =""""

'Parses the code present in the MTS file
Do Until objFile.AtEndOfStream 
strNextLine = objFile.Readline 
b=""
Obj= Split(strNextLine," @@")
'ObjInt=Split(Obj(0),"")
Act=Split(Obj(0),".")
Action=Act(Ubound(Act))

Obj1=Split(Obj(0),".")
For i=0 to Ubound(Obj1)-1
a=Obj1(i)
If b="" Then
b=a
Else 
b=b&"."& a
End If

Next
fobj=Split(b,".")
Object=fobj(Ubound(fobj))

If instr(b,"") Then
CleanRow=Split(b,"")
b=CleanRow(1)
End If
'Print  b

Sloop=Split (b,".")

For i=0 to Ubound(Sloop)
For j=0 to Ubound(Sloop)-i
If ObjPart="" Then
ObjPart=ObjPart&Sloop(j)
Else
ObjPart=ObjPart&"."&Sloop(j)
End If
Next
ClassObj=Split(Sloop(Ubound(Sloop)-i),"(")

'Getting class of fragmented object
CObj=ClassObj(0)
ObjPass=ObjPart
ObjPart =""

Execute("Set theTestObject = " &ObjPass)

Set Props = theTestObject.GetTOProperties
PropsCount = Props.Count
For k = 0 To PropsCount -1
PropName = Props(k).Name
PropValue = Props(k).Value

If  CompletProp=""  Then
CompletProp=Quote & PropName & ":=" & PropValue & Quote
Else
CompletProp=CompletProp &","&Quote & PropName & ":=" & PropValue & Quote
End If

Next
'Print CompletProp
If FragElement="" Then
FragElement=CObj&"("&CompletProp&")"
Else   
FragElement=FragElement &"."&CObj&"("&CompletProp&")"
End If
If CompElem="" Then
CompElem=FragElement 
Else
CompElem=FragElement &"." &CompElem
End If
FragElement=""
CompletProp=""
Next
Print  "'"  &Action &" action applied on "& Object & " object"
Print CompElem&"."&Action
Print vbcrlf
CompElem =""

Loop 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Keep the following code as Initiate.Vbs (You can keep it on quick Launch for ease of use)

'Create the QTP App object
Set qtApp = CreateObject("QuickTest.Application") Loc = qtApp.Test.Location Loc1=Loc&"\Action1\Script.mts" Loc2=Loc&"\Action1\Resource.mtr" Loc3=Loc&"\Action1\ObjectRepository.bdb" set filesys=CreateObject("Scripting.FileSystemObject")
'Perform the file Copy filesys.CopyFile Loc1, "C:\Converter\" filesys.CopyFile Loc2, "C:\Converter\Rec2Des\Action1\" filesys.CopyFile Loc3, "C:\Converter\Rec2Des\Action1\" 'Open the test in read-only mode qtApp.Open "C:\Converter\Rec2Des", True 'Get the instance of the openedtest Set qtTest = qtApp.Test 'Run the test qtTest.Run

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Steps:
  1. Open QTP and start recording a script.
  2. Save the above recorded script at any desired location (Do not close it)
  3. Run Initiate.vbs File

No comments:

Post a Comment