You are on page 1of 12

'Adding background color:

On error resume next


Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add
Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.SetBackgroundPicture "D:\baby.JPEG"
********************************************************************************
********************************************************************************
********************************************************************************
***********************
Getting bitmap:
systemutil.Run "http:\\www.gmail.com"
browser("name:=Gmail: Email from Google").page("title:=Gmail: Email from Google"
).webedit("name:=Email","html.id:=Email").Set "subhaparthi"
Browser("name:=Gmail: Email from Google").page("title:=Gmail: Email from Google"
).webedit("name:=Passwd","width:=143").Set "gaterd"
Browser("name:=Gmail: Email from Google").page("title:=Gmail: Email from Google"
).Webbutton("name:=Sign in").Click
Browser("name:=Gmail: Email from Google").page("title:=Gmail: Email from Google"
).CaptureBitmap "D:\Errorr.bmp",True
x="D:\Errorr.bmp"
reporter.ReportEvent micDone,"The bitmap","of password error message is", x
********************************************************************************
********************************************************************************
********************************************************************************
***********************
Border in excel:
Const s = 1
Const q = 1
Set a = CreateObject("Excel.Application")
a.Visible = True
Set b = a.Workbooks.Add()
Set c = b.Worksheets(1)
k = 1
For i = 1 to 5
For j = 1 to 5
c.Cells(i,j) = k
k = k + 1
Next
Next
c.UsedRange.Borders(5).LineStyle = s
c.UsedRange.Borders(5).Color = RGB(255, 199, 0)
c.UsedRange.Borders(5).Weight = q
********************************************************************************
********************************************************************************
********************************************************************************
***********************
'catching the text to the result excel
datatable.AddSheet("subhasri")
datatable.ImportSheet "E:\catch.xls","sheet1","subhasri"
h=datatable.Getsheet("subhasri").GetRowCount
For i=1 to h
datatable.GetSheet("subhasri").SetCurrentRow(i)
systemutil.Run "C:\Program Files\HP\QuickTest Professional\samples\fl

ight\app\flight3a.exe"
a=datatable.Value("Agentname",3)
b=datatable.Value("Password",3)
c=datatable.Value("DOF",3)
d=datatable.Value("Flyfrom",3)
e=datatable.Value("Flyto",3)
f=datatable.Value("Name",3)
g=datatable.Value("Ticket",3)
x=len(a)
y=len(b)
If (x>3 and x<11) Then
If (y>3 and y<11) Then
If (b="mercury") Then
window("text:=Login").Winedit("attached text:=Agent Name:").Set a
window("text:=Login").Winedit("attached text:=Password:").Set b
window("text:=Login").WinButton("text:=OK").Click
Status="pass"
Pop="login successful"
window("text:=Flight Reservation").WinObject("attached text:=Date of Fl
ight:","nativeclass:=MSMaskWndClass").Type c
window("text:=Flight Reservation").Wincombobox("attached text:=Fly From
:","nativeclass:=ComboBox").Select d
window("text:=Flight Reservation").Wincombobox("attached text:=Fly To:"
,"nativeclass:=ComboBox").Select e
window("text:=Flight Reservation").Winbutton("text:=FLIGHT").Click
window("text:=Flight Reservation").Dialog("text:=Flights Table").Winbut
ton("text:=OK").Click
window("text:=Flight Reservation").winedit("attached text:=Customer Nam
e:","nativeclass:=Edit").Set f
window("text:=Flight Reservation").winedit("attached text:=Tickets:","n
ativeclass:=Edit").Set g
window("text:=Flight Reservation").Winbutton("text:=&Insert").Click
window("text:=Flight Reservation").Close
else
window("text:=Login").Winedit("attached text:=Agent Name:").Set a
window("text:=Login").Winedit("attached text:=Password:").Set b
window("text:=Login").WinButton("text:=OK").Click
Pop=Dialog("text:=Login").Dialog("text:=Flight Reservations").Static("t
ext:=Incorrect password. Please try again").GetROProperty("text")
Dialog("text:=Login").Dialog("text:=Flight Reservations").winbutton("te
xt:=OK").Click
window("text:=Login").WinButton("text:=Cancel").Click
Status="fail"
End If
else
window("text:=Login").Winedit("attached text:=Agent Name:").Set a
window("text:=Login").Winedit("attached text:=Password:").Set b
window("text:=Login").WinButton("text:=OK").Click
Pop=Dialog("text:=Login").Dialog("text:=Flight Reservations").Static("t
ext:=Password must be at least 4 characters long").GetROProperty("text")
Dialog("text:=Login").Dialog("text:=Flight Reservations").winbutton("te
xt:=OK").Click
window("text:=Login").WinButton("text:=Cancel").Click
Status="fail"
End If
else
window("text:=Login").Winedit("attached text:=Agent Name:").Set a

window("text:=Login").Winedit("attached text:=Password:").Set b
window("text:=Login").WinButton("text:=OK").Click
Pop=Dialog("text:=Login").Dialog("text:=Flight Reservations").Static("t
ext:=Agent name must be at least 4 characters long.").GetROProperty("text")
Dialog("text:=Login").Dialog("text:=Flight Reservations").winbutton("te
xt:=OK").Click
window("text:=Login").WinButton("text:=Cancel").Click
Status="fail"
End If
datatable.Value("Status",3)=Status
datatable.Value("Popup",3)=Pop
Next
datatable.Export "D:\run.xls"
datatable.DeleteSheet(3)
********************************************************************************
********************************************************************************
********************************************************************************
***********************
'Copies the content from file catch and pastes it in book1 file in A1 colunm
Set a=createobject("Excel.Application")
a.Visible=True
set b=a.Workbooks.Open ("E:\catch.xls")
set c=a.Workbooks.Open ("E:\Book1.xls")
b.Worksheets("sheet1").UsedRange.copy
wait(10)
c.Worksheets("sheet1").Range("A1").Pastespecial -4163
********************************************************************************
********************************************************************************
********************************************************************************
***********************
Creating a text file and writing into it:
Set a=createobject("scripting.filesystemobject")
Set b=a.CreateTextFile("E:\Subhaasri.Txt")
b.Close
Set z=Createobject("scripting.filesystemobject")
Set c=z.OpenTextFile("E:\Subhaasri.txt",2,True)
c.WriteLine "hello"
c.WriteLine "subha"
c.WriteLine "udhayas"
c.WriteLine "jaya"
********************************************************************************
********************************************************************************
********************************************************************************
***********************
Using database connection:
Dim conobj,comobj,rc,namee,Mobile,Email,i
Set conobj=createobject("ADODB.Connection")
conobj.Open "Provider=Microsoft.jet.oledb.4.0;Data Source=D:\hearty\ramesh.mdb"
Set comobj=Createobject("ADODB.Command")
comobj.ActiveConnection=conobj
datatable.ImportSheet "D:\hearty\login.xls","sheet1",1
rc=datatable.GetSheet(1).GetRowCount
For i= 1 to rc
datatable.GetSheet(1).SetCurrentRow(i)
agentname=Datatable.Value("agentname",1)
password=datatable.Value("password",1)

dof=Datatable.Value("dof",1)
flyfrm=datatable.Value("flyfrm",1)
flyto=Datatable.Value("flyto",1)
passen=datatable.Value("passen",1)
tickets=datatable.Value("tickets",1)
comobj.CommandText="INSERT INTO login VALUES ('"&agentname&"','"&password&"
','"&dof&"','"&flyfrm&"','"&flyto&"','"&passen&"','"&tickets&"')"
comobj.Execute
Next
datatable.DeleteSheet(1)
conobj.Close
Set conobj=Nothing
Set comobj=Nothing
'Get the value from database and run the login
Set conobj=createobject("ADODB.Connection")
conobj.Open "Provider=Microsoft.jet.oledb.4.0;Data Source=D:\hearty\ramesh.mdb"
Set rsobj=createobject("ADODB.recordset")
rsobj.Open "select * from login",conobj
rsobj.MoveFirst
While not rsobj.EOF
uid=rsobj("agentname")
pwd=rsobj("password")
dof=rsobj("dof")
ff=rsobj("flyfrm")
ft=rsobj("flyto")
paname=rsobj("passen")
tick=rsobj("ticket")
a=len(uid)
b=len(pwd)
systemutil.Run"C:\Program Files\HP\QuickTest Professional\samples\flight\ap
p\flight4a.exe"
If a>3 and a<11 Then
If b>3 and b<11 Then
If pwd="mercury" Then
Dialog ("text:=Login").Activate
Dialog ("text:=Login").Winedit ("attached text:=Agent Name:").se
t uid
Dialog ("text:=Login").Winedit ("attached text:=Password:").Set pwd
Dialog ("text:=Login").winbutton ("text:=OK").Click
else
Dialog ("text:=Login").Winbutton ("text:=cancel").Click
End If
else
Dialog ("text:=Login").Winbutton ("text:=cancel").Click
End If
else
Dialog ("text:=Login").Winbutton ("text:=cancel").Click
End If
rsobj.MoveNext
Wend
rsobj.Close
conobj.Close
Set rsobj=Nothing
Set conobj=Nothing
********************************************************************************
********************************************************************************

********************************************************************************
***********************
deleting a particular row in a excel sheet:
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Open("E:\Book1.xls")
i = 1
'Do Until objExcel.Cells(i, 1).Value = ""
If objExcel.Cells(i, 1).Value = "delete" Then
Set objRange = objExcel.Cells(i, 1).Entirecolumn
objRange.Delete
'
i = i - 1
End If
i = i + 1
'Loop
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\\\\\\\\\\\\\\\\\\\\\
'
'Const xlDown = -4121
'
'Set objExcel = CreateObject("Excel.Application")
'objExcel.Visible = True
'Set objWorkbook = objExcel.Workbooks.Add()
'Set objWorksheet = objWorkbook.Worksheets(1)
'
'objWorksheet.Cells(1,1) = 1
'objWorksheet.Cells(2,1) = 2
'objWorksheet.Cells(3,1) = 3
'objWorksheet.Cells(4,1) = 4
'objWorksheet.Cells(5,1) = 5
'
'Set objRange = objExcel.Range("A1")
'objRange.End(xlDown).Activate
'
'intNewRow = objExcel.ActiveCell.Row + 1
'strNewCell = "A" & intNewRow
'objExcel.Range(strNewCell).Activate
********************************************************************************
********************************************************************************
********************************************************************************
***********************
'For complete flight reservation
a=datatable.Value("Agent",1)
msgbox a
b=datatable.Value("Password",1)
c=datatable.Value("Date_of_flight",1)
d=datatable.Value("Fly_from",1)
e=datatable.Value("Fly_to",1)
f=datatable.Value("Name",1)
g=datatable.Value("Tickets",1)
systemutil.run"C:\Program Files\HP\QuickTest Professional\samples\flight\app\fli
ght4a.exe"
If (b="Mercury")then
dialog("text:=Login").WinEdit("attached text:=Ag

ent Name:").Set a
dialog("text:=Login").WinEdit("attached text:=Pa
ssword:").Set b
dialog("text:=Login").WinButton("text:=OK").Clic
k
Window("text:=Flight Reservation").Activate
Window("text:=Flight Reservation").Winobject("at
tached text:=Date of Flight:","nativeclass:=MSMaskWndClass").Type c
Window("text:=Flight Reservation").wincombobox("
attached text:=Fly From:").Select d
Window("text:=Flight Reservation").wincombobox("
attached text:=Fly To:").Select e
x=Window("text:=Flight Reservation").WinButton("
text:=Flight").GetROProperty("enabled")
msgBox x
Window("text:=Flight Reservation").Winbutton("te
xt:=Flight").Click
'
Window("text:=Flight Reservation").Dialog("text:
=Flights Table").Winlist("attached text:=From").Select 1
Window("text:=Flight Reservation").Dialog("text:
=Flights Table").Winbutton("text:=OK").Click
Window("text:=Flight Reservation").WinEdit("atta
ched text:=Name:","nativeclass:=Edit").Set f
Window("text:=Flight Reservation").WinEdit("attached
text:=Tickets:","nativeclass:=Edit").Set g
Window("text:=Flight Reservation").WinRadioButton("t
ext:=Economy").Set
Window("text:=Flight Reservation").Winbutton("text:=
&Insert Order").Click
Window("text:=Flight Reservation").close
else
dialog("text:=Login").Winbutton("text:=cancel").Click
end if
********************************************************************************
********************************************************************************
********************************************************************************
***********************
'Get the value from database and run the login
Set conobj=createobject("ADODB.Connection")
conobj.Open "Provider=Microsoft.jet.oledb.4.0;Data Source=D:\hearty\ramesh.mdb"
Set rsobj=createobject("ADODB.recordset")
rsobj.Open "select * from login",conobj
rsobj.MoveFirst
While not rsobj.EOF
uid=rsobj("agentname")
pwd=rsobj("password")
dof=rsobj("dof")
ff=rsobj("flyfrm")
ft=rsobj("flyto")
paname=rsobj("passen")
tick=rsobj("ticket")
a=len(uid)
b=len(pwd)
systemutil.Run"C:\Program Files\HP\QuickTest Professional\samples\flight\ap
p\flight4a.exe"
If a>3 and a<11 Then
If b>3 and b<11 Then
If pwd="mercury" Then

Dialog ("text:=Login").Activate
Dialog ("text:=Login").Winedit ("attached text:=Agent Name:").se
t uid
Dialog ("text:=Login").Winedit ("attached text:=Password:").Set pwd
Dialog ("text:=Login").winbutton ("text:=OK").Click
else
Dialog ("text:=Login").Winbutton ("text:=cancel").Click
End If
else
Dialog ("text:=Login").Winbutton ("text:=cancel").Click
End If
else
Dialog ("text:=Login").Winbutton ("text:=cancel").Click
End If
rsobj.MoveNext
Wend
rsobj.Close
conobj.Close
Set rsobj=Nothing
Set conobj=Nothing
********************************************************************************
********************************************************************************
********************************************************************************
***********************
Getting data from notepad
dim x,y,a,b,q
Set a=createobject("scripting.filesystemobject")
set b=a.CreateTextFile("E:\sri.txt",1)
b.writeline "subha Mercury"
b.writeline "udhay Mercury"
b.close
Set x=createobject("scripting.filesystemobject")
Set y=x.OpenTextFile("E:\sri.txt",1)
While y.AtEndOfLine=False
z=y.Readline
msgbox z
q=split(z," ")
systemutil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\fl
ight3a.exe"
Dialog("Text:=Login").WinEdit("attached text:=Agent name:").Set q(0)
Dialog("Text:=Login").WinEdit("attached text:=Password:").Set q(1)
Dialog("Text:=Login").WinButton("text:=Ok").Click
Wend
********************************************************************************
********************************************************************************
********************************************************************************
***********************
getting links in notepad and xls using datatable method
on error resume next
Dim a,b,x,y,f,c
Set a=createobject("scripting.filesystemobject")
Set b=a.OpenTextFile("E:\Test.txt",2)
systemutil.Run "http://google.co.in"
Browser("title:=google").Page("title:=google").WebTable("text:=Advanced searchLa
nguage tools").WebEdit("name:=q").Set "Ko songs"
browser("title:=google").page("title:=google").webTable("text:=Advanced searchLa

nguage tools").Webbutton("name:=google search").Click


Set x=description.Create
x("micclass").value="Link"
Set y=browser("title:=google").Page("title:=ko songs - Google Search").ChildObje
cts(x)
msgBox y.count
For i=1 to y.count-1
f=y(i).getroproperty("text")
datatable.SetCurrentRow(i+1)
datatable.Value("Links",1)= f
b.writeLine f
Next
datatable.Export "E:\subhalinks.xls"
datatable.DeleteSheet(1)
********************************************************************************
********************************************************************************
********************************************************************************
***********************
handling multiple windows
On error resume next
Set a=Description.Create
a("micclass").value="Browser"
Set x=Desktop.ChildObjects(a)
msgbox x.count
For i=0 to x.count-1
z=inputbox("enter value")
y=x(i).getroproperty("hwnd")
Browser("hwnd:="&y).page("title:=google").webedit("name:=q").set z
Browser("hwnd:="&y).page("title:=.*").webbutton("name:=.*").click
Next
********************************************************************************
********************************************************************************
********************************************************************************
***********************
getting all the urls(src) of the img in a excel:
systemutil.Run "http://www.google.co.in/search?q=stlc&hl=en&biw=1024&bih=540&prm
d=ivns&source=lnms&tbm=isch&ei=aksbTpvYFeaTmQXZ1ejgCA&sa=X&oi=mode_link&ct=mode&
cd=2&ved=0CAsQ_AUoAQ"
Set img=description.Create
img("html tag").value="IMG"
Set allimg=browser("title:=.*").page("title:=.*").ChildObjects(img)
msgbox allimg.count
For i= 0 to allimg.count-1
datatable.SetCurrentRow(i)
x=allimg(i).getroproperty("src")
reporter.ReportEvent micDone,"The image url","is"&i &x
datatable.Value("imagelink",1)=x
Next
datatable.Export "C:\imagefsrc.xls"
datatable.DeleteSheet(1)
********************************************************************************
********************************************************************************
********************************************************************************
***********************
checking whether the 1st four chars are alpha and last four are numeric:

a="subha1234"
b=left(a,4)
msgbox b
c=isnumeric(b)
If c="False" Then
reporter.ReportEvent micPass,"The first four letters is alphabetic"," "
&c
else
reporter.ReportEvent micPass,"The first four letters is numeric"," " &c
End If
d=right(a,4)
msgbox d
e=isnumeric(d)
If e="False" Then
reporter.ReportEvent micPass,"The first four letters is alphabetic"," "
&e
else
reporter.ReportEvent micPass,"The first four letters is numeric"," " &e
End If
********************************************************************************
********************************************************************************
********************************************************************************
***********************
Function all(page,micclass)
Set a=description.Create
a("micclass").value=micclass
Set b=page.childobjects(a)
End Function
Function edit(page)
Set alledit=all(page,"WebEdit")
End Function
Function button(page)
Set allbutton=all(page,"WebButton")
End Function
Function links(page)
Set alllinks=all(page,"Links")
End Function
set page=Browser("name:=Google").Page("title:=Google")
Msgbox "The edit buttons are" & edit(page).count
Msgbox "The links are" & links(page).count
Msgbox "The buttons are" & button(page).count
********************************************************************************
********************************************************************************
********************************************************************************
***********************
Merging cells:
Set objExcel1 = CreateObject("Excel.Application")
objExcel1.Visible = True
objExcel1.Workbooks.Add
objExcel1.ActiveWorkbook.ActiveSheet.Cells(1, 1).Value = "Title of Of the three
columns"
objExcel1.ActiveWorkbook.ActiveSheet.Range("A1:C1").Merge
objExcel1.ActiveWorkbook.SaveAs "D:\hi.xls"
Set exobj=createobject("Excel.Application")
exobj.visible=True

exobj.workbooks.Add
exobj.ActiveWorkbook.Activesheet.cells(2,2).value="hi hell and welcome to"
exobj.activeworkbook.activesheet.Range("A2:D2").Merge
Set eob=createobject("Excel.Application")
eob.Visible=True
eob.Workbooks.Add
eob.ActiveWorkbook.ActiveSheet.cells(1,3).value="hello hello"
********************************************************************************
********************************************************************************
********************************************************************************
***********************
one excel to another:
Set a=createobject("Excel.Application")
a.Visible=True
a.Workbooks.Add
a.ActiveWorkbook.ActiveSheet.Cells(1,2).value="subha"
a.ActiveWorkbook.SaveAs "E:\hihi.xls"
Set b=createobject("Excel.Application")
b.Visible=True
b.Workbooks.Add
b.ActiveWorkbook.ActiveSheet.cells(2,3).value="udhaya"
a.ActiveWorkbook.ActiveSheet.UsedRange.copy
b.ActiveWorkbook.Activesheet.Range("D1").PasteSpecial -4123
********************************************************************************
********************************************************************************
********************************************************************************
***********************
pwd protect:
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = FALSE
Set objWorkbook = objExcel.Workbooks.Add
Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.Cells(1, 1).Value = Now
objWorkbook.SaveAs "C:\Scripts\Test.xls",,"%reTG54w"
objExcel.Quit
********************************************************************************
********************************************************************************
********************************************************************************
***********************
reversing a string
a="subhasri"
b = Len(a)
For i = 0 To Len(a) - 1
strOut = Mid(a, b - i, 1)
msgbox strOut
strTmp = strTmp & strOut
Next
msgbox strTmp
********************************************************************************
********************************************************************************
********************************************************************************
***********************
shell
systemutil.Run "http:\\google.co.in"
Set a=description.Create

a("micclass").value="Link"
Set b=Browser("name:=Google").Page("title:=Google").ChildObjects(a)
Set c= createobject("Wscript.shell")
For i=0 to b.count
msg=b(i).getroproperty("text")
msgtime="1"
msgtitle="Links"
c.Popup msg,msgtime,msgtitle
Next
********************************************************************************
********************************************************************************
********************************************************************************
***********************
links into a xls using external excel method:
on error resume next
Dim a,b,x,y,f,c
Set a= createobject("Excel.application")
Set b=createobject("Excel.sheet")
b.Application.visible=true
systemutil.Run "http://google.co.in"
Browser("title:=google").Page("title:=google").WebTable("text:=Advanced searchLa
nguage tools").WebEdit("name:=q").Set "Ko songs"
browser("title:=google").page("title:=google").webTable("text:=Advanced searchLa
nguage tools").Webbutton("name:=google search").Click
Set x=description.Create
x("micclass").value="Link"
Set y=browser("title:=google").Page("title:=ko songs - Google Search").ChildObje
cts(x)
'msgBox y.count
For i=0 to y.count-1
'
g=split(f," ")
a.ActiveSheet.cells(i,1).value=y(i).getroproperty("text")
b.saveas "E:xyz.xlsx"
Next
********************************************************************************
********************************************************************************
********************************************************************************
***********************
links into a excel:
on error resume next
Dim a,b,x,y,f,c
systemutil.Run "http://google.co.in"
Browser("title:=google").Page("title:=google").WebTable("text:=Advanced searchLa
nguage tools").WebEdit("name:=q").Set "Ko songs"
browser("title:=google").page("title:=google").webTable("text:=Advanced searchLa
nguage tools").Webbutton("name:=google search").Click
Set x=description.Create
x("micclass").value="Link"
Set y=browser("title:=google").Page("title:=ko songs - Google Search").ChildObje
cts(x)
msgBox y.count
For i=1 to y.count-1
f=y(i).getroproperty("text")
datatable.SetCurrentRow(i+1)
'
reporter.ReportEvent micPass,y(i).getroproperty("text"),""
datatable.Value("Links",1)=f
Next

datatable.Export "D:\Links.xlsx"
datatable.DeleteSheet(1)
********************************************************************************
********************************************************************************
********************************************************************************
***********************
********************************************************************************
********************************************************************************
********************************************************************************
***********************