userfuncjtions

Define a public function to accept user entered URL and saved it in an environment variable.

In Setup Action:
Environment.Value("userEnteredURL")= UserInputURL()

In PublicFunction library:
'@Description Accept user input URL
Public Function UserInputURL()
    UserInputURL=Inputbox("Please enter the URL you want to test.","Enter Testing URL","http://newtours.demoaut.com/")
End Function

String functions:
Define a function to get the file name

Public Function GetFileName(filepath)


Date functions:Define a function that returns current date in MMM DD YYYY format
Function f_FormatingDate(fDateMMMDDYYY)


 tDate = Date
  
 tMonth  = MonthName(Month(CDate(tDate)), true)
 tDay = Day(Date())
 tYear= Year(Date())

 If tDay  tDay="0"& tDay
 End If

 fDateMMMDDYYY = tMonth & " " & tDay & " " & tYear

end function


Define a function to ask user to select an excel datatable
Function f_OpenFileDialog(tpath,kDataTable)
 Set ObjFSO = CreateObject("UserAccounts.CommonDialog") 
 ObjFSO.Filter="ExcelFiles|*.xls"
 ObjFSO.FilterIndex = 1

 ObjFSO.InitialDir = tpath

 InitFSO = ObjFSO.ShowOpen 
 If InitFSO = False Then
  msgbox  "Cannot proceed without selecting DataTable."
  End If
 KDataTable = ObjFSO.FileName 
end function

Add a new folder:
  function f_AddNewFolder(path, folderName)
    Dim fso1, f, fc, nf
    Set fso1 = CreateObject("Scripting.FileSystemObject")
    Set f = fso1.GetFolder(path)
    Set fc = f.SubFolders
    If folderName "" Then
      If Not(fso1.FolderExists(path & folderName)) then
 Set nf = fc.Add(folderName)
      End If
    Else
    Set nf = fc.Add("New Folder")
    End If
  End function

 Const OverwriteExisting = TRUE
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 objFSO.CopyFile tFilePath  , "C:Temp", OverwriteExisting
   
    'Rename it by adding the run name
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 objFSO.MoveFile (tFileNamePath_inTemp) , (tNewFileNamePath )
 set objFSO = nothing

 Function f_CloseOpenBrowsers()

 For each Process in GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery ("select * from Win32_Process where Name='iexplore.exe'")
  Process.Terminate
 Next

登录后才可评论.