Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 27

21-02-2008 1.

Swap 2 numbers with out temporary variable a=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="&b a=a+b b=a-b a=a-b Print "Value of a&b after swapping:"&vbnewline&"a="&a&vbnewline&"b="&b 2. Print prime numbers a=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-1 If i mod j=0 Then flag=1 Exit for End If Next If flag=0 Then print(i) End If flag=0 Next 3. Print the data in triangle shape str=inputbox("Enter the string:") l=len(str) j=0 For i=l to 1 step -1 j=j+1 tri=mid(str,1,j) print space(i)&tri Next 4. Sort Array elements a=array(100,10,50,40,80,30) For j=lbound(a) to ubound(a)-1 For k=lbound(a) to ubound(a)-1 If 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)=temp End If Next Next For i=lbound(a) to ubound(a) print(a(i)) Next 5. Find a character in a string str=inputbox("Enter the string to test:") ch=inputbox("Enter the character to find:") print "Entered String is:"&" "&str print "Expected Character is:"&" "&ch l=len(str) print "Length of the string is:"&" "&l x=0 For i=1 to l expe=mid(str,i,1) x=x+1 If expe=ch Then print "Position of the character in a given string:"&" "&i End 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-1 if ch=str(i) then Count+1 end if Next print(Count) 6. Convert string to Upper Case str=inputbox("Enter the string to convert:") constr=ucase(str) print constr 7. Returning Character specific to ASCII value chval=inputbox("Enter the ASCII value to find the character:") '(Any no 1 to 256) char=chr(chval) print char

8. Display current date and Time curdatentime=now print 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 string Dim a(4) For i=0 to 4 a(i)=inputbox("Enter the string:") Next print "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:"&" "&str print "Word to be replaced is:"&" "&wordtorepl replstr=replace(str, wordtorepl, vbtab) print replstr 12. Replace a word in a string with other word str=inputbox("Enter the string:") word=inputbox("Enter the word to be replaced:") repword=inputbox("Enter the replacing word:") print "Given string is:"&" "&str print "Expected word to be replaced is:"&" "&word print "Replacing word:"&" "&repword repstr=replace(str, word, repword) print repstr 13. Create your own Class and Object Class Testing (Create a class) Function JTP() (Create one function under that) Print "How is your experience in JTP" End Function End Class Set 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.readall print getcont Loop 15. Find all subfolders in a folder Function 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 Function psf("C:\TD_75") 16. Remove all empty files in the folder Function empfldr(fldrname) Set fso=createobject("Scripting.filesystemobject") Set fdr=fso.getfolder(fldrname) Set fdrs=fdr.files For each foldr in fdrs s= foldr.size If s=0 Then print foldr foldr.delete End If Next End Function empfldr("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 word Refer script 12 19. Print elements in a collection str=inputbox("Enter the string:") l=len(str) msgbox l arr=split(str, " ") 'Splits the string where ever it finds space For i=lbound(arr) to ubound(arr) result= result&arr(i)&vbnewline Next print result 20. Check whether string is in email format str=inputbox("Enter the string in E-mail format:") print str mailstr=instr(str, "@") If mailstr<>0 Then print "String is in E-mail format" End If If mailstr=0 Then print "String is not in E-mail format" End If 21. Check whether given string is in date format str=cdate(inputbox("Enter the string in date format:")) print str datestr=isdate(str) print "The given formate is "&datestr 22. Read all items in a tree (Explorer) rightclick on startmenu--Explore icount=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 window icount=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 week sysdate=date print sysdate dayofweek=weekday(sysdate) print dayofweek 'Calculates from sunday. 25. Find whether current month is a long month cmon=month(now) print cmon If 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" else print "current month is not a long month" End If 26. Find whether given year is a leap year myyear=inputbox("Enter year of format(YYYY):") print myyear If myyear mod 4=0 Then print "Given year is a leap year" else print "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:"&" "&num dnum=inputbox("Enter the decimal places to be formated:") print "Decimal places to be formated is:"&" "&dnum formatno=formatnumber(num,dnum) print "No. after formated:"&" "&formatno 28. Write a program to Generate a Random Number Dim MyValue, Response Do until response=vbNO mynum= int (rnd*10000) msgbox mynum response= MsgBox ("continue? ", vbYesNo) Loop OR

43.print the program to generate the ramdom no num=inputbox("enter the num") For i= 1 to num x=randomnumber.value(0,100) print x Next 29. Write a program to print the decimal part of a given number dec=inputbox("Enter the decimal no.:") print "Given no is:"&" "&dec whol=int(dec) L1=len(dec) L2=len(whol) explen=L1-L2-1 decpart=formatnumber(dec-whol,explen) print decpart 30. Add two 3X3 matrices Dim a(2,2), b(2,2), c(2,2) For i=0 to 2 For j=0 to 2 a(i,j)=cint(inputbox("Enter value for array a= "&"row"&i&"column"&j)) Next Next For i=0 to 2 For j=0 to 2 b(i,j)=cint(inputbox("Enter value for array b= "&"row"&i&"column"&j)) Next Next For i=0 to 2 addmat=" " For j=0 to 2 c(i,j)=a(i,j)+b(i,j) addmat=addmat&c(i,j)&" " Next print(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("item s count") print icount For i=1 to icount itemlist=Browser("YellowPages").Page("YellowPages").WebList("category_id").GetItem(i) print itemlist Next 33. 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 dictionary Set dict=createobject("Scripting.Dictionary") dict.add "A","Advance" dict.add "B","Brilliant" dict.add "C","Congrats" dict.add "D","Dynamic" val=dict.keys itm=dict.items For 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" else msgbox "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" else msgbox "Not Connected" End If Set result=db.execute("Select * from tony") colcount=result.fields.count colname=" " For i=0 to colcount-1 colname=colname&vbtab&result.fields(i).name Next print colname While not result.eof rval=" " For i=0 to colcount-1 rval=rval&vbtab&result.fields(i).value Next print rval result.movenext Wend 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:"&" "&xval yval=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" else msgbox "Focused" End If 43. Check default selection in list box - YP -> Admin->Entries->Oracle->Category defsel=browser("YellowPages").Page("YellowPages").WebList("category_id").GetTOProperty("defau lt value") print defsel 44. Print URL name YP ->Home url=browser("YellowPages").Page("YellowPages").GetROProperty("url") print url 45. List all links in the web page - YP->Home set obj=description.Create obj("html tag").value="A" set chobj=browser("YellowPages").Page("YellowPages").ChildObjects(obj) msgbox chobj.count For i=0 to chobj.count-1 list=chobj(i).GetROProperty("innertext") print list Next 46. List all applications opened in the system (window task manager) icount=dialog("Windows Task Manager").WinListView("SysListView32"). GetItemsCount() msgbox icount For 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" else msgbox "Wrong" End If 54.Check window resizable - FR a=window("Flight Reservation").GetROProperty("maximizable") b=window("Flight Reservation").GetROProperty("minimizable") print a print b if 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) then msgbox "pass" else msgbox "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-1 rval=rval&vbtab&window("Services").Window("Services (Local)").WinListView("SysListView32").GetSubItem(i,j) Next print rval Next

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-YelloPageslogo").GetROProperty("alt") If ttip=true Then msgbox "Exist" else msgbox "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").Activate dialog("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.atendofstream rd=fd.readline print rd Loop 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 7 a(i)=inputbox("Enter the string:") Next str=join (a) print str Set fso=createobject("Scripting.filesystemobject") Set opfile=fso.opentextfile("E:\Menaka\test.txt",2) opfile.write(str) opfile.close datatable.GetSheet("Global").addparameter "Menaka",str wait 3 58. Add and Remove Repositories to the action reppath="E:\Menaka\share.tsr" (add objs in repo then export those objs repositoriescollection.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,1 set s=DataTable.GetSheet("Global") t=s.getrowcount msgbox t x=s.getparametercount MsgBox x for i=1 to t ch="" For j=1 to x val=datatable.Value(j) ch=ch&vbtab&val Next print ch datatable.SetNextRow next 62. Display entire data in the web table -> YP Admin -> Categories -> Categories Do rcount=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 Next If browser("YellowPages").Page("YellowPages").link("Next").Exist Then continued=true browser("YellowPages").Page("YellowPages").Link("Next").Click else continued=false Exit do End If loop while continued=true 65. Report Results status to Results file a=inputbox("enter the value") If a=10 Then reporter.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.count For i=0 to ccount-1 cname=cname&space(i)&rs.fields(i).name Next Set 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-1 rval=rval&space(i)&rs.fields(i).value Next fil.write (vbnewline&rval) rs.movenext Wend fil.close 64. Find which add-ins are loaded. Set app = CreateObject("QuickTest.Application") Set val=app.addins For i=1 to val.count If val(i).status="Active" Then print("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-1 Set dt(i)=d.addparameter(inputbox("enter col name"),"mm") n=dt(i).name Set s1(i)=s.addparameter(n," ")

print n Next 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=nothing End Function sendmail "balajinallasamy@gmail.com","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 if qtApp.ShowPaneScreen "ActiveScreen", false wait 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.xml set d=XMLUtil.CreateXML d.loadfile"C:\as.xml" set r= d.getrootelement() z=r.elementname() MsgBox z Set a=r.attributes() y=a.count() msgbox y set chi=r.childelements() x=chi.count() msgbox x If 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 g else 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 Next MsgBox t end 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 path path=Reporter.Reportpath Msgbox (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" else msgbox "check box not selected" End If

73. Modify Mandatory and Assistive properties programmatically Dim App Dim objIdent Dim WinListobj Dim prop Set App = CreateObject("QuickTest.Application") Set objIdent = App.Options.ObjectIdentification Set WinListobj = objIdent.Item("WinList") objIdent.ResetAll WinListobj.OrdinalIdentifier = "Index" prop = WinListobj.MandatoryProperties.Find("nativeclass") WinListobj.MandatoryProperties.Remove prop If 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" else msgbox "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 qtApp Dim qtTest Dim qtResultsOpt Set qtApp = CreateObject("QuickTest.Application") qtApp.Options.Run.ImageCaptureForTestResults = "OnError" (Itll select For error) qtApp.Options.Run.ViewResults = true (If u give false here u wont get result sheet) (To capture movie) Dim qtApp Dim qtTest Dim qtResultsOpt Set qtApp = CreateObject("QuickTest.Application") qtApp.Options.Run.MovieCaptureForTestResults = "Warning" (Itll 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").Close window("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" else msgbox "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 = True App.Options.Run.StepExecutionDelay = 0 App.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: "&n If n<=15 Then msgbox "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 indfor

usfor=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-YelloPageslogo").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, true Recovery.Activate Recovery = true Recovery.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 Next End Function DelCatche("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").Activate cnt=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&vbnewline Next print t

89. Configure maximum timeout value for web page to load Dim qtApp Set 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") Next Next print "The Arry a=" For i=0 to 1 ch ="" For j=0 to 1 ch=ch&a(i,j)&vbtab Next print ch print newline Next For i=0 to 1 For j=0 to 1 b(i,j)=inputbox("enter array elements of b") Next Next print "The Arry b=" For i=0 to 1 ch ="" For j=0 to 1 ch=ch&b(i,j)&vbtab Next print ch print newline Next

For 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 Next Next print "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 newline Next 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.getparametercount MsgBox x t=s.getrowcount msgbox t For j=1 to x f=0 For l=1 to t s=datatable.GetSheet(1).GetParameter(j).valueByrow(l) If s<>"" Then f=f+1 End If ' datatable.SetxtRow(l) Next

print ("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 t x=s.getparametercount MsgBox 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 file window("Flight Reservation").Activate reporter.ReportEvent micPass,"attached text","Flight No" 13.To read from Vbs file Set 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").Click Dialog("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

You might also like