21-02-2008
1. Swap 2 numbers with out temporary variablea=cint(inputbox("Enter the value of a to swap:"))b=cint(inputbox("Enter the value of b to swap:"))print "Value of a&b befor swaping:"&vbnewline&"a="&a&vbnewline&"b="&ba=a+bb=a-ba=a-bPrint "Value of a&b after swapping:"&vbnewline&"a="&a&vbnewline&"b="&b
2. Print prime numbersa=cint(inputbox("Enter the starting range of no.:"))b=cint(inputbox("Enter the ending range of no.:"))For i= a to b
For j= 2 to i-1If i mod j=0 Thenflag=1Exit for
End IfNext
If flag=0 Thenprint(i)
End If flag=0Next
3. Print the data in triangle shapestr=inputbox("Enter the string:")l=len(str)j=0For i=l to 1 step -1
j=j+1tri=mid(str,1,j)print space(i)&tri
Next
4. Sort Array elementsa=array(100,10,50,40,80,30)For j=lbound(a) to ubound(a)-1
For k=lbound(a) to ubound(a)-1If a(k)<a(k+1) Then '(a(k)>a(k+1) to sort in asecnding order)temp=a(k)a(k)=a(k+1)
a(k+1)=tempEnd If
NextNextFor i=lbound(a) to ubound(a)
print(a(i))Next
5. Find a character in a stringstr=inputbox("Enter the string to test:")ch=inputbox("Enter the character to find:")print "Entered String is:"&" "&strprint "Expected Character is:"&" "&chl=len(str)print "Length of the string is:"&" "&lx=0For i=1 to l
expe=mid(str,i,1)x=x+1If expe=ch Thenprint "Position of the character in a given string:"&" "&iEnd If
Next
66.Find a character in a string
Dim str(25)str(25)=inputbox("enter the string")ch=inputbox("enter the character that has to be counted")n=len(str)For i=0 to n-1if ch=str(i) thenCount+1end if Nextprint(Count)
6. Convert string to Upper Casestr=inputbox("Enter the string to convert:")constr=ucase(str)print constr
7. Returning Character specific to ASCII valuechval=inputbox("Enter the ASCII value to find the character:") '(Any no 1 to 256)char=chr(chval)print char
8. Display current date and Timecurdatentime=nowprint curdatentime
9. Finding difference between 2 dates.mydate1=cdate(inputbox("Enter the starting date(mm/dd/yyyy):"))mydate2=cdate(inputbox("Enter the starting date(mm/dd/yyyy):"))difference=datediff("yyyy", mydate1, mydate2)print difference
10. Converting an array to stringDim a(4)For i=0 to 4a(i)=inputbox("Enter the string:")Nextprint "The String is:"&" "&join (a)
11. Replace space with tab in between the words of a string.str=inputbox("Enter the string:")wordtorepl=inputbox("Enter the word to be replaced:")print "Given string is:"&" "&strprint "Word to be replaced is:"&" "&wordtoreplreplstr=replace(str, wordtorepl, vbtab)print replstr
12. Replace a word in a string with other wordstr=inputbox("Enter the string:")word=inputbox("Enter the word to be replaced:")repword=inputbox("Enter the replacing word:")print "Given string is:"&" "&strprint "Expected word to be replaced is:"&" "&wordprint "Replacing word:"&" "&repwordrepstr=replace(str, word, repword)print repstr
13. Create your own Class and ObjectClass Testing ‘(Create a class) Function JTP() ‘(Create one function under that)
Print "How is your experience in JTP" End FunctionEnd ClassSet obj=new Testing ‘(Create new object)obj.JTP ‘(Calling the above function)
14. Read and display data from a text file Set fso=createobject("scripting.filesystemobject")Set txtfile=fso.opentextfile("E:\Menaka\fso.txt")Do until tfile.atendofstream
getcont=txtfile.readallprint getcont
Loop
15. Find all subfolders in a folderFunction psf(fldrname) Set fso=createobject("Scripting.filesystemobject") Set fdr=fso.getfolder(fldrname) Set fdrs=fdr.subfolders For each foldr in fdrs
print fldrname&"/"&foldr.name psf=psf(fldrname&"/"&foldr.name) next
End Functionpsf("C:\TD_75")
16. Remove all empty files in the folderFunction empfldr(fldrname)Set fso=createobject("Scripting.filesystemobject")Set fdr=fso.getfolder(fldrname)Set fdrs=fdr.filesFor each foldr in fdrs
s= foldr.sizeIf s=0 Thenprint foldr foldr.deleteEnd If
NextEnd Functionempfldr("E:\Menaka")
17. From file print all the lines that start with “Error” Set fso=createobject("Scripting.filesystemobject") Set fdr=fso.opentextfile("E:\Menaka\test.txt")
While not fdr.atendofstream rl=fdr.readline() m=mid(rl,1,5)If m="Error" Then n=n&rl&vbnewline End If Wend
print n
18. Replace a word with another wordRefer script 12
19. Print elements in a collectionstr=inputbox("Enter the string:")l=len(str)msgbox larr=split(str, " ") 'Splits the string where ever it finds spaceFor i=lbound(arr) to ubound(arr)
result= result&arr(i)&vbnewlineNext print result
20. Check whether string is in email formatstr=inputbox("Enter the string in E-mail format:")print strmailstr=instr(str, "@")If mailstr<>0 Then print "String is in E-mail format"End IfIf mailstr=0 Then
print "String is not in E-mail format"End If
21. Check whether given string is in date formatstr=cdate(inputbox("Enter the string in date format:"))print strdatestr=isdate(str)print "The given formate is "&datestr
22. Read all items in a tree (Explorer) ‘rightclick on startmenu--Exploreicount=window("Start Menu").WinTreeView("SysTreeView32").GetItemsCount()For i=0 to icount-1
itemlist=window("Start Menu").WinTreeView("SysTreeView32").GetItem(i)print itemlist
Next
23. List all objects in system tray windowicount=window("Window").WinToolbar("ToolbarWindow32").GetItemsCount()For i=1 to icount
gitem=window("Window").WinToolbar("ToolbarWindow32").GetItem(i)print gitem
Next
24. Print current day of the weeksysdate=dateprint sysdatedayofweek=weekday(sysdate)print dayofweek 'Calculates from sunday.
25. Find whether current month is a long monthcmon=month(now)print cmonIf cmon=1 or cmon=3 or cmon=5 or cmon=7 or cmon=8 or cmon=10 or cmon=12 Then
print "current month is a long month"elseprint "current month is not a long month"
End If
26. Find whether given year is a leap yearmyyear=inputbox("Enter year of format(YYYY):")print myyearIf myyear mod 4=0 Then
print "Given year is a leap year"elseprint "Given year is not a leap year"
End If
27. Format Number to specified decimal places
num=inputbox("Enter the decimal no:")print "Entered decimal no is:"&" "&numdnum=inputbox("Enter the decimal places to be formated:")print "Decimal places to be formated is:"&" "&dnumformatno=formatnumber(num,dnum)print "No. after formated:"&" "&formatno
28. Write a program to Generate a Random Number
Dim MyValue, ResponseDo until response=vbNOmynum= int (rnd*10000)msgbox mynumresponse= MsgBox ("continue? ", vbYesNo)Loop
OR
43.print the program to generate the ramdom nonum=inputbox("enter the num")For i= 1 to num
x=randomnumber.value(0,100)print x
Next29. Write a program to print the decimal part of a given number
dec=inputbox("Enter the decimal no.:")print "Given no is:"&" "&decwhol=int(dec)L1=len(dec)L2=len(whol)explen=L1-L2-1decpart=formatnumber(dec-whol,explen)print decpart
30. Add two 3X3 matricesDim a(2,2), b(2,2), c(2,2)For i=0 to 2
For j=0 to 2a(i,j)=cint(inputbox("Enter value for array a= "&"row"&i&"column"&j))Next
NextFor i=0 to 2
For j=0 to 2b(i,j)=cint(inputbox("Enter value for array b= "&"row"&i&"column"&j))Next
NextFor i=0 to 2
addmat=" "For j=0 to 2c(i,j)=a(i,j)+b(i,j)addmat=addmat&c(i,j)&" "Nextprint(addmat)
Next
31. Write a Script to enter data in login screen – YP->Admin
Browser("YellowPages").Page("YellowPages").WebElement("Login").GetTOProperty("Exist")Browser("YellowPages").Page("YellowPages").WebEdit("Login").Set "admin"Browser("YellowPages").Page("YellowPages").WebEdit("Password").Set "admin"Browser("YellowPages").Page("YellowPages").WebButton("Login").Click
32. Read items in a list box - YP -> Admin->Entries->Oracle->Category
icount=Browser("YellowPages").Page("YellowPages").WebList("category_id").GetTOProperty("items count")print icountFor i=1 to icountitemlist=Browser("YellowPages").Page("YellowPages").WebList("category_id").GetItem(i)print itemlistNext33. Read items on a desktop
icount=Window("Program Manager").WinListView("SysListView32").GetItemsCount()For i=0 to icount-1
itemlist=Window("Program Manager").WinListView("SysListView32").GetItem(i)print itemlist
Next
34. Place and retrieve data in a dictionarySet dict=createobject("Scripting.Dictionary")dict.add "A","Advance"dict.add "B","Brilliant"dict.add "C","Congrats"dict.add "D","Dynamic"val=dict.keysitm=dict.itemsFor i=0 to dict.count-1
print val(i)&" "&"for"&" "&itm(i)Next
35. Read items from a tabbed window -> System->Properties
icount=dialog("System Properties").WinTab("SysTabControl32").GetItemsCount()For i=0 to icount-1
itm=dialog("System Properties").WinTab("SysTabControl32").GetItem(i)print itm
Next
36. Check whether scrollbars exists inside a editor -> Notepad
sbar=window("Notepad").WinEditor("Edit").GetRoProperty("hasvscroll")If sbar=true Then
msgbox "Yes, Existing"elsemsgbox "No, not Existing"
End If
37. Print data from oracle database
Set db=createobject("ADODB.Connection")db.open="DSN=menaka;UID=scott;PWD=tiger;SERVER=oracle"If db.state=1 Then
msgbox "Connected"elsemsgbox "Not Connected"
End IfSet result=db.execute("Select * from tony")colcount=result.fields.countcolname=" "For i=0 to colcount-1
colname=colname&vbtab&result.fields(i).nameNextprint colnameWhile not result.eof
rval=" "For i=0 to colcount-1rval=rval&vbtab&result.fields(i).valueNextprint rval
result.movenextWend
38. Insert a new row into the database
Set db=createobject("ADODB.Connection")db.open="DSN=menaka;UID=scott;PWD=tiger;SERVER=oracle"Set result=db.execute("insert into tony values(105,'veena','QA',7000.00)")msgbox "Inserted"
39. Update specific field in the database
Set db=createobject("ADODB.Connection")db.open="DSN=menaka;UID=scott;PWD=tiger;SERVER=oracle"Set result=db.execute("update tony set sal=9500.00 where sno=100")msgbox "updated"
40. Write a program to delete all records whose username starts with demo
Set db=createobject("ADODB.Connection")db.open="DSN=menaka;UID=scott;PWD=tiger;SERVER=oracle"Set result=db.execute("delete from tony where name like demo")msgbox "deleted"
41. Find the x and y coordinates of a button –YP->Home-> search
xval=Browser("YellowPages").Page("YellowPages").WebButton("Search").GetROProperty("x")print "Value of 'x' coordinate is:"&" "&xvalyval=Browser("YellowPages").Page("YellowPages").WebButton("Search").GetROProperty("y")print "Value of 'y' coordinate is:"&" "&yval
42. Check whether edit box is focused -> YP->Home->Name
focus=browser("YellowPages").Page("YellowPages").WebEdit("name").GetROProperty("focused")If focus=0 Then
msgbox "Not focused"elsemsgbox "Focused"
End If
43. Check default selection in list box - YP -> Admin->Entries->Oracle->Category
defsel=browser("YellowPages").Page("YellowPages").WebList("category_id").GetTOProperty("default value")print defsel
44. Print URL name – YP ->Homeurl=browser("YellowPages").Page("YellowPages").GetROProperty("url")print url
45. List all links in the web page - YP->Homeset obj=description.Createobj("html tag").value="A"set chobj=browser("YellowPages").Page("YellowPages").ChildObjects(obj)msgbox chobj.countFor i=0 to chobj.count-1
list=chobj(i).GetROProperty("innertext") print listNext
46. List all applications opened in the system (window task manager)
icount=dialog("Windows Task Manager").WinListView("SysListView32"). GetItemsCount()msgbox icountFor i=0 to icount-1
itemlist=dialog("Windows Task Manager").WinListView("SysListView32").GetItem(i)print itemlist
Next
47. Check window resizable - FR
resize=window("Flight Reservation").GetROProperty("hassizebox")If resize=false Then
msgbox "Done"elsemsgbox "Wrong"
End If
54.Check window resizable - FRa=window("Flight Reservation").GetROProperty("maximizable")b=window("Flight Reservation").GetROProperty("minimizable")print a print bif b= true and a = false Then
print("not resizable") else print("resizable")
End If
48. Write your own standard checkpoint
If ( window("Flight Reservation").WinButton("Insert Order"). CheckProperty("enabled",true) eqv true) thenmsgbox "pass"elsemsgbox "fails"end if
49. List the process running in the computer (Services window)
ccount=window("Services").Window("Services (Local)").WinListView("SysListView32").ColumnCount()icount=window("Services").Window("Services (Local)").WinListView("SysListView32").GetItemsCount()For i=0 to icount-1
rval=" "For j=0 to ccount-1rval=rval&vbtab&window("Services").Window("Services
(Local)").WinListView("SysListView32").GetSubItem(i,j) Next
print rvalNext
50. Check given text displayed on the web page – YP->Home (“dynamic site”)
Browser("YellowPages").Page("YellowPages").Check CheckPoint("YellowPages")
51. Capture Desktop Screen shot
window("Program Manager"). WinListView("SysListView32"). CaptureBitmap("C:\scrshot.bmp")
52. Find whether image contains tool tip – YP->Home->Yellow Pages Logo
ttip=browser("YellowPages").Page("YellowPages").Image("CC-YelloPages-logo").GetROProperty("alt")If ttip=true Then
msgbox "Exist"elsemsgbox "Not Exist"
End If
53. Invoke Application in the Browser -> YP
invokeapplication"C:\Program Files\Internet Explorer\IEXPLORE.EXE"browser("Cannot find server"). Navigate("http://localhost:8081/yellowpages/Default.jsp")
(or)
systemutil.Run("http://localhost:8081/yellowpages/Default.jsp")
54. Read and Update data from environmental variable
systemutil.Run("C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe")environment.LoadFromFile("C:\Documents and Settings\j27menaka\Desktop\inficspractice.xml")dialog("Login").Activatedialog("Login").WinEdit("Agent Name:").Set environment ("AgentName")dialog("Login").WinEdit("Password:").Set environment ("Password")dialog("Login").WinButton("OK").Click
55. Find font type and size -> YP->Home->”Top”
fnt=browser("YellowPages").Page("YellowPages").WebElement("Top").GetROProperty("outerhtml")print fnt
56. Read and display data from CSV file ->” inficsinfo.csv” (Open a text file then save that with extension .csv)
Set fso=createobject("Scripting.FileSystemObject")Set fd=fso.opentextfile("E:\Menaka\inficsinfo.csv")Do until fd.atendofstreamrd=fd.readlineprint rdLoop
57. Write a Program to print “NOW I AM CONFIDENT IN VBSCRIPTING and QTP” to print log, text file and Data table
Dim a(8)For i=0 to 7a(i)=inputbox("Enter the string:")Nextstr=join (a)print str
Set fso=createobject("Scripting.filesystemobject")Set opfile=fso.opentextfile("E:\Menaka\test.txt",2)opfile.write(str)opfile.closedatatable.GetSheet("Global").addparameter "Menaka",strwait 3
58. Add and Remove Repositories to the action
reppath="E:\Menaka\share.tsr" ‘(add obj’s in repo then export those obj’srepositoriescollection.Add(reppath)wait 4
59. Write a program to open and print a word document
Set fso=createobject("Scripting.filesystemobject")Set fdr=fso.opentextfile("E:\Menaka\tony.doc",2) fdr.write "Hi everybody"&vbnewline&"How are you"&vbnewline&"How is your class going on" fdr.close
60. Find screen resolution
scrhgt=window("Program Manager").WinListView("SysListView32"). GetROProperty("height")scrwid=window("Program Manager").WinListView("SysListView32"). GetROProperty("width")print "Screen resolution is:"&vbnewline&"Height"&" "&scrhgt&vbnewline&"Width "&" "&scrwid
61. Read data from all sheets and all parameters of the file – “inficsinfo.xls”
datatable.ImportSheet "C:\Data.xls",1,1set s=DataTable.GetSheet("Global")t=s.getrowcountmsgbox tx=s.getparametercountMsgBox xfor i=1 to tch=""For j=1 to xval=datatable.Value(j)ch=ch&vbtab&valNextprint chdatatable.SetNextRownext
62. Display entire data in the web table -> YP – Admin -> Categories -> Categories
Dorcount=browser("YellowPages").Page("YellowPages").WebTable("Categories").RowCount()For i=1 to rcount-1
gitem=browser("YellowPages").Page("YellowPages").WebTable("Categories").GetCellData(i,1)print gitem
NextIf browser("YellowPages").Page("YellowPages").link("Next").Exist Then
continued=truebrowser("YellowPages").Page("YellowPages").Link("Next").Clickelse continued=falseExit do
End Ifloop while continued=true
65. Report Results status to Results file
a=inputbox("enter the value")If a=10 Thenreporter.ReportEvent 0,a,"both values are equal"else reporter.ReportEvent 1,a,"both values are not equal"End If
63. Import data to excel file from a database – FR Orders Tables -> FRdata.xls
Set db=createobject("ADODB.Connection")db.open="DSN=QT_Flight32"Set rs=db.execute("Select * from orders")ccount=rs.fields.countFor i=0 to ccount-1
cname=cname&space(i)&rs.fields(i).nameNextSet fso=createobject("Scripting.filesystemobject")Set fil=fso.opentextfile("E:\Menaka\FRdata.xls",2)fil.write (cname)While not rs.eof
rval=" "For i=0 to ccount-1rval=rval&space(i)&rs.fields(i).valueNext
fil.write (vbnewline&rval)rs.movenextWendfil.close
64. Find which add-ins are loaded.
Set app = CreateObject("QuickTest.Application")Set val=app.addinsFor i=1 to val.countIf val(i).status="Active" Thenprint("the addin "&val(i).name&" is loaded")End If Next
66. Find the name of columns in the table
Dim dt(10),s1(10)Set d=datatable.GetSheet("Global")Set s=datatable.AddSheet("Menaka")col=inputbox ("entr no of col")For i=0 to col-1Set dt(i)=d.addparameter(inputbox("enter col name"),"mm")n=dt(i).nameSet s1(i)=s.addparameter(n," ")print nNext
67. Write a program to send an email using outlook
Function sendmail(sendto,subject,body) Set ol=createobject("Outlook.Application") Set mail=ol.createitem(0) mail.to=sendto mail.subject=subject mail.body=body mail.send ol.quit Set mail=nothing Set ol=nothingEnd Functionsendmail "[email protected]","Hi","How are you"
68. Write a program to Disable active screen programmatically
Set qtApp = CreateObject("QuickTest.Application")Set qtActiveScreenOpt = qtApp.Options.ActiveScreen If qtActiveScreenOpt.CaptureLevel <> "None" Then (' If the current capture level is not "None" ) qtActiveScreenOpt.CaptureLevel = "Minimum" (' Capture properties only for recorded object )end ifqtApp.ShowPaneScreen "ActiveScreen", falsewait 4
69. Read elements in the XML file –> inficspractice.xml
Set doc = XMLUtil.CreateXML() doc.LoadFile "E:\Menaka\ inficspractice.xml " Set root = doc.GetRootElement() Set children = root.ChildElements() Set child = children.ItemByName("balu") numOfChildren = 0 While Not child Is nothing numOfChildren = numOfChildren+1 Set child = children.ItemByName("balu",numOfChildren+1) Wend msgbox "The number of children named balu is " & numOfChildren
(OR)
55. Read elements in the XML file –> inficspractice.xmlset d=XMLUtil.CreateXMLd.loadfile"C:\as.xml"set r= d.getrootelement()z=r.elementname()MsgBox zSet a=r.attributes()y=a.count()msgbox yset chi=r.childelements() x=chi.count()msgbox xIf y=0 Then For i=1 to x Set fc=chi.item(i)
set c=fc.childelements() n=fc.elementname() For j= 1 to c.count
Set f=c.item(j) g=g&f.elementname&"----"&f.value&vbnewline
Next Next msgbox gelse For k=1 to y For i=1 to x
Set p=a.item(k) m=p.name()
v=p.value() Set fc=chi.item(i) set c=fc.childelements()
n=fc.elementname() For j= 1 to c.count
Set f=c.item(j)
t=t&m&"="&chr(9)&v&""&chr(9)&n&"="&chr(9)&f.elementname&""&chr(9)&f.value&vbnewline
Next Next NextMsgBox tend if
70. Define test results location through program
Dim qtApp Dim qtTest Dim qtResultsOpt set qtApp = CreateObject("QuickTest.Application") Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") qtResultsOpt.ResultsLocation = "C:\Tests\Res1" Set qtResultsOpt = Nothing Set qtTest = Nothing Set qtApp = Nothing
(OR)
Dim pathpath=Reporter.ReportpathMsgbox (path)
71. Check whether a window is in minimized or maximized ->YP
min=browser("YellowPages").GetROProperty("Minimized")msgbox min
72. Check whether a check button is selected or not -> FR->OpenOrder
x=window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").GetROProperty("checked")y=window("Flight Reservation").Dialog("Open Order").WinCheckBox("Flight Date").GetROProperty("checked")z=window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").GetROProperty("checked")If x="ON" or y="ON" or z="ON" Then
msgbox "check box is selected"elsemsgbox "check box not selected"
End If
73. Modify Mandatory and Assistive properties programmatically
Dim App Dim objIdent Dim WinListobjDim propSet App = CreateObject("QuickTest.Application") Set objIdent = App.Options.ObjectIdentification Set WinListobj = objIdent.Item("WinList")objIdent.ResetAllWinListobj.OrdinalIdentifier = "Index" prop = WinListobj.MandatoryProperties.Find("nativeclass")WinListobj.MandatoryProperties.Remove propIf WinListobj.AvailableProperties.Find("items count") <> -1 Then '(If "items count" is an available prop for winlist) WinListobj.MandatoryProperties.Add "items count"End If WinListobj.AssistiveProperties.RemoveAll WinListobj.AssistiveProperties.Add "all items" '(if its blank here its 2nd prop)WinListobj.AssistiveProperties.Add "width", 1 '(1 stands for add as 1st prop)WinListobj.AssistiveProperties.Add "height", -1 '(-1 stands for add as last prop)WinListobj.AssistiveProperties.MoveToPos 2, 1
Hint: In the above last line is not mandatory. 1 & -1 is also not mandatory
74. Check whether dialog is middle of the window -> FR->OpenOrder
frx=window("Flight Reservation").GetROProperty("x")fry=window("Flight Reservation").GetROProperty("y")oox=window("Flight Reservation").Dialog("Open Order").GetROProperty("x")ooy=window("Flight Reservation").Dialog("Open Order").GetROProperty("y")If frx=208 and fry=154 and oox=345 and ooy=250 Then
msgbox "Dialog is in the middle"elsemsgbox "Dialog is not in the middle"
End If
75. Instruct Quick test to Capture Movie Segments of Each Error and Warning
(To capture image)
Dim qtAppDim qtTest Dim qtResultsOpt Set qtApp = CreateObject("QuickTest.Application") qtApp.Options.Run.ImageCaptureForTestResults = "OnError" (It’ll select “For error”)qtApp.Options.Run.ViewResults = true (If u give false here u wont get result sheet)
(To capture movie)
Dim qtAppDim qtTest Dim qtResultsOpt Set qtApp = CreateObject("QuickTest.Application") qtApp.Options.Run.MovieCaptureForTestResults = "Warning" (It’ll select “For error and warning)qtApp.Options.Run.ViewResults = true
Hint: Before running this script go to options--run--deactivate "save image capture to results" / “Save movie to results” After executing the script if you see the same it will be activated)
76. Check whether we can select multiple items in the combo box
a=window("Flight Reservation").WinComboBox("Fly From:").GetROProperty("all Item")If a=true Then
msgbox ("multiple selection possible")else msgbox ("multiple selection not possible")end if
77. Close all the dialogs open on a window FR-> OpenOrder -> Error Window
window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").Closewindow("Flight Reservation").Dialog("Open Order").Close
78. Check whether a check button is selected or not -> FR->OpenOrder
x=window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").GetROProperty("checked")y=window("Flight Reservation").Dialog("Open Order").WinCheckBox("Flight Date").GetROProperty("checked")z=window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").GetROProperty("checked")If x="ON" or y="ON" or z="ON" Then
msgbox "check box is selected"elsemsgbox "check box not selected"
End If
79. Configure Run options programmatically
Dim App Set App = CreateObject("QuickTest.Application")App.Options.Run.RunMode = "Fast"App.Options.Run.ViewResults = TrueApp.Options.Run.StepExecutionDelay = 0App.Options.Run.ImageCaptureForTestResults = "OnError" App.Options.Run.MovieCaptureForTestResults = "Onerror"
(In the above instead of “OnError” we can select “Never”/”OnWarning”/”Always”)
80. Check whether edit box allows exactly 15 characters -> YP ->Home->Name
str=inputbox ("str")browser("YellowPages").Page("YellowPages").WebEdit("name").set(str)n=len(str)msgbox "length of name given is: "&nIf n<=15 Thenmsgbox "It allows only 15 characters"else msgbox "It allows more than 15 characters"End If
81. Convert Date from Indian Format to US format
indfor=inputbox("Enter date in dd/mm/yyyy format")msgbox indforusfor=cdate(indfor)msgbox usfor
82. Check whether items in the page are aligned properly -> YP -> Home->Editboxes
a1=browser("YellowPages").Page("YellowPages").WebEdit("name").GetROProperty("x")a2=browser("YellowPages").Page("YellowPages").WebEdit("address").GetROProperty("x")a3=browser("YellowPages").Page("YellowPages").WebEdit("city").GetROProperty("x")a4=browser("YellowPages").Page("YellowPages").WebEdit("state").GetROProperty("x")a5=browser("YellowPages").Page("YellowPages").WebEdit("zip").GetROProperty("x")If (a1=a2 and a2=a3 and a3=a4 and a4=a5) Then msgbox "alligned"else msgbox "not alligned"End If
83. Check whether a link contains image to its left side. -> YP-Home link-> YP Logo
a=browser("YellowPages").Page("YellowPages").image("CC-YelloPages-logo").GetROProperty("abs_x")b=browser("YellowPages").Page("YellowPages").WebElement("Home").GetROProperty("abs_x")If (a<b) Then print "Image Exists on the left side of the link" Else print "Image does not Exists on the left side of the link"End If
84. Enable and Disable Recovery scenarios programmatically
msgbox Recovery.Count,, "Number of Recovery Scenarios" msgbox Recovery,, "Is Recovery enabled?" for Iter = 1 to Recovery.Count Recovery.GetScenarioName Iter, ScenarioFile, ScenarioName Position = Recovery.GetScenarioPosition( ScenarioFile, ScenarioName ) msgbox Recovery.GetScenarioStatus( Position )ScenarioFile = Empty ScenarioName = Empty Next Recovery.Activate Recovery.SetScenarioStatus 1, trueRecovery.Activate Recovery = trueRecovery.Activate
85. Check whether stock prices are updating an hourly basis
a1=dialog("Date/Time Properties").WinEdit("Edit").GetVisibleText()wait(5)a2=dialog("Date/Time Properties").WinEdit("Edit").GetVisibleText()If (a1=a2) Then print "stock price not updating"else print "updating" End If
86. Clear the cache in the webpage
Function DelCatche (FdrName) Set fso=createObject("scripting.FileSystemObject") Set fdr=fso.getfolder(FdrName) Set FilCol=fdr.files For each fil in FilCol print fil.name' fil.delete NextEnd FunctionDelCatche("C:\WINT\Drive Cache")87. Check Marquee
mar=browser("Browser").Page("Page").WebElement("welcome_2").GetTOProperty("outerhtml") print mar
88. Read menu names and items -> FR
window("Flight Reservation").Activatecnt=window("Flight Reservation").WinMenu("Menu"). GetItemProperty("File","subMenuCount")For i=1 to cnt nam=window("Flight Reservation").WinMenu("Menu"). BuildMenuPath("File",i) n2=window("Flight Reservation").WinMenu("Menu"). GetItemProperty(nam,"Label") t=t&n2&vbnewlineNextprint t
89. Configure maximum timeout value for web page to load
Dim qtAppSet qtApp = CreateObject("QuickTest.Application") ' Configure the Web application to use with this test qtApp.test.Settings.Launchers("Web").Active = True ' Configure other Web settings qtApp.Test.Settings.Web.BrowserNavigationTimeout = 70000 qtApp.Visible = True ' Make the QuickTest application visible Set qtApp = Nothing ' Release the Application object
90. Matrix multiplication (2*2) matrix
Dim a(1,1), b(1,1), c(1,1)For i=0 to 1 For j=0 to 1 a(i,j)=inputbox("enter array elements of a") NextNextprint "The Arry a="For i=0 to 1 ch ="" For j=0 to 1 ch=ch&a(i,j)&vbtab Next print ch print newlineNextFor i=0 to 1 For j=0 to 1 b(i,j)=inputbox("enter array elements of b") NextNextprint "The Arry b="For i=0 to 1 ch ="" For j=0 to 1 ch=ch&b(i,j)&vbtab Next print ch print newlineNextFor i=0 to 1 For j=0 to 1 c(i,j)=0
For k=0 to 1 c(i,j)=a(i,k)*b(k,j)+c(i,j)
print c(i,j) Next NextNextprint "The Multiplied matrix is Arry c="For i=0 to 1 ch ="" For j=0 to 1 ch=ch&c(i,j)&vbtab Next print ch print newlineNext
Write a program to export object repository file to XML (Not completed)
Set obj = CreateObject("Mercury.ObjectRepositoryUtil") Set lod=obj.load("C:\Document and Settings\j27menaka\Desktop\obj.tsr")val=lod.ExportToXml("C:\Document and Settings\j27menaka\Desktop \obj.tsr"," C:\Document and Settings\j27menaka\Desktop\objrep.xml")
msgbox "Done"
---------------------------------------------------------------------------------------------
40.Find number of rows in each column
set s=DataTable.GetSheet("Global")x=s.getparametercountMsgBox x t=s.getrowcount msgbox t
For j=1 to x f=0For l=1 to t
s=datatable.GetSheet(1).GetParameter(j).valueByrow(l) If s<>"" Then
f=f+1 End If
' datatable.SetxtRow(l)Nextprint ("No of Rows = "&f)datatable.SetCurrentRow(l)
Next
72.Retrieve all the columns and row in the table
set s=DataTable.GetSheet("Global")t=s.getrowcount msgbox tx=s.getparametercountMsgBox x
For i=1 to x
For j=1 to t k= datatable.Value(i)
l=datatable.Value(j)' k= getsheet("global").getcelldata(i,j)' print(k(i,j))
print k print l
Next Next
Test85.Report Results status to Results filewindow("Flight Reservation").Activatereporter.ReportEvent micPass,"attached text","Flight No"
13.To read from Vbs fileSet fso=createobject ("scripting.filesystemobject")Set tstr=fso.opentextfile("C:\Documents and Settings\j26ashwini\Demolib.vbs",1)While not tstr. AtEndOfStream
fline=tstr.Readline ( )print fline
Wend
msgbox Recovery.Count,, "Number of Recovery Scenarios" msgbox Recovery,, "Is Recovery enabled?" for Iter = 1 to Recovery.Count Recovery.GetScenarioName Iter, ScenarioFile, ScenarioName Position = Recovery.GetScenarioPosition( ScenarioFile, ScenarioName ) msgbox Recovery.GetScenarioStatus( Position )ScenarioFile = Empty ScenarioName = Empty Next Recovery.Activate
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"Dialog("Login").WinEdit("Agent Name:").Set "manju"Dialog("Login").WinEdit("Password:").SetSecure "manju"Dialog("Login").WinButton("OK").ClickDialog("Login").Dialog("Flight Reservations").Check CheckPoint("Flight Reservations")Dialog("Login").WinEdit("Agent Name:").Set "manju"Dialog("Login").WinEdit("Password:").SetSecure "mercury"Dialog("Login").WinButton("OK").Click