
Wednesday, October 7, 2009
Verify Whether DataBase is Exist or Not and if it's not Restore given Database in Data Base through QTP
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)
'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
strUserName = wshNetwork.UserName
msgbox strUserName
Wednesday, September 30, 2009
Find out all the drives including Caption,size from one machine
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_DiskDrive",,48)
For Each objItem in colItems
msgbox "Caption: " & objItem.Caption
msgbox "DeviceID: " & objItem.DeviceID
msgbox "Partitions: " & objItem.Partitions
msgbox "Size: " & objItem.Size
Next
Add all Recovery scenarios to new test through code
Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTestRecovery 'As QuickTest.Recovery ' Declare a Recovery object variable
Dim intIndex ' Declare an index variable
' Open QuickTest and prepare objects variables
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application
objectqtApp.Launch ' Start QuickTest
qtApp.New ' Open a new test
qtApp.Visible = True ' Make the QuickTest application visible
Set qtTestRecovery = qtApp.Test.Settings.Recovery ' Return the Recovery object for the current test
If qtTestRecovery.Count > 0 Then ' If there are any default scenarios specified for the test qtTestRecovery.RemoveAll ' Remove them
End If
' Add recovery scenarios
qtTestRecovery.Add "C:\Recovery.qrs", "ErrMessage", 1 ' Add the "ErrMessage" scenario as the first scenario
qtTestRecovery.Add "C:\Recovery.qrs", "AppCrash", 2 ' Add the "AppCrash" scenario as the second scenario
qtTestRecovery.Add "C:\Recovery.qrs", "ObjDisabled", 3 ' Add the "ObjDisabled" scenario as the third scenario
' Enable all scenarios
For intIndex = 1 To qtTestRecovery.Count ' Iterate the scenarios
qtTestRecovery.Item(intIndex).Enabled = True ' Enable each Recovery Scenario (Note: the 'Item' property is default and can be omitted)
Next
' Enable the recovery mechanism (with default, on errors, setting)
qtTestRecovery.Enabled = True
'Ensure that the recovery mechanism is set to be activated only after errors
qtTestRecovery.SetActivationMode "OnError"
'OnError is the default, the other option is "OnEveryStep".
Set qtApp = Nothing ' Release the Application object
Set qtTestRecovery = Nothing ' Release the Recovery object