Custom Search

Wednesday, October 7, 2009

What is Quick Test Professional Tool ?http://qtpfaq.wordpress.com/category/new-qtp-9x/

http://qtpfaq.wordpress.com/category/new-qtp-9x/

Basic(ASP, Visual Basic, VBScript, etc...)

//http://home.att.net/~gobruen/progs/basic/index.html#vbs

Verify Whether DataBase is Exist or Not and if it's not Restore given Database in Data Base through QTP

'Variable Declaration
Option Explicit
Dim Dsn_conn , rs , oServer , strServer,strUid,strQry , strDBName , fso, msg , FileStatus
Dim objConnection , oRestore ,SQLDMORestore_Database , strFilePath , strActualPath
' Action parameters
strServer=parameter("Server")''''' Server Name where SQL is Running
strUid=parameter("Uid") '''''' User Id which have permissions to logon SQL
strDBName=Parameter("DBName") '''' DB Name which DB you have to Restore
strFilePath=Parameter("FilePath") '' Path of the DB file
Set objConnection=Createobject("ADODB.Connection")
Dsn_conn= "DRIVER=SQL Server;SERVER="&strServer&";UID="&strUid&";APP=QuickTest
Professional;WSID="&strServer&";Trusted_Connection=Yes"
objConnection.Open(Dsn_conn)
If err.number <> 0 Then
Reporter.ReportEvent 1 ,"DBConnection","Unable to Connect to the database"&"Err Description = " & err.Description
Else
Reporter.ReportEvent 0 ,"DBConnection","Connection Succeeded"
End If
Set rs=CreateObject("ADODB.RecordSet")
' Verify whether Data base is Exist or not
strQry = "if not exists(select * from sys.databases where name = 'selftest') create database selftest"
Set rs=objconnection.execute(strQry)
'rs.Close
objConnection.Close
' Verify whether DB File is Exist in C Drive or not
strActualPath="C:\selftest.bak"
FileStatus=ReportFileStatus(strActualPath)
Function ReportFileStatus(filespec)
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = "True"
Else
msg = "False"
End If
ReportFileStatus = msg
set fso=nothing
End Function
' Copy the DB File From given path to C Drive
If Filestatus="True" Then
Call RestoreDBFromFile(strServer,strDBName,strActualPath)
Else
Set fso = CreateObject("Scripting.FileSystemObject")
fso.copyFile strFilePath,"C:\"
FileStatus=ReportFileStatus(strActualPath)
If Filestatus="True" Then
Reporter.ReportEvent 0,"Data Base File"," Is Copied"
Call RestoreDBFromFile(strServer,strDBName,strActualPath)
Else
Reporter.ReportEvent 1,"Data Base File"," Is Not Copied"
End If
End If
' Delete DB File From C Drive
DeleteAFile(strActualPath)
Sub DeleteAFile(filespec)
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile(filespec)
End Sub
Sub RestoreDBFromFile(ServerName , DBName , BackupToRestore )
'simple err checking
If ServerName = "" Or DBName = "" Or BackupToRestore = "" Then
Reporter.ReportEvent 1,"DB Connection ", "You MUST provide server name, database name, and the name of the bak file you want to restore"
Exit Sub
End If
'open connection to server
Set oServer =CreateObject("SQLDMO.SQLServer")
With oServer
.LoginSecure = True
.Connect ServerName
End With
'also need a restore object
Set oRestore = CreateObject("SQLDMO.Restore")
With oRestore
.Database = DBName
.Action = SQLDMORestore_Database
.ReplaceDatabase = True
.Files = BackupToRestore
.SQLRestore oServer
End With
Set oRestore = Nothing
oServer.DisConnect
Set oServer = Nothing
Reporter.ReportEvent 0,"Data Base","Data Base is Restored with Name : "&DBName
End Sub

how to get the column values and column header through QTP from Infragistics UltraGrid(If Applications are developed using Net advantage Controls)

rowcount=WpfWindow("Eclipsys Gateway My").SwfWindow("Custom View").SwfTable("grFilter").GetNAProperty("Rows.Count")
'Then to access each row:
For I = 0 TO rowcount-1
Set currentRow = WpfWindow("Eclipsys Gateway My").SwfWindow("Custom View").SwfTable("grFilter").GetNAProperty("Rows["+CSTR(I)+"]")
' To get a specific cell text for the current row
cellText =WpfWindow("Eclipsys Gateway My").SwfWindow("Custom View").SwfTable("grFilter").GetNAProperty("Rows["+CSTR(I)+"].Cells[3].Text")
msgbox cellText
Next

iColIndex = 2
strColKey = "value"
SET grid = WpfWindow("Eclipsys Gateway My").SwfWindow("Custom View").SwfTable("grFilter")
msgbox grid.GetNAProperty("DisplayLayout.Bands[0].Columns["+CSTR(iColIndex)+"].Header.Caption")
msgbox grid.GetNAProperty("DisplayLayout.Bands[0].Columns["+strColKey +"].Header.Caption")

How to find the Network UserName

Set wshNetwork =CreateObject( "WScript.Network" )
strUserName = wshNetwork.UserName
msgbox strUserName