Home
Welcome to Automation section of Ultimate timepass
Here you can find lots of day to day useful automation code samples mainly related to VB script, VBA , Quicktest Professional and Test Partner.
You can also find good collection of automation code related to integration with various QA automation tools like Quality center, ALM and Microsoft test management etc.
Please select your desire section from below links.
Article related to Quicktest Professional (QTP) Web based automation:-
- Close Opened Browsers Except QC
- GET COUNT AND NAMES OF ALL OPEN BROWSERS
- Get No of links in a page- Descriptive programming
- Drag and Drop the files into application
- Function to click on menu (Mimic the user action)
- Function to display type ahead list in a dropdown
Article related to Excel automation with Quicktest Professional (QTP). These code could be used VBA applications also.
- Read Excel using ADODB connection
- To Delete Columns from a Excel sheet
- Delete Rows From excel sheet
- Excel sorting
- Save as a Password Protected Excel sheet
- Open a Password Protected excel and save as unprotected
- Find a value in Excel Sheet
- Create and update a excel File at given path
- To Query a Excel Sheet as a database
Articles related to XML automation with Quicktest Professional (QTP)
Articles related to VB script automation with Quicktest Professional (QTP)
- To type keyboard input onto the open window
- Set a default Printer
- To Verify an Application launch
- Create MS Word, Edit and Print a blank page
- Create a MS Access(.mdb) database file
- Import a XML file to MS Access database
- Connect to SQL Server
- Connect to MS Access DB
- Create a Text File at given path
- Read a text file and store data in a variable
- Get number of pages in pdf
Connect to SQL Server
Connection string fro SQL Server, use following code:
Steps:
1) Create an ADODB connection with provider as "sqloledb"
2) Open database connection
Code:
'Connect to SQL Server
'==============================================
Function Create_SQL_Connection(DataSource,Ini_catalog)
'1) Create an ADODB connection with provider as "sqloledb"'
set SQLcon= CreateObject( "ADODB.Connection")
SQLcon.ConnectionString = "Provider='sqloledb';Data Source='" & DataSource & "';" & _
"Initial Catalog='" & Ini_catalog & " ';Trusted_Connection=YES"
'2) Open database connection'
SQLcon.Open
End Function
Make a message alert with ding sound using Microsoft Office assistant popup
Make a message alert with ding sound using Microsoft Office assistant popup, use following code:
Code:
strAgentName = "MERLIN"
strAgentPath = "C:\Windows\Msagent\Chars\" & strAgentName & ".acs"
Set objAgent = CreateObject("Agent.Control.2")
objAgent.Connected = TRUE
objAgent.Characters.Load strAgentName, strAgentPath
Set objPeter = objAgent.Characters.Character(strAgentName)
objPeter.MoveTo 500,300
objPeter.Show
objPeter.Play "GetAttention"
objPeter.Play "GetAttentionReturn"
objPeter.Speak("You got a message, script provided by Automation.ultimatetimepass.com")
Wscript.Sleep 2000
Set objAction= objPeter.Hide
Do While objPeter.Visible = True
Wscript.Sleep 250
Loop
Kill a task manager process
To Kill a task manager process , use following code:
Steps:
1) Get an object from winmgmts root\CIMV2
2) Execute SQL to retrieve all process from process
3) Kill all process
Code:
Dim objWMIService, colItems,OSname,strComputer
strComputer = "."
strProcessToKill="Winword.exe"
'1) Get an object from winmgmts root\CIMV2'
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'2) Execute SQL to retrieve all process from process
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & strProcessToKill & "'")
'3) Kill all process'
For Each objProcess in colProcessList
objProcess.Terminate()
Next