Skip to main content

Posts

Showing posts with the label Functions

Get All Function Names & Count From Library File(UFT\QTP\VBS)

sLibFile = "D:\Temp\\FunctionLibrary.txt" sResFile = "D:\Temp\Res.txt" Call  GetAllFuncNames(sLibFile,sResFile) Function GetAllFuncNames(sLibFile,sResFile)   On Error Resume Next Const ForReading = 1 Set oFso = CreateObject("Scripting.FileSystemObject") 'Open Txt File Set oTempFile = oFso.GetFile(sLibFile) Set oFile = oTempFile.OpenAsTextStream(1, true) sAllData = oFile.ReadAll oFile.Close Set oFile = Nothing Set oTempFile = Nothing If Instr(sAllData,"a")<= 0 Then Set oFile = oFso.OpenTextFile(sLibFile,1) sAllData = oFile.ReadAll oFile.Close Set oTempFile = Nothing Set oFile = Nothing End If aAllData = Split(sAllData,VBNewLine) 'Find Func Names For iCurRow = 0 To Ubound(aAllData) -1 sRowData = aAllData(iCurRow) sRowData = Cstr(Trim(sRowData)) If sRowData <> "" And Len(sRowData) >= 5 Then If (Instr(sRowData,"Function ") > 0 Or Instr(sRowData,"Sub ...

Files and Folders related Functions..

Files and Folders related Functions VBScript Runtime Properties Like the objects in the WSH core object model, VBScript runtime objects provide an extensive supply of properties. You can use the properties to view or change numerous file system attributes. These properties are listed here. · AtEndOfLine . Returns a value of either true or false depending on whether the file pointer precedes the TextStream file’s end-of-line marker. · AtEndOfStream . Returns a value of either true or false depending on whether the end of a TextStream file has been reached. · Attributes . Retrieves or sets file and folder attributes. · AvailableSpace . Retrieves the amount of free space available on a drive. · Column . Retrieves the current column position within a TextStream file. · CompareMode . Retrieves or sets the comparison mode used to compare a Dictionary object’s string keys. · Count . Returns a count of the items in a col...

FileSystemObject..

Managing Files and Folders As you have already seen this afternoon the FileSystemObject is actually fairly easy to work with. All that you have to do is establish an instance of it and you can start using its properties and methods. In the sections that follow you’ll see examples of how to use this object to create, copy, move, and delete files and folders. Copying Files Using the FileSystemObject object’s CopyFile() method you can copy one or more files. For example, you might want to copy all the files in the folder on your computer to a network drive at the end of each day. I’ll show you how to work with network drives this evening. For now let’s just focus on how the CopyFile() method works.The first step in copying a file is to set up an instance of the FileSystemObject. Then you can execute its CopyFile() method as shown here. Set fsoObject = CreateObject("Scripting.FileSystemObject") fsoObject.CopyFile("d:\ displayText.txt", "d:\myDocs\ displayText.t...

QTP Scripts examples...

1. Script for sending a mail using outlook express. Dim objOutlookMsg,objOutlook Set objOutlook = CreateObject(”Outlook.Application”) Set objOutlookMsg = objOutlook.CreateItem(olMailItem) objOutlookMsg.To = “” objOutlookMsg.CC = “ “ objOutlookMsg.BCC = “” objOutlookMsg.Subject = “test” objOutlookMsg.Body = “” objOutlookMsg.Attachments.Add “C:\Documents and Settings\Desktop\testreport.txt” objOutlookMsg.Send 2. Script for opening a Notepad file. In Expert view write a builtin funtion invokeapplication”c:/whatever the path” Run Dim a Set a = WScript.CreateObject (”WSCript.shell”) a.run “notepad.exe” Dim oShell Set oShell = CreateObject (”WSCript.shell”) oShell.run “cmd/notepad.exe” Set oShell = Nothing DsystemUtil.Run “Notepad.exe” 3. Script for connecting the oracle database public void connectDB() { Const adOpenStatic = 3 Const adLockOptimistic = 3 Const adUseClient = 3 Set objCon=CreateObject(”ADODB.Connection”) Set objRec=CreateObject(” ADODB.Recordset”) objCon.Open “DRIVER={Oracle i...

ExpandAllMenusFor Notepad

'=================================================================================== 'Function Name :ExpandAllMenusFor Notepad ' Created By :Jai ' Description : Expand all menuitems in the Notepad ' Created : Oct-16- 08 '=================================================================================== Function ExpandAllMenus() Window("regexpwndtitle:= Notepad").Activate With Window("regexpwndtitle:= Notepad").WinMenu("Menuobjtype:= 2") nTopMenuCount = .GetItemProperty("", "SubMenuCount") For i = 1 To nTopMenuCount sTopItemPath = .BuildMenuPath("", i) sTopItemLabel = .GetItemProperty(sTopItemPath, "Label") sReport = sReport + sTopItemLabel + vbNewLine bHasSubMenu = .GetItemProperty(sTopItemPath, "HasSubMenu") If bHasSubMenu Then ...

Test Setting in QTP

'Testsettings '-------------------------------- '=================================================== '' Function Name : Testsettings '' Created By : Jay '' Description : Configuring the Test settings ' Parameters :-- '' Created : 08 July 2008 '=================================================== Dim App 'As Application Set App = CreateObject("QuickTest.Application") App.Launch App.Visible = True App.Test.Settings.Launchers("Web").Active = False App.Test.Settings.Launchers("Web").Browser = "IE" App.Test.Settings.Launchers("Web").Address = "http://newtours.mercury.com " App.Test.Settings.Launchers("Web").CloseOnExit = True App.Test.Settings.Launchers("Windows Applications").Active = True App.Test.Settings.Launchers("Windows Applications").Applications.RemoveAll App.Test...

CreateImageFromClipBoard using QTP

'-------------------------------------------------------------------------' Method : CreateImageFromClipBoard' Author : Jai Purpose : It gets the clipboard image and convert as a image file.' Parameters: FileName - String, contains the BMP file name' iIndex - Integer, contains the Worksheet index' Returns : String. The replaced file name it gives.' Caller : - Nil' Calls : - Nil' ------------------------------------------------------------------------- Sub CreateImageFromClipBoard(sFileName) Dim wshShell,ShellReturnCode, sCmdExec Set WshShell = WScript.CreateObject("WScript.Shell") sCmdExec = "D:\autostuff\i_view32.exe /silent /clippaste /convert="& sFileName ShellReturnCode = WshShell.Run(sCmdExec, 1, True) End Sub