Monday, April 21, 2008

QTP Code Generate Random String

Function GetRandomString (ByVal strLength)
Dim i, strRand
Const sChr ="a"
Randomize
For i = 0 To strLength-1
strRand = strRand + Chr(Asc(sChr) + Rnd() * 25 )
If i = 0 Then
strRand = Ucase(strRand)
End If
Next
GetRandomString = strRand
End Function
'Ex: To get a random string with 5 characters use following call
Print GetRandomString (5)

Sunday, April 20, 2008

How to restore GRUB?

How to restore GRUB, When do you want to restore GRUB?
Take an example: You have dual boot system Windows OS and Linux. Somehow if you need to reinstall Windows OS it will overwrite the boot loader. So next time you boot to your system you won’t be able to boot into Linux.
How to fix the problem?
First you need to switch to Linux using live Linux CD, Then issue following command:
Open Terminal and logged in using root
#grub
grub>find /boot/grub/stage1
(hd0, x) ex: (hd0, 2)
grub>root (hd0, 2)
grub> setup (hd0)
quit
Reboot the system and you will able to log in into the Linux OS

Saturday, April 12, 2008

QTP DB2 connection using ODBC

Requirements: IBM DB2 ODBC Driver
Function DB2Connect ()
DB2ConnStr = "Provider=IBMDADB2.1; Database=HSAPSETS; Hostname=DB2Host; Schema=Schema;Protocol=TCPIP; Port=50004; Uid=Db2user; Pwd=Db2Pass"
Set DB2Cn = CreateObject("ADODB.Connection") 'Create Object ADODB Connection
With DB2Cn
.CursorLocation = 3 : .ConnectionString = DB2ConnStr : .Open
End with
End Function

Wednesday, April 9, 2008

QTP XML Parser

How to parese XML imported from QTP repository?
Dim XMLNode, XMLFile
XMLFile = "C:\QTPObj.xml"
Set XMLNode = XMLUtil.CreateXMLFromFile(XMLFile).GetRootElement()
Function xmlParse(ByVal nodeName)
Dim Attrib, Node, firstChild, intX, intY
Set Attrib = nodeName.Attributes()
Set Node = nodeName.ChildElements ()
If nodeName.ElementName () = "qtpRep:Object" Then
If Attrib.Count = 2 Then
Print Attrib.Item(1).Value & "(" & Attrib.Item(2).Value &")."
End If
End If
'Get Childnode
For intX = 1 To Node.Count
Set firstChild = Node.Item(intX)
xmlParse firstChild
Next
End Function
'Parse the XML data
MatchData XMLNode