Saturday, July 19, 2008

Magic of temp in Automation

Hey,

All of earlier posts were not of my own writings, i just searched on net and extracted whatever i feel essential and useful for testers in automation.

Today is my turn to write my own experice in test automation.

Topic is use of temp folder/file in automation

At times we need to create temporary folders/files to store some intermediate data or content for computation during course of execution time.

Here is a simple scripts will be helpful in creating a folder or file as per your requirement.

Sysntax to use the below code: Call CreateTemp(folderorfilepath,folder/file)

E.g. To create a folder - Call CreateTemp("c:\temp\test\storetemp\","folder")
E.g. To create a file -Call CreateTemp("c:\temp\test\storetemp\storeresults.txt","file")

'******************************************************
' Name of the Function : CreateTemp
' Functionalty : To create a temporary folder/file
' Created By : Rajesh
' Created On : 19th July 08
' Input Parameter :
' 1. strPath: Path of the file system object (file/folder)
' 2. strFSO: Type of file system object. Possible values are FILE/FOLDER
' Return Value : NA
'********************************************************
Sub createtemp(strPath,strFSOType)
On Error Resume Next

Dim objFso 'ref object for file system

'Set referemce to file system object
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Verify the prvided path is not empty
If strPath <> "" Then 'Fixes endless recursion in some instances when at lowest directory

'verify for the provided folder heirarchy in the file system and create if not exists
If Not objFSO.FolderExists(objFSO.GetParentFolderName(strPath)) then Call createtemp(objFSO.GetParentFolderName(strPath),"FOLDER")


'Verify the last node is a folder or file
If UCase(strFSOType) = "FOLDER" Then
objFSO.CreateFolder(strPath)
ElseIf UCase(strFSOType) = "FILE" Then

'If the file is already exists delete it and create new one
If objFSO.FileExists(strPath) Then
objFSO.DeleteFile strPath,True
End If

objFSO.CreateTextFile(strPath)
Exit Sub
End If
End If

Set objFso = Nothing
End Sub


Please provide me your comments

2 comments:

Anonymous said...

What testing tool are you using?

Unknown said...

Nice job..please post some more scripts