SlideShare a Scribd company logo
FILE SYSTEM OBJECTS EXAMPLES
Examples:
i) Create a Folder
Dim objFso
Set objFso=CreateObject(“scripting.FileSystemObject”)
objFso.CreateFolder “C:Documents and Settings1 Desktophyderabad”
ii) Check if the Folder Exist or not? If not create the Folder
Dim objFso, myFolder
myFolder=”C:Documents and Settings1 Desktophyderabad”
Set objFso=CreateObject(“scripting.FileSystemObject”)
If Not objFso.FolderExists(myFolder) Then
objFso.CreateFolder (myFolder)
End If
iii) Copy a Folder
Dim objFso, myFolder
myFolder=”C:Documents and Settings1 Desktophyderabad”
Set objFso=CreateObject(“scripting.FileSystemObject”)
objFso.CopyFolder myFolder,”E:abcd”
iv) Delete a folder
Dim objFso, myFolder
myFolder=”C:Documents and Settings1Desktophyderabad”
Set objFso=CreateObject(“scripting.FileSystemObject”)
objFso.DeleteFolder( myFolder)
2nd
Dim objFso, myFolder
myFolder=”C:Documents and Settings1Desktophyderabad”
Set objFso=CreateObject(“scripting.FileSystemObject”)
If objFso.FolderExists(myFolder) Then
objFso.DeleteFolder( myFolder)
End If
v) Return a Collection of Disk Drives
Dim objFso, colDrives
Set objFso=CreateObject(“scripting.FileSystemObject”)
Set colDrives=objFso.Drives
For Each oDrive in colDrives
Msgbox oDrive
Next
vi) Get available space on a Drive
Dim objFso
Set objFso=CreateObject(“scripting.FileSystemObject”)
Set myDrive=objFso.GetDrive(“D:”)
Msgbox myDrive.AvailableSpace/(1024^3) & ” GB”
vii) Creating a Text File
Dim objFso
Set objFso=CreateObject(“scripting.FileSystemObject”)
objFso.CreateTextFile (“C:Documents and Settings1 Desktopabcd.txt”)
objFso.CreateTextFile (“C:Documents and Settings1 Desktopabcd.doc”)
objFso.CreateTextFile (“C:Documents and Settings1 Desktopabcd.xls”)
objFso.CreateTextFile (“C:Documents and Settings1 Desktopabcd.pdf”)
Note: We can Create other files also, but they act as Text/Flat Files
viii) Check if the File Exist or not? If not create the File
Dim objFso, myFile1,myFile2, myFile3, myFile4
myFile1=”C:Documents and Settings1 Desktopabcd.txt”
myFile2=”C:Documents and Settings1 Desktopabcd.doc”
myFile3=”C:Documents and Settings1 Desktopabcd.xls”
myFile4=”C:Documents and Settings1 Desktopabcd.pdf”
Set objFso=CreateObject(“scripting.FileSystemObject”)
If Not objFso.FileExists(myFile1) Then
objFso.CreateTextFile (myFile1)
End If
If Not objFso.FileExists(myFile2) Then
objFso.CreateTextFile (myFile2)
End If
If Not objFso.FileExists(myFile3) Then
objFso.CreateTextFile (myFile3)
End If
If Not objFso.FileExists(myFile4) Then
objFso.CreateTextFile (myFile4)
End If
ix) ReadData Character by Character from a text file
Dim objFso, myFile, myChar
Set objFso=CreateObject(“scripting.FileSystemObject”)
Set myFile=objFso.OpenTextFile(“C:Documents and Settings1 Desktopabcd.txt”,1) ’1 for Read,
2 for Write and 8 for Append
Do Until myFile.AtEndOfStream=True
myChar=myFile.Read(1)
Msgbox myChar
Loop
myFile.Close
Set objFso=Nothing
x)Read Line by Line from a Text File
Dim objFso, myFile, myChar
Set objFso=CreateObject(“scripting.FileSystemObject”)
Set myFile=objFso.OpenTextFile(“C:Documents and Settings1 Desktopabcd.txt”,1) ’1 for Read,
2 for Write and 8 for Append
Do Until myFile.AtEndOfStream=True
myChar=myFile.ReadLine
Msgbox myChar
Loop
myFile.Close
Set objFso=Nothing
xi) Data Driven Testing by fetching Test data directly from a Text file.
‘*****************************************************************************
********
‘Test Requirement: Data Driven Testing by fetching Test data directly from a Text file.
‘Author: xyz
‘Date of Creation: 24-08-2010
‘Pre-requasites:
‘abcd.txt (Test Data File)
‘Test Flow:
‘Create File System object
‘Open the file with Read mode and store reference into a variable
‘Skipe the first line
‘Read line by line and split the Data
‘Login Operation
‘Form Looping and pass Parameters
‘*****************************************************************************
********
Dim objFso, myFile, myLine, myField
Set objFso=CreateObject(“scripting.FileSystemObject”)
Set myFile=objFso.OpenTextFile(“C:Documents and Settings1 Desktopabcd.txt”,1) ’1 for Read,
2 for Write and 8 for Append
myFile.SkipLine
Do Until myFile.AtEndOfStream =True
myLine=myFile.ReadLine
myField=Split(myLine,”,”)
SystemUtil.Run “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe”
Dialog(“text:=Login”).Activate
Dialog(“text:=Login”).WinEdit(“attached text:=Agent Name:”).Set myField(0)
Dialog(“text:=Login”).WinEdit(“attached text:=Password:”).Set myField(1)
Wait 2
Dialog(“text:=Login”).WinButton(“text:=OK”).Click
Window(“text:=Flight Reservation”).Close
Loop
myFile.Close
Set objFso=Nothing
xii) Write Data to a Text File
Dim objFso, myFile, Result, a, b
a=10: b=20
Result=a+b
Set objFso=CreateObject(“scripting.FileSystemObject”)
Set myFile=objFso.OpenTextFile(“C:Documents and Settings1 Desktopabcd.txt”,2) ’1 for Read,
2 for Write and 8 for Append
myFile.WriteLine “Addition of a, b is: “&Result
myFile.Close
Set objFso=Nothing
xiii) Delete a Text File
Dim objFso
Set objFso=CreateObject(“scripting.FileSystemObject”)
objFso.DeleteFile(“C:Documents and Settings1 Desktopabcd.doc”)
Set objFso=Nothing
xiv) Check if the File Exists or not? If Exists delete the File
———–
Dim objFso
Set objFso=CreateObject(“scripting.FileSystemObject”)
If objFso.FileExists(“C:Documents and Settings1 Desktopabcd.pdf”) Then
objFso.DeleteFile(“C:Documents and Settings1 Desktopabcd.pdf”)
End If
Set objFso=Nothing
xv) Calculate size of a Text File
Dim objFso
Set objFso=CreateObject(“scripting.FileSystemObject”)
File_Size= objFso.GetFile(“C:Documents and Settings1 Desktopabcd.txt”).Size
Msgbox File_Size& ” Bytes”
Set objFso=Nothing
xvi)Compare Two Text File by Size, by Text and by Binary values
Option Explicit
Dim objFso, File1, File2, myFile1, myFile2, File_First, File_Second, Files_Compare
File1=”C:Documents and Settings1 abcd.txt”
File2=”C:Documents and Settings1 desktopxyz.txt”
Set objFso=CreateObject(“scripting.FileSystemObject”)
‘Comaring two text files by Size
If objFso.GetFile(File1).Size= objFso.GetFile(File2).Size Then
Msgbox “Files are Same in Size”
Else
Msgbox “Files are Not Same”
End If
‘Comaring two text files by Text
Set File_First=objFso.OpenTextFile(File1)
Set File_Second=objFso.OpenTextFile(File2)
myFile1=File_First.ReadAll
myFile2=File_Second.ReadAll
‘Msgbox myFile1
Files_Compare=strComp(myFile1,myFile2,1) ’1 for Texual Comparision
If Files_Compare=0 Then
Msgbox “Files are having Same Text”
Else
Msgbox “Files are having Different Text”
End If
‘Binary Comparision of Two Text Files
Files_Compare=strComp(myFile1,myFile2,0) ’0 for Binary Comparision (It is Default mode)
If Files_Compare=0 Then
Msgbox “Files are Equal”
Else
Msgbox “Files are Not Equal”
End If
Set objFso=Nothing
xvii) Count the number of times a word appears in a Text File
Option Explicit
Dim objFso, File1, myWord, myData, myFile, objRegEx, MatchesFound, TotMatches
File1=”C:Documents and Settings1 RIGHATWAYDesktopabcd.txt”
Set objFso=CreateObject(“scripting.FileSystemObject”)
Set myFile=objFso.OpenTextFile(File1)
myData=myFile.ReadAll
myWord=”QTP”
Set objRegEx= New RegExp ‘Creating Regular Expression Object
objRegEx.Pattern=myWord ‘Search string
objRegEx.Global=True ‘ Finding all Matches
objRegEx.IgnoreCase=True ‘ Ignoring Case
Set MatchesFound=objRegex.Execute(myData) ‘Executing the Total file data to find natches
TotMatches=MatchesFound.Count
Msgbox “Matches: “&TotMatches
Set objFso=Nothing
xviii) Capture all Button Names from Login dialog Box and Export to a Text File
Option Explicit
Dim objFso, FilePath, myFile, oButton, myButton, Buttons, i, TotButtons
FilePath=”C:Documents and Settings1 RIGHATWAYDesktopabcd.txt”
Set objFso=CreateObject(“scripting.FileSystemObject”)
Set myFile=objFso.OpenTextFile(FilePath,2)
myFile.WriteLine “Button Names”
myFile.WriteLine “————”
Set oButton=Description.Create
oButton(“micclass”).value=”WinButton”
SystemUtil.Run “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe”
Set Buttons=Dialog(“text:=Login”).ChildObjects(oButton)
TotButtons=Buttons.Count
For i= 0 to TotButtons-1 Step 1
myButton=Buttons(i).GetRoProperty(“text”)
myFile.WriteLine myButton
Next
myFile.Close
Set objFso=Nothing
xix) Capture Customer Names from 1 to 10 Orders in FR and export to a Text File
*****************************************************************
‘Test Requirement: Capture Customer names from 1 to 10 orders
‘and export to text file
‘Test Flow:
‘Create an object in File system class
‘Open the text file in write mode using File sytem object
‘Login Operation
‘Form Loop to open 1 to 10 orders
‘capture the Customer names and write to external text file
‘*****************************************************************
Dim objFso, myFile
Set objFso=CreateObject(“scripting.FilesystemObject”)
Set myFile=objFso.OpenTextFile(“C:Documents and Settingsgcr.GCRC-
9A12FBD3D9Desktopabc.txt”,2)
myFile.WriteLine “Customer Names”
myFile.WriteLine “———”
If Not Window(“Flight Reservation”).Exist(3) Then
SystemUtil.Run “C:Program FilesHPQuickTest
Professionalsamplesflightappflight4a.exe”,”",”C:Program FilesHPQuickTest
Professionalsamplesflightapp”,”open”
Dialog(“Login”).Activate
Dialog(“Login”).WinEdit(“Agent Name:”).Set “nagesh”
Dialog(“Login”).WinEdit(“Password:”).SetSecure
“4c9e05a626f9b6471971fb15474e791b28cc1ed0″
Dialog(“Login”).WinButton(“OK”).Click
End If
For Order_Number= 1 to 10 step 1
Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).WinButton(“Button”).Click
Window(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON”
Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set Order_Number
Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).Click
wait 2
Customer_Name = Window(“Flight Reservation”).WinEdit(“Name:”).GetVisibleText()
myFile.WriteLine Customer_Name
Next
myFile.Close
Set objFso=Nothing
HOW TO WORK WITH EXCEL
'''Script to create a new excel file , write data
'''save the file with read and write protected
'''''pwd1 is for read protected pwd2 is for write protected
Set xl=CreateObject("Excel.Application")
Set wb=xl.Workbooks.Add
xl.DisplayAlerts=False
Set ws=wb.Worksheets("sheet1")
ws.cells(1,1)=100
ws.cells(1,2)=200
wb.Saveas "e:data2.xls",,"pwd1","pwd2"
wb.Close
Set xl=nothing
'''Script to open excel file ,which is read and write protected write data
'''''pwd1 is for read protected pwd2 is for write protected
Set xl=CreateObject("Excel.Application")
Set wb=xl.Workbooks.Open("e:data2.xls",0,False,5,"pwd1","pwd2")
xl.DisplayAlerts=False
Set ws=wb.Worksheets("sheet1")
ws.cells(1,2)="hello"
ws.cells(2,2)="new data"
wb.Save
wb.Close
Set xl=nothing
''Script to get the list of links in Google and do spell check
===============================================================
dim d
set mw=CreateObject("Word.Application")
set d=Description.Create
d("micclass").value="Link"
set a=Browser("Google").page("Google").childobjects(d)
for i=0 to a.count-1
mw.WordBasic.filenew
s=a(i).getROProperty("innertext")
mw.WordBasic.insert s
if mw.ActiveDocument.Spellingerrors.count>0 then
Reporter.ReportEvent 1,"Spelling","spelling error :"&s
end if
mw.ActiveDocument.Close(False)
next
mw.quit
set mw=nothing
=========================================
''''Script to check ON the checkboxes in yahoo mail inbox
=========================================
Dim d
Set d=Description.Create
d("micclass").value="WebCheckBox"
Set c=Browser("Inbox (17) - Yahoo! Mail").Page("Inbox (17) - Yahoo!
Mail").ChildObjects(d)
For i=1 to 10
c(i).set "ON"
Next
========================================
'''script to select a mail having subject 'hi' or 'HI'
========================================
n=Browser("yahoo").Page("yahoo").WebTable("Inbox").RowCount
For i=2 to n
s=Browser("yahoo").Page("yahoo").WebTable("Inbox").GetCellData(i,7)
If lcase(trim(s))="hi" Then
Browser("yahoo").Page("yahoo").WebCheckBox("index:="&i-1).set "ON"
End If
Next
========================================
'''''Function to send a mail
========================================
Function SendMail(SendTo, Subject, Body, Attachment)
Set otl=CreateObject("Outlook.Application")
Set m=otl.CreateItem(0)
m.to=SendTo
m.Subject=Subject
m.Body=Body
If (Attachment <> "") Then
Mail.Attachments.Add(Attachment)
End If
m.Send
otl.Quit
Set m = Nothing
Set otl = Nothing
End Function
Call SendMail("nagesh.rao46@gmail.com","hi","This is test mail for testing","")
'''''''''''''''create a new text file
=====================================================
Dim fs,f
Set fs=CreateObject("Scripting.FileSystemObject")
Set f=fs.CreateTextFile("e:file1.txt")
f.WriteLine "hello"
f.WriteLine "this is sample data"
f.Close
Set fs=nothing
=====================================================
'''''''''''''''read data from a text file
=====================================================
Dim fs,f
Set fs=CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile("e:file1.txt",1)
While f.AtEndOfLine<>True
msgbox f.ReadLine
Wend
f.Close
Set fs=nothing
=====================================================
''''''''''create a new excel file and write data
=====================================================
Dim xl,wb,ws
Set xl=CreateObject("Excel.Application")
Set wb=xl.Workbooks.Add
Set ws=wb.Worksheets("sheet1")
ws.cells(1,1)=10
ws.cells(2,1)=20
ws.cells(3,1)=50
wb.SaveAs "e:file1.xls"
wb.Close
Set xl=nothing
=====================================================
'''''''open existing file and write data in second column in Sheet1
=====================================================
Dim xl,wb,ws
Set xl=CreateObject("Excel.Application")
Set wb=xl.Workbooks.Open("e:file1.xls")
Set ws=wb.Worksheets("sheet1")
ws.cells(1,2)="Testing"
ws.cells(2,2)="hyd"
ws.cells(3,2)="ap"
wb.Save
wb.Close
Set xl=nothing
=====================================================
'''''''''''read data from excel from rows and columns
=====================================================
Dim xl,wb,ws
Set xl=CreateObject("Excel.Application")
Set wb=xl.Workbooks.Open("e:file1.xls")
Set ws=wb.Worksheets("sheet1")
r=ws.usedrange.rows.count
c=ws.usedrange.columns.count
For i=1 to r
v=""
For j=1 to c
v=v&" "& ws.cells(i,j)
Next
print v
print "-----------------------"
Next
wb.Close
Set xl=nothing
======================================================
''''''''''''''''get the bgcolor in a cell in excel
======================================================
Dim xl,wb,ws
Set xl=CreateObject("Excel.Application")
Set wb=xl.Workbooks.Open("e:file3.xls")
Set ws=wb.Worksheets("sheet1")
r=ws.usedrange.rows.count
c=ws.usedrange.columns.count
For i=1 to r
For j=1 to c
x=ws.cells(i,j).interior.colorindex
msgbox x
Next
Next
wb.Close
Set xl=nothing
======================================================='
'''''''''''''''''''''create word and write data
=======================================================
dim mw
set mw=CreateObject("Word.Application")
mw.Documents.Add
mw.selection.typetext "hello"
mw.ActiveDocument.SaveAs "e:file1.doc"
mw.quit
set mw=nothing
=======================================================
''''''''''script will display all the doc files in all the drives in the system
========================================================
Dim mw
Set mw=CreateObject("Word.Application")
Set fs=createobject("Scripting.FileSystemObject")
Set d=fs.Drives
mw.FileSearch.FileName="*.doc"
For each dr in d
msgbox dr
mw.FileSearch.LookIn=dr
mw.FileSearch.SearchSubFolders=True
mw.FileSearch.Execute
For each i in mw.FileSearch.FoundFiles
print i
Set f=fs.GetFile(i)
print f.Name&" "&f.Size&" "&f.DateCreated
print "-------------------------------------------------------------------"
Next
Next
mw.Quit
==========================================================
'''''''''Open Internet Explorer and navigate to yahoomail
==========================================================
Dim ie
Set ie=CreateObject("InternetExplorer.Application")
ie.Visible=True
ie.Navigate "www.yahoomail.com"
x=Browser("CreationTime:=0").GetROProperty("title")
msgbox x
==========================================================
''''''Create word, Create table and write all the services names
==========================================================
Set mw = CreateObject("Word.Application")
mw.Visible = True
Set dc = mw.Documents.Add()
Set objRange = dc.Range()
dc.Tables.Add
objRange,1,3
Set objTable = dc.Tables(1)
x=1
strComputer = "."
Set wms=GetObject("winmgmts:" & strComputer & "rootcimv2")
Set colItems = wms.ExecQuery("Select * from Win32_Service")
For Each s in colItems
If x > 1 Then
objTable.Rows.Add()
End If
objTable.Cell(x, 1).Range.Font.Bold = True
objTable.Cell(x, 1).Range.Text = s.Name
objTable.Cell(x, 2).Range.text = s.DisplayName
objTable.Cell(x, 3).Range.text = s.State
x = x + 1
Next
*******************************************************************************************
'How do we validate links in web page and how to display linknames with status in excel
'*************************************************************************
Set objExcel=Createobject("excel.application")
objExcel.Visible=True
objExcel.Workbooks.Add
set objSheet=objExcel.ActiveSheet
objSheet.Cells(1,1)="LinkName"
set c1=objSheet.Cells(1,1)
C1.Font.color=vbblue
objSheet.Cells(1,2)="Expected URL"
set c2=objSheet.Cells(1,2)
C2.Font.color=vbblue
objSheet.Cells(1,3)="Actual URL"
set c3=objSheet.Cells(1,3)
C3.Font.color=vbblue
objSheet.Cells(1,4)="Status"
set c4=objSheet.Cells(1,4)
C4.Font.color=vbBlue
Set objDesc=Description.Create
objDesc("micclass").value="Link"
set objLinks=Browser("title:=.*").page("title:=.*").childobjects(objDesc)
msgbox objLinks.count
For i=0 to objLinks.count-35 step 1
strLinkName=Browser("title:=.*").page("title:=.*").Link("name:=.*","index:="&i).Getroproperty(
"name")
strExpUrl=Browser("title:=.*").page("title:=.*").Link("name:=.*","index:="&i).GetRoproperty("ur
l")
Browser("title:=.*").page("title:=.*").Link("name:=.*","index:="&i).click
Browser("title:=.*").Sync
strActUrl=Browser("title:=.*").GetROProperty("url")
If instr(strActUrl,strExpUrl)>0Then
Reporter.ReportEvent micPass,"Link Vaidation","Succeed"
objSheet.Cells(i+2,1)=strLinkName
objSheet.Cells(i+2,2)=strExpUrl
objSheet.Cells(i+2,3)=strActUrl
objSheet.Cells(i+2,4)="Pass"
Set C4=objSheet.Cells(i+2,4)
C4.Font.color=vbGreen
Else
Reporter.ReportEvent micFail,"Link Vaidation","Failed"
objSheet.Cells(i+2,1)=strLinkName
objSheet.Cells(i+2,2)=strExpUrl
objSheet.Cells(i+2,3)=strActUrl
objSheet.Cells(i+2,4)="Fail"
Set C4=objSheet.Cells(i+2,4)
C4.Font.color=vbRed
End If
Browser("title:=.*").Back
Next
set objWbook=objExcel.ActiveWorkbook
objWbook.SaveAs "C:OutPutdata.xls"
objExcel.Quit
Set objExcel=nothing
'*****************************************************************************
HOW DO WE VERIFY LINKS IN A WEB PAGE
******************************************************************************
On error resume next 'To handle run time error
''SystemUtil.CloseProcessByName "iexplore.exe"
Systemutil.Run "iexplore","https://login.sample.com/amserver/UI/Login"
Browser( "sample").Page("sample ").WebEdit("html id:=IDToken1").Set "56793287"
Browser("sample ").Page("sample ").WebEdit("html id:=IDToken2").Set "ranao2009"
Browser("sample ").Page("sample ").WebButton("html id:=signIn").Click
wait(10)
Browser("sample ").Dialog("text:=Security Information").Winbutton("text:=&Yes").click
If Browser("sample ").Page("sample ").Image("close_text_button").Exist(10) Then
Browser("sample ").Page("sample ").Image("close_text_button").Click
End if
Set objLinkDesc=Description.Create
objLinkDesc("micclass").value="Link"
'To count no of links in a web page
Set objLinks = Browser("sample ").Page("sample ").ChildObjects(objLinkDesc)
'Set objLinks=Browser("sample ").page("sample ").childobjects(objLinkDesc)
msgbox objLinks.count
For i=1 to objLinks.count-187 step 1
strTargetUrl=Browser("title:=.*").Page("title:=.*").Link("text:=.*","index:="&i).GetRoProperty("url")
print(strTargetUrl)
' Reporter.ReportEvent micDone,""&strTargetUrl,""
' objLinks(i).click
Browser("title:=.*").Page("title:=.*").Link("text:=.*","index:="&i).click
Browser("title:=.*").Sync
strActualUrl=Browser("title:=.*").GetROProperty("url")
Print(strActualUrl)
'Verify Link is navigating into the correct page
If instr(strTargetUrl,strActualUrl)>0 Then
Reporter.ReportEvent micPass,"Navigate to correct page","The Actual URL is"& vbcrlf
&strActualUrl& vbcrlf &"The Target URL is"& vbcrlf &strTargetUrl 'Report result to the QTP test log
Else
Reporter.ReportEvent micFail,"Navigate to wrong page","The Actual URL is"& vbcrlf
&strActualUrl& vbcrlf &"The Target URL is"& vbcrlf &strTargetUrl 'Report result to the QTP test log
End If
Browser("title:=.*").Page("title:=.*").Link("name:=SampleHomeLogo").click
Browser("title:=.*").Sync
Next
‘*************************************************************************
'How to select specified checkbox in a web table
‘***************************************************************************
intRowcount = Browser("Inbox (477) - Yahoo! Mail").Page("Inbox (477) - Yahoo!
Mail").WebTable("Inbox").RowCount()
For i=2 to intRowcount
strTxt=Browser("Inbox (477) - Yahoo! Mail").Page("Inbox (477) - Yahoo!
Mail").WebTable("Inbox").GetCellData(i,5)
If strcomp(strTxt,"FreeHotPasses")=0 Then
set objChkBox=Browser("Inbox (477) - Yahoo! Mail").Page("Inbox (477) -
Yahoo! Mail").WebTable("Inbox").ChildItem(i,2,"WebCheckBox",0)
objChkBox.set "ON"
End If
Next
‘*****************************************************************************
*****
‘Sample script on registration in realtor application
‘*****************************************************************************
**
systemutil.Run "iexplore","www.realtor.com"
If Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate
Listings,").WebElement("Welcome | Sign In | Sign").Exist Then
reporter.ReportEvent micPass,"Step 1","Test is Pass"
Else
Reporter.ReportEvent micFail,"Step 1","Test is Fail"
End if
Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").Link("Sign Up").Click
If Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate
Listings,").WebElement("SIGN UP").Exist Then
Reporter.ReportEvent micPass,"Step2","Test is Pass"
else
Reporter.ReportEvent micFail,"Step 2","Test is Fail"
End if
UserId="nagesh.rao49"
Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").WebEdit("WebEdit").Set
UserId&"@gmail.com"
Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate
Listings,").WebEdit("WebEdit_2").SetSecure "4c697cca0717f1d0d617bead25615149f6b4"
Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate
Listings,").WebEdit("WebEdit_3").SetSecure "4c697cce3c61c2ec9481da3cd6ab89da7bd9"
Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").WebList("select").Select
"Female"
Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").WebEdit("WebEdit_4").Set
"1980"
Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").Link("Sign Up_2").Click
If Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").WebElement("THANK
YOU").Exist Then
Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").Link("CLOSE").Click
End if
‘***********************************************************************
' How to delete cookies
‘*************************************************************************
systemutil.Run "iexplore","www.realtor.com"
webutil.DeleteCookies
systemutil.CloseDescendentProcesses
‘************************************************************************
'How to validate Links in specified web page
‘***************************************************************************
Set objLinkDesc=Description.Create
objLinkDesc("micclass").value="Link"
set objLinks=Browser("title:=.*").Page("title:=.*").ChildObjects(objLinkDesc)
msgbox objLinks.count
For i=0 to objLinks.count-5
strExpUrl=
Browser("title:=.*").page("title:=.*").Link("text:=.*","index:="&i).Getroproperty("url")
Browser("title:=.*").page("title:=.*").Link("text:=.*","index:="&i).click
' strExpUrl=objLinks(i).Getroproperty("url")
'Browser("title:=.*").page("title:=.*").Link("text:=.*","index:="&i).click
'objLinks(i).click
Browser("title:=.*").Sync
strActUrl=Browser("title:=.*").GetROProperty("url")
If instr( strExpUrl,strActUrl)>0 Then
Reporter.ReportEvent micPass,"Link validation","Test is pass"
Else
Reporter.ReportEvent micFail,"Link validation","Test is Fail"
End If
Browser("title:=.*").Back
'Browser("Commercial Real Estate").Page("Commercial Real Estate").Image("REALTOR.com® -
Official").Click
Browser("title:=.*").Sync
'wait(10)
Next
‘****************************************************************
'How to set link names of specified page and keep them into a excel file
‘****************************************************************
Set objExcel=Createobject("Excel.application")
objExcel.Visible=True
objExcel.Workbooks.Add
set objsheet=objExcel.ActiveSheet
objsheet.cells(1,1)="LinkName"
set C=objsheet.cells(1,1)
c.font.color=vbblue
Set objLinkdesc=Description.Create
objLinkdesc("micclass").value="Link"
Set
objLinks=Browser("title:=.*").Page("title:=.*").ChildObjects(objLinkdesc)
For i=0 to objLinks.count-1
strLinkname=objLinks(i).GetRoproperty("name")
objsheet.cells(i+2,1)=strLinkname
Next
set objWbook=objExcel.ActiveWorkbook
objWbook.SaveAs("C:Demo.xls")
objExcel.Quit
Set objExcel=nothing
‘*****************************************************************************
*********
p = Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").WebElement("Welcome,
nagesh.rao48").GetROProperty("innertext")
arr=split(p,",")
If trim(arr(1))=UserId Then
Reporter.ReportEvent micPass,"Step 3","Test is Pass"
Else
Reporter.ReportEvent micFail,"Step 3","Test is Fail"
End If
‘***********************************************************************
‘************************************************************************
'How to focus the cursor on the object and howto select the itemsfrom dropdown
‘*************************************************************************
x = Browser("Google").Page("Google").WebEdit("q").GetROProperty("abs_x")
y=Browser("Google").Page("Google").WebEdit("q").GetROProperty("abs_y")
'
Set objDevice=Createobject("mercury.Devicereplay")
objDevice.Mouseclick x,y,0
Set objShell=Createobject("wscript.shell")
objShell.SendKeys "q"
wait(4)
Set objDesc=Description.Create
objDesc("micclass").value="WebElement"
objDesc("name").value="Google Search"
set objWele=Browser("Google").Page("Google").WebTable("qtp interview
questions").ChildObjects(objDesc)
msgbox objWele.count
For i= 0 to objWele.count-1 step 1
objShell.SendKeys"{DOWN}"
strName=objWele(i).GetRoproperty("innertext")
Reporter.ReportEvent micDone,"Item Name--"&strName,"Item Captured"
Next
Set objDevice=Nothing
Set objShell=nothing
******************************************************************************
**********************
'How to focus the cursor on the object
'Browser("Google").Page("Welcome: Mercury Tours").Image("Desinations").Click
'x=Browser("Google").Page("Welcome: Mercury
Tours").Image("Desinations").GetROProperty("abs_x")
'y=Browser("Google").Page("Welcome: Mercury
Tours").Image("Desinations").GetROProperty("abs_y")
'
' Set objDevice=Createobject("Mercury.Devicereplay")
' objDevice.MouseMove x,y
' wait(10)
''*****************************************************************************
*************************************

More Related Content

What's hot

jQuery
jQueryjQuery
jQuery
Cheng-Yu Lin
 
Intro to HTML5 Web Storage
Intro to HTML5 Web StorageIntro to HTML5 Web Storage
Intro to HTML5 Web Storage
dylanks
 
Creating, Updating and Deleting Document in MongoDB
Creating, Updating and Deleting Document in MongoDBCreating, Updating and Deleting Document in MongoDB
Creating, Updating and Deleting Document in MongoDB
Wildan Maulana
 
Hidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard LibraryHidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard Library
doughellmann
 
2012 oct-12 - java script inheritance
2012 oct-12 - java script inheritance2012 oct-12 - java script inheritance
2012 oct-12 - java script inheritance
pedro.carvalho
 
Mongo db readingdocumentusecases
Mongo db readingdocumentusecasesMongo db readingdocumentusecases
Mongo db readingdocumentusecases
zarigatongy
 
Webinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDBWebinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDB
MongoDB
 
Persistencia de datos con Parse
Persistencia de datos con ParsePersistencia de datos con Parse
Persistencia de datos con Parse
Alfonso Alba
 
jQuery. Write less. Do More.
jQuery. Write less. Do More.jQuery. Write less. Do More.
jQuery. Write less. Do More.
Dennis Loktionov
 
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
Dave Stokes
 
Latinoware
LatinowareLatinoware
Latinoware
kchodorow
 
PostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL SuperpowersPostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL Superpowers
Amanda Gilmore
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
kchodorow
 
Python Files
Python FilesPython Files
Python Files
Vikram Nandini
 
Asp.net create delete directory folder in c# vb.net
Asp.net   create delete directory folder in c# vb.netAsp.net   create delete directory folder in c# vb.net
Asp.net create delete directory folder in c# vb.net
relekarsushant
 
2017-06-22 Documentation as code
2017-06-22 Documentation as code2017-06-22 Documentation as code
2017-06-22 Documentation as code
Jérémie Bresson
 
Dojo: Beautiful Web Apps, Fast
Dojo: Beautiful Web Apps, FastDojo: Beautiful Web Apps, Fast
Dojo: Beautiful Web Apps, Fast
Gabriel Hamilton
 
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
Liwei Chou
 
Indexing
IndexingIndexing
Indexing
Mike Dirolf
 
Testable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptTestable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScript
Jon Kruger
 

What's hot (20)

jQuery
jQueryjQuery
jQuery
 
Intro to HTML5 Web Storage
Intro to HTML5 Web StorageIntro to HTML5 Web Storage
Intro to HTML5 Web Storage
 
Creating, Updating and Deleting Document in MongoDB
Creating, Updating and Deleting Document in MongoDBCreating, Updating and Deleting Document in MongoDB
Creating, Updating and Deleting Document in MongoDB
 
Hidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard LibraryHidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard Library
 
2012 oct-12 - java script inheritance
2012 oct-12 - java script inheritance2012 oct-12 - java script inheritance
2012 oct-12 - java script inheritance
 
Mongo db readingdocumentusecases
Mongo db readingdocumentusecasesMongo db readingdocumentusecases
Mongo db readingdocumentusecases
 
Webinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDBWebinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDB
 
Persistencia de datos con Parse
Persistencia de datos con ParsePersistencia de datos con Parse
Persistencia de datos con Parse
 
jQuery. Write less. Do More.
jQuery. Write less. Do More.jQuery. Write less. Do More.
jQuery. Write less. Do More.
 
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
 
Latinoware
LatinowareLatinoware
Latinoware
 
PostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL SuperpowersPostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL Superpowers
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
 
Python Files
Python FilesPython Files
Python Files
 
Asp.net create delete directory folder in c# vb.net
Asp.net   create delete directory folder in c# vb.netAsp.net   create delete directory folder in c# vb.net
Asp.net create delete directory folder in c# vb.net
 
2017-06-22 Documentation as code
2017-06-22 Documentation as code2017-06-22 Documentation as code
2017-06-22 Documentation as code
 
Dojo: Beautiful Web Apps, Fast
Dojo: Beautiful Web Apps, FastDojo: Beautiful Web Apps, Fast
Dojo: Beautiful Web Apps, Fast
 
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
 
Indexing
IndexingIndexing
Indexing
 
Testable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptTestable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScript
 

Viewers also liked

Moment of truth
Moment of truthMoment of truth
Moment of truth
Puneet Bhatnagar
 
Formulación inorgánica
Formulación inorgánicaFormulación inorgánica
Formulación inorgánicabesteiroalonso
 
M.press n 11 12
M.press n 11 12M.press n 11 12
M.press n 11 12Maike Loes
 
Pitching a business
Pitching a businessPitching a business
Pitching a business
Subramanyam Kasibhat
 
Marxism
MarxismMarxism
Marxism
mhill52
 
Cor animatore-missionario-04
Cor animatore-missionario-04Cor animatore-missionario-04
Cor animatore-missionario-04Maike Loes
 
Alluren of prototype-based OOP
Alluren of prototype-based OOPAlluren of prototype-based OOP
Alluren of prototype-based OOPazuma satoshi
 
Trabajo informatica camping
Trabajo informatica campingTrabajo informatica camping
Trabajo informatica campingjuanortegaperez
 
Presentation1
Presentation1Presentation1
Presentation1
Migena Love
 
Giornata in memoria dei missionari martiri
Giornata in memoria dei missionari martiriGiornata in memoria dei missionari martiri
Giornata in memoria dei missionari martiri
Maike Loes
 
Passport extra curricular yr 7 abs
Passport extra curricular yr 7 absPassport extra curricular yr 7 abs
Passport extra curricular yr 7 abs
stoliros
 
Geo Explor
Geo ExplorGeo Explor
Geo Explor
ajcmiller
 
V3+ Caltech+ M I T+ Enterprise+ Forum+ + Social+ Networking
V3+ Caltech+ M I T+ Enterprise+ Forum+ + Social+ NetworkingV3+ Caltech+ M I T+ Enterprise+ Forum+ + Social+ Networking
V3+ Caltech+ M I T+ Enterprise+ Forum+ + Social+ Networking
socialmediamid
 
Hw to factor
Hw to factorHw to factor
Hw to factor
41142391
 
Lc portuguese toolbox_i_booklet
Lc portuguese toolbox_i_bookletLc portuguese toolbox_i_booklet
Lc portuguese toolbox_i_booklet
Ricardo Monteiro
 
ライブコーディング(?)で学ぶPerlオブジェクト指向
ライブコーディング(?)で学ぶPerlオブジェクト指向ライブコーディング(?)で学ぶPerlオブジェクト指向
ライブコーディング(?)で学ぶPerlオブジェクト指向azuma satoshi
 
MOSES: Community finding using Model-based Overlapping Seed ExpanSion
MOSES: Community finding using Model-based Overlapping Seed ExpanSionMOSES: Community finding using Model-based Overlapping Seed ExpanSion
MOSES: Community finding using Model-based Overlapping Seed ExpanSion
aaronmcdaid
 
Computer’s evolution By Bobby King and Michael McWilliams
Computer’s evolution By Bobby King and Michael McWilliamsComputer’s evolution By Bobby King and Michael McWilliams
Computer’s evolution By Bobby King and Michael McWilliams
LostHunter
 
Dasar pakatan rakyat
Dasar pakatan rakyatDasar pakatan rakyat
Dasar pakatan rakyat
pakatanrakyat
 

Viewers also liked (20)

Moment of truth
Moment of truthMoment of truth
Moment of truth
 
Formulación inorgánica
Formulación inorgánicaFormulación inorgánica
Formulación inorgánica
 
M.press n 11 12
M.press n 11 12M.press n 11 12
M.press n 11 12
 
Pitching a business
Pitching a businessPitching a business
Pitching a business
 
Marxism
MarxismMarxism
Marxism
 
Cor animatore-missionario-04
Cor animatore-missionario-04Cor animatore-missionario-04
Cor animatore-missionario-04
 
Alluren of prototype-based OOP
Alluren of prototype-based OOPAlluren of prototype-based OOP
Alluren of prototype-based OOP
 
Trabajo informatica camping
Trabajo informatica campingTrabajo informatica camping
Trabajo informatica camping
 
Presentation1
Presentation1Presentation1
Presentation1
 
Giornata in memoria dei missionari martiri
Giornata in memoria dei missionari martiriGiornata in memoria dei missionari martiri
Giornata in memoria dei missionari martiri
 
Passport extra curricular yr 7 abs
Passport extra curricular yr 7 absPassport extra curricular yr 7 abs
Passport extra curricular yr 7 abs
 
Geo Explor
Geo ExplorGeo Explor
Geo Explor
 
V3+ Caltech+ M I T+ Enterprise+ Forum+ + Social+ Networking
V3+ Caltech+ M I T+ Enterprise+ Forum+ + Social+ NetworkingV3+ Caltech+ M I T+ Enterprise+ Forum+ + Social+ Networking
V3+ Caltech+ M I T+ Enterprise+ Forum+ + Social+ Networking
 
Triángulos
TriángulosTriángulos
Triángulos
 
Hw to factor
Hw to factorHw to factor
Hw to factor
 
Lc portuguese toolbox_i_booklet
Lc portuguese toolbox_i_bookletLc portuguese toolbox_i_booklet
Lc portuguese toolbox_i_booklet
 
ライブコーディング(?)で学ぶPerlオブジェクト指向
ライブコーディング(?)で学ぶPerlオブジェクト指向ライブコーディング(?)で学ぶPerlオブジェクト指向
ライブコーディング(?)で学ぶPerlオブジェクト指向
 
MOSES: Community finding using Model-based Overlapping Seed ExpanSion
MOSES: Community finding using Model-based Overlapping Seed ExpanSionMOSES: Community finding using Model-based Overlapping Seed ExpanSion
MOSES: Community finding using Model-based Overlapping Seed ExpanSion
 
Computer’s evolution By Bobby King and Michael McWilliams
Computer’s evolution By Bobby King and Michael McWilliamsComputer’s evolution By Bobby King and Michael McWilliams
Computer’s evolution By Bobby King and Michael McWilliams
 
Dasar pakatan rakyat
Dasar pakatan rakyatDasar pakatan rakyat
Dasar pakatan rakyat
 

Similar to Qtp Imp Script Examples

Excel Scripting
Excel Scripting Excel Scripting
Excel Scripting
G C Reddy Technologies
 
Format xls sheets Demo Mode
Format xls sheets Demo ModeFormat xls sheets Demo Mode
Format xls sheets Demo Mode
Jared Bourne
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second Language
Rob Dunn
 
Parameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple inputParameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple input
uanna
 
Inventory program in mca p1
Inventory program in mca p1Inventory program in mca p1
Inventory program in mca p1
rameshvvv
 
descriptive programming
descriptive programmingdescriptive programming
descriptive programming
Anand Dhana
 
Coding using jscript test complete
Coding using jscript test completeCoding using jscript test complete
Coding using jscript test complete
Viresh Doshi
 
N this article first we will create a table in a my sql database and then we ...
N this article first we will create a table in a my sql database and then we ...N this article first we will create a table in a my sql database and then we ...
N this article first we will create a table in a my sql database and then we ...
Mark Daday
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
Sunil OS
 
Java File I/O
Java File I/OJava File I/O
Java File I/O
Canterbury HS
 
file compression/zip file.report
file compression/zip file.reportfile compression/zip file.report
file compression/zip file.report
Taslima Yasmin Tarin
 
Lecture 11.pdf
Lecture 11.pdfLecture 11.pdf
Lecture 11.pdf
SakhilejasonMsibi
 
Examplecode
ExamplecodeExamplecode
Examplecode
Sailaja Rama
 
Saving Data
Saving DataSaving Data
Saving Data
SV.CO
 
Sphinx autodoc - automated API documentation (EuroPython 2015 in Bilbao)
Sphinx autodoc - automated API documentation (EuroPython 2015 in Bilbao)Sphinx autodoc - automated API documentation (EuroPython 2015 in Bilbao)
Sphinx autodoc - automated API documentation (EuroPython 2015 in Bilbao)
Takayuki Shimizukawa
 
Get docs from sp doc library
Get docs from sp doc libraryGet docs from sp doc library
Get docs from sp doc library
Sudip Sengupta
 
Sphinx autodoc - automated api documentation - PyCon.MY 2015
Sphinx autodoc - automated api documentation - PyCon.MY 2015Sphinx autodoc - automated api documentation - PyCon.MY 2015
Sphinx autodoc - automated api documentation - PyCon.MY 2015
Takayuki Shimizukawa
 
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84
Mahmoud Samir Fayed
 
09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP
Nguyen Tuan
 
Gl qtp day 3 2
Gl qtp day 3   2Gl qtp day 3   2
Gl qtp day 3 2
Pragya Rastogi
 

Similar to Qtp Imp Script Examples (20)

Excel Scripting
Excel Scripting Excel Scripting
Excel Scripting
 
Format xls sheets Demo Mode
Format xls sheets Demo ModeFormat xls sheets Demo Mode
Format xls sheets Demo Mode
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second Language
 
Parameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple inputParameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple input
 
Inventory program in mca p1
Inventory program in mca p1Inventory program in mca p1
Inventory program in mca p1
 
descriptive programming
descriptive programmingdescriptive programming
descriptive programming
 
Coding using jscript test complete
Coding using jscript test completeCoding using jscript test complete
Coding using jscript test complete
 
N this article first we will create a table in a my sql database and then we ...
N this article first we will create a table in a my sql database and then we ...N this article first we will create a table in a my sql database and then we ...
N this article first we will create a table in a my sql database and then we ...
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
Java File I/O
Java File I/OJava File I/O
Java File I/O
 
file compression/zip file.report
file compression/zip file.reportfile compression/zip file.report
file compression/zip file.report
 
Lecture 11.pdf
Lecture 11.pdfLecture 11.pdf
Lecture 11.pdf
 
Examplecode
ExamplecodeExamplecode
Examplecode
 
Saving Data
Saving DataSaving Data
Saving Data
 
Sphinx autodoc - automated API documentation (EuroPython 2015 in Bilbao)
Sphinx autodoc - automated API documentation (EuroPython 2015 in Bilbao)Sphinx autodoc - automated API documentation (EuroPython 2015 in Bilbao)
Sphinx autodoc - automated API documentation (EuroPython 2015 in Bilbao)
 
Get docs from sp doc library
Get docs from sp doc libraryGet docs from sp doc library
Get docs from sp doc library
 
Sphinx autodoc - automated api documentation - PyCon.MY 2015
Sphinx autodoc - automated api documentation - PyCon.MY 2015Sphinx autodoc - automated api documentation - PyCon.MY 2015
Sphinx autodoc - automated api documentation - PyCon.MY 2015
 
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84
 
09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP
 
Gl qtp day 3 2
Gl qtp day 3   2Gl qtp day 3   2
Gl qtp day 3 2
 

Qtp Imp Script Examples

  • 1. FILE SYSTEM OBJECTS EXAMPLES Examples: i) Create a Folder Dim objFso Set objFso=CreateObject(“scripting.FileSystemObject”) objFso.CreateFolder “C:Documents and Settings1 Desktophyderabad” ii) Check if the Folder Exist or not? If not create the Folder Dim objFso, myFolder myFolder=”C:Documents and Settings1 Desktophyderabad” Set objFso=CreateObject(“scripting.FileSystemObject”) If Not objFso.FolderExists(myFolder) Then objFso.CreateFolder (myFolder) End If iii) Copy a Folder Dim objFso, myFolder myFolder=”C:Documents and Settings1 Desktophyderabad” Set objFso=CreateObject(“scripting.FileSystemObject”) objFso.CopyFolder myFolder,”E:abcd” iv) Delete a folder Dim objFso, myFolder myFolder=”C:Documents and Settings1Desktophyderabad” Set objFso=CreateObject(“scripting.FileSystemObject”) objFso.DeleteFolder( myFolder) 2nd Dim objFso, myFolder
  • 2. myFolder=”C:Documents and Settings1Desktophyderabad” Set objFso=CreateObject(“scripting.FileSystemObject”) If objFso.FolderExists(myFolder) Then objFso.DeleteFolder( myFolder) End If v) Return a Collection of Disk Drives Dim objFso, colDrives Set objFso=CreateObject(“scripting.FileSystemObject”) Set colDrives=objFso.Drives For Each oDrive in colDrives Msgbox oDrive Next vi) Get available space on a Drive Dim objFso Set objFso=CreateObject(“scripting.FileSystemObject”) Set myDrive=objFso.GetDrive(“D:”) Msgbox myDrive.AvailableSpace/(1024^3) & ” GB” vii) Creating a Text File Dim objFso Set objFso=CreateObject(“scripting.FileSystemObject”) objFso.CreateTextFile (“C:Documents and Settings1 Desktopabcd.txt”) objFso.CreateTextFile (“C:Documents and Settings1 Desktopabcd.doc”) objFso.CreateTextFile (“C:Documents and Settings1 Desktopabcd.xls”) objFso.CreateTextFile (“C:Documents and Settings1 Desktopabcd.pdf”) Note: We can Create other files also, but they act as Text/Flat Files viii) Check if the File Exist or not? If not create the File Dim objFso, myFile1,myFile2, myFile3, myFile4
  • 3. myFile1=”C:Documents and Settings1 Desktopabcd.txt” myFile2=”C:Documents and Settings1 Desktopabcd.doc” myFile3=”C:Documents and Settings1 Desktopabcd.xls” myFile4=”C:Documents and Settings1 Desktopabcd.pdf” Set objFso=CreateObject(“scripting.FileSystemObject”) If Not objFso.FileExists(myFile1) Then objFso.CreateTextFile (myFile1) End If If Not objFso.FileExists(myFile2) Then objFso.CreateTextFile (myFile2) End If If Not objFso.FileExists(myFile3) Then objFso.CreateTextFile (myFile3) End If If Not objFso.FileExists(myFile4) Then objFso.CreateTextFile (myFile4) End If ix) ReadData Character by Character from a text file Dim objFso, myFile, myChar Set objFso=CreateObject(“scripting.FileSystemObject”) Set myFile=objFso.OpenTextFile(“C:Documents and Settings1 Desktopabcd.txt”,1) ’1 for Read, 2 for Write and 8 for Append Do Until myFile.AtEndOfStream=True myChar=myFile.Read(1) Msgbox myChar Loop myFile.Close Set objFso=Nothing
  • 4. x)Read Line by Line from a Text File Dim objFso, myFile, myChar Set objFso=CreateObject(“scripting.FileSystemObject”) Set myFile=objFso.OpenTextFile(“C:Documents and Settings1 Desktopabcd.txt”,1) ’1 for Read, 2 for Write and 8 for Append Do Until myFile.AtEndOfStream=True myChar=myFile.ReadLine Msgbox myChar Loop myFile.Close Set objFso=Nothing xi) Data Driven Testing by fetching Test data directly from a Text file. ‘***************************************************************************** ******** ‘Test Requirement: Data Driven Testing by fetching Test data directly from a Text file. ‘Author: xyz ‘Date of Creation: 24-08-2010 ‘Pre-requasites: ‘abcd.txt (Test Data File) ‘Test Flow: ‘Create File System object ‘Open the file with Read mode and store reference into a variable ‘Skipe the first line ‘Read line by line and split the Data ‘Login Operation ‘Form Looping and pass Parameters ‘***************************************************************************** ********
  • 5. Dim objFso, myFile, myLine, myField Set objFso=CreateObject(“scripting.FileSystemObject”) Set myFile=objFso.OpenTextFile(“C:Documents and Settings1 Desktopabcd.txt”,1) ’1 for Read, 2 for Write and 8 for Append myFile.SkipLine Do Until myFile.AtEndOfStream =True myLine=myFile.ReadLine myField=Split(myLine,”,”) SystemUtil.Run “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe” Dialog(“text:=Login”).Activate Dialog(“text:=Login”).WinEdit(“attached text:=Agent Name:”).Set myField(0) Dialog(“text:=Login”).WinEdit(“attached text:=Password:”).Set myField(1) Wait 2 Dialog(“text:=Login”).WinButton(“text:=OK”).Click Window(“text:=Flight Reservation”).Close Loop myFile.Close Set objFso=Nothing xii) Write Data to a Text File Dim objFso, myFile, Result, a, b a=10: b=20 Result=a+b Set objFso=CreateObject(“scripting.FileSystemObject”) Set myFile=objFso.OpenTextFile(“C:Documents and Settings1 Desktopabcd.txt”,2) ’1 for Read, 2 for Write and 8 for Append myFile.WriteLine “Addition of a, b is: “&Result myFile.Close Set objFso=Nothing
  • 6. xiii) Delete a Text File Dim objFso Set objFso=CreateObject(“scripting.FileSystemObject”) objFso.DeleteFile(“C:Documents and Settings1 Desktopabcd.doc”) Set objFso=Nothing xiv) Check if the File Exists or not? If Exists delete the File ———– Dim objFso Set objFso=CreateObject(“scripting.FileSystemObject”) If objFso.FileExists(“C:Documents and Settings1 Desktopabcd.pdf”) Then objFso.DeleteFile(“C:Documents and Settings1 Desktopabcd.pdf”) End If Set objFso=Nothing xv) Calculate size of a Text File Dim objFso Set objFso=CreateObject(“scripting.FileSystemObject”) File_Size= objFso.GetFile(“C:Documents and Settings1 Desktopabcd.txt”).Size Msgbox File_Size& ” Bytes” Set objFso=Nothing xvi)Compare Two Text File by Size, by Text and by Binary values Option Explicit Dim objFso, File1, File2, myFile1, myFile2, File_First, File_Second, Files_Compare File1=”C:Documents and Settings1 abcd.txt” File2=”C:Documents and Settings1 desktopxyz.txt” Set objFso=CreateObject(“scripting.FileSystemObject”) ‘Comaring two text files by Size If objFso.GetFile(File1).Size= objFso.GetFile(File2).Size Then
  • 7. Msgbox “Files are Same in Size” Else Msgbox “Files are Not Same” End If ‘Comaring two text files by Text Set File_First=objFso.OpenTextFile(File1) Set File_Second=objFso.OpenTextFile(File2) myFile1=File_First.ReadAll myFile2=File_Second.ReadAll ‘Msgbox myFile1 Files_Compare=strComp(myFile1,myFile2,1) ’1 for Texual Comparision If Files_Compare=0 Then Msgbox “Files are having Same Text” Else Msgbox “Files are having Different Text” End If ‘Binary Comparision of Two Text Files Files_Compare=strComp(myFile1,myFile2,0) ’0 for Binary Comparision (It is Default mode) If Files_Compare=0 Then Msgbox “Files are Equal” Else Msgbox “Files are Not Equal” End If Set objFso=Nothing xvii) Count the number of times a word appears in a Text File Option Explicit Dim objFso, File1, myWord, myData, myFile, objRegEx, MatchesFound, TotMatches
  • 8. File1=”C:Documents and Settings1 RIGHATWAYDesktopabcd.txt” Set objFso=CreateObject(“scripting.FileSystemObject”) Set myFile=objFso.OpenTextFile(File1) myData=myFile.ReadAll myWord=”QTP” Set objRegEx= New RegExp ‘Creating Regular Expression Object objRegEx.Pattern=myWord ‘Search string objRegEx.Global=True ‘ Finding all Matches objRegEx.IgnoreCase=True ‘ Ignoring Case Set MatchesFound=objRegex.Execute(myData) ‘Executing the Total file data to find natches TotMatches=MatchesFound.Count Msgbox “Matches: “&TotMatches Set objFso=Nothing xviii) Capture all Button Names from Login dialog Box and Export to a Text File Option Explicit Dim objFso, FilePath, myFile, oButton, myButton, Buttons, i, TotButtons FilePath=”C:Documents and Settings1 RIGHATWAYDesktopabcd.txt” Set objFso=CreateObject(“scripting.FileSystemObject”) Set myFile=objFso.OpenTextFile(FilePath,2) myFile.WriteLine “Button Names” myFile.WriteLine “————” Set oButton=Description.Create oButton(“micclass”).value=”WinButton” SystemUtil.Run “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe” Set Buttons=Dialog(“text:=Login”).ChildObjects(oButton) TotButtons=Buttons.Count For i= 0 to TotButtons-1 Step 1
  • 9. myButton=Buttons(i).GetRoProperty(“text”) myFile.WriteLine myButton Next myFile.Close Set objFso=Nothing xix) Capture Customer Names from 1 to 10 Orders in FR and export to a Text File ***************************************************************** ‘Test Requirement: Capture Customer names from 1 to 10 orders ‘and export to text file ‘Test Flow: ‘Create an object in File system class ‘Open the text file in write mode using File sytem object ‘Login Operation ‘Form Loop to open 1 to 10 orders ‘capture the Customer names and write to external text file ‘***************************************************************** Dim objFso, myFile Set objFso=CreateObject(“scripting.FilesystemObject”) Set myFile=objFso.OpenTextFile(“C:Documents and Settingsgcr.GCRC- 9A12FBD3D9Desktopabc.txt”,2) myFile.WriteLine “Customer Names” myFile.WriteLine “———” If Not Window(“Flight Reservation”).Exist(3) Then SystemUtil.Run “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe”,”",”C:Program FilesHPQuickTest Professionalsamplesflightapp”,”open” Dialog(“Login”).Activate Dialog(“Login”).WinEdit(“Agent Name:”).Set “nagesh”
  • 10. Dialog(“Login”).WinEdit(“Password:”).SetSecure “4c9e05a626f9b6471971fb15474e791b28cc1ed0″ Dialog(“Login”).WinButton(“OK”).Click End If For Order_Number= 1 to 10 step 1 Window(“Flight Reservation”).Activate Window(“Flight Reservation”).WinButton(“Button”).Click Window(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON” Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set Order_Number Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).Click wait 2 Customer_Name = Window(“Flight Reservation”).WinEdit(“Name:”).GetVisibleText() myFile.WriteLine Customer_Name Next myFile.Close Set objFso=Nothing
  • 11. HOW TO WORK WITH EXCEL '''Script to create a new excel file , write data '''save the file with read and write protected '''''pwd1 is for read protected pwd2 is for write protected Set xl=CreateObject("Excel.Application") Set wb=xl.Workbooks.Add xl.DisplayAlerts=False Set ws=wb.Worksheets("sheet1") ws.cells(1,1)=100 ws.cells(1,2)=200 wb.Saveas "e:data2.xls",,"pwd1","pwd2" wb.Close Set xl=nothing '''Script to open excel file ,which is read and write protected write data '''''pwd1 is for read protected pwd2 is for write protected Set xl=CreateObject("Excel.Application") Set wb=xl.Workbooks.Open("e:data2.xls",0,False,5,"pwd1","pwd2") xl.DisplayAlerts=False Set ws=wb.Worksheets("sheet1") ws.cells(1,2)="hello" ws.cells(2,2)="new data" wb.Save wb.Close Set xl=nothing ''Script to get the list of links in Google and do spell check =============================================================== dim d set mw=CreateObject("Word.Application") set d=Description.Create d("micclass").value="Link" set a=Browser("Google").page("Google").childobjects(d) for i=0 to a.count-1 mw.WordBasic.filenew s=a(i).getROProperty("innertext") mw.WordBasic.insert s if mw.ActiveDocument.Spellingerrors.count>0 then Reporter.ReportEvent 1,"Spelling","spelling error :"&s end if mw.ActiveDocument.Close(False) next
  • 12. mw.quit set mw=nothing ========================================= ''''Script to check ON the checkboxes in yahoo mail inbox ========================================= Dim d Set d=Description.Create d("micclass").value="WebCheckBox" Set c=Browser("Inbox (17) - Yahoo! Mail").Page("Inbox (17) - Yahoo! Mail").ChildObjects(d) For i=1 to 10 c(i).set "ON" Next ======================================== '''script to select a mail having subject 'hi' or 'HI' ======================================== n=Browser("yahoo").Page("yahoo").WebTable("Inbox").RowCount For i=2 to n s=Browser("yahoo").Page("yahoo").WebTable("Inbox").GetCellData(i,7) If lcase(trim(s))="hi" Then Browser("yahoo").Page("yahoo").WebCheckBox("index:="&i-1).set "ON" End If Next ======================================== '''''Function to send a mail ======================================== Function SendMail(SendTo, Subject, Body, Attachment) Set otl=CreateObject("Outlook.Application") Set m=otl.CreateItem(0) m.to=SendTo m.Subject=Subject m.Body=Body If (Attachment <> "") Then Mail.Attachments.Add(Attachment) End If m.Send otl.Quit Set m = Nothing Set otl = Nothing End Function Call SendMail("nagesh.rao46@gmail.com","hi","This is test mail for testing","") '''''''''''''''create a new text file ===================================================== Dim fs,f Set fs=CreateObject("Scripting.FileSystemObject") Set f=fs.CreateTextFile("e:file1.txt")
  • 13. f.WriteLine "hello" f.WriteLine "this is sample data" f.Close Set fs=nothing ===================================================== '''''''''''''''read data from a text file ===================================================== Dim fs,f Set fs=CreateObject("Scripting.FileSystemObject") Set f=fs.OpenTextFile("e:file1.txt",1) While f.AtEndOfLine<>True msgbox f.ReadLine Wend f.Close Set fs=nothing ===================================================== ''''''''''create a new excel file and write data ===================================================== Dim xl,wb,ws Set xl=CreateObject("Excel.Application") Set wb=xl.Workbooks.Add Set ws=wb.Worksheets("sheet1") ws.cells(1,1)=10 ws.cells(2,1)=20 ws.cells(3,1)=50 wb.SaveAs "e:file1.xls" wb.Close Set xl=nothing ===================================================== '''''''open existing file and write data in second column in Sheet1 ===================================================== Dim xl,wb,ws Set xl=CreateObject("Excel.Application") Set wb=xl.Workbooks.Open("e:file1.xls") Set ws=wb.Worksheets("sheet1") ws.cells(1,2)="Testing" ws.cells(2,2)="hyd" ws.cells(3,2)="ap" wb.Save wb.Close Set xl=nothing ===================================================== '''''''''''read data from excel from rows and columns ===================================================== Dim xl,wb,ws Set xl=CreateObject("Excel.Application")
  • 14. Set wb=xl.Workbooks.Open("e:file1.xls") Set ws=wb.Worksheets("sheet1") r=ws.usedrange.rows.count c=ws.usedrange.columns.count For i=1 to r v="" For j=1 to c v=v&" "& ws.cells(i,j) Next print v print "-----------------------" Next wb.Close Set xl=nothing ====================================================== ''''''''''''''''get the bgcolor in a cell in excel ====================================================== Dim xl,wb,ws Set xl=CreateObject("Excel.Application") Set wb=xl.Workbooks.Open("e:file3.xls") Set ws=wb.Worksheets("sheet1") r=ws.usedrange.rows.count c=ws.usedrange.columns.count For i=1 to r For j=1 to c x=ws.cells(i,j).interior.colorindex msgbox x Next Next wb.Close Set xl=nothing =======================================================' '''''''''''''''''''''create word and write data ======================================================= dim mw set mw=CreateObject("Word.Application") mw.Documents.Add mw.selection.typetext "hello" mw.ActiveDocument.SaveAs "e:file1.doc" mw.quit set mw=nothing ======================================================= ''''''''''script will display all the doc files in all the drives in the system ======================================================== Dim mw Set mw=CreateObject("Word.Application")
  • 15. Set fs=createobject("Scripting.FileSystemObject") Set d=fs.Drives mw.FileSearch.FileName="*.doc" For each dr in d msgbox dr mw.FileSearch.LookIn=dr mw.FileSearch.SearchSubFolders=True mw.FileSearch.Execute For each i in mw.FileSearch.FoundFiles print i Set f=fs.GetFile(i) print f.Name&" "&f.Size&" "&f.DateCreated print "-------------------------------------------------------------------" Next Next mw.Quit ========================================================== '''''''''Open Internet Explorer and navigate to yahoomail ========================================================== Dim ie Set ie=CreateObject("InternetExplorer.Application") ie.Visible=True ie.Navigate "www.yahoomail.com" x=Browser("CreationTime:=0").GetROProperty("title") msgbox x ========================================================== ''''''Create word, Create table and write all the services names ========================================================== Set mw = CreateObject("Word.Application") mw.Visible = True Set dc = mw.Documents.Add() Set objRange = dc.Range() dc.Tables.Add objRange,1,3 Set objTable = dc.Tables(1) x=1 strComputer = "." Set wms=GetObject("winmgmts:" & strComputer & "rootcimv2") Set colItems = wms.ExecQuery("Select * from Win32_Service") For Each s in colItems If x > 1 Then objTable.Rows.Add() End If objTable.Cell(x, 1).Range.Font.Bold = True objTable.Cell(x, 1).Range.Text = s.Name objTable.Cell(x, 2).Range.text = s.DisplayName
  • 16. objTable.Cell(x, 3).Range.text = s.State x = x + 1 Next ******************************************************************************************* 'How do we validate links in web page and how to display linknames with status in excel '************************************************************************* Set objExcel=Createobject("excel.application") objExcel.Visible=True objExcel.Workbooks.Add set objSheet=objExcel.ActiveSheet objSheet.Cells(1,1)="LinkName" set c1=objSheet.Cells(1,1) C1.Font.color=vbblue objSheet.Cells(1,2)="Expected URL" set c2=objSheet.Cells(1,2) C2.Font.color=vbblue objSheet.Cells(1,3)="Actual URL" set c3=objSheet.Cells(1,3) C3.Font.color=vbblue objSheet.Cells(1,4)="Status" set c4=objSheet.Cells(1,4) C4.Font.color=vbBlue Set objDesc=Description.Create objDesc("micclass").value="Link" set objLinks=Browser("title:=.*").page("title:=.*").childobjects(objDesc) msgbox objLinks.count
  • 17. For i=0 to objLinks.count-35 step 1 strLinkName=Browser("title:=.*").page("title:=.*").Link("name:=.*","index:="&i).Getroproperty( "name") strExpUrl=Browser("title:=.*").page("title:=.*").Link("name:=.*","index:="&i).GetRoproperty("ur l") Browser("title:=.*").page("title:=.*").Link("name:=.*","index:="&i).click Browser("title:=.*").Sync strActUrl=Browser("title:=.*").GetROProperty("url") If instr(strActUrl,strExpUrl)>0Then Reporter.ReportEvent micPass,"Link Vaidation","Succeed" objSheet.Cells(i+2,1)=strLinkName objSheet.Cells(i+2,2)=strExpUrl objSheet.Cells(i+2,3)=strActUrl objSheet.Cells(i+2,4)="Pass" Set C4=objSheet.Cells(i+2,4) C4.Font.color=vbGreen Else Reporter.ReportEvent micFail,"Link Vaidation","Failed" objSheet.Cells(i+2,1)=strLinkName objSheet.Cells(i+2,2)=strExpUrl objSheet.Cells(i+2,3)=strActUrl objSheet.Cells(i+2,4)="Fail" Set C4=objSheet.Cells(i+2,4) C4.Font.color=vbRed End If Browser("title:=.*").Back
  • 18. Next set objWbook=objExcel.ActiveWorkbook objWbook.SaveAs "C:OutPutdata.xls" objExcel.Quit Set objExcel=nothing '***************************************************************************** HOW DO WE VERIFY LINKS IN A WEB PAGE ****************************************************************************** On error resume next 'To handle run time error ''SystemUtil.CloseProcessByName "iexplore.exe" Systemutil.Run "iexplore","https://login.sample.com/amserver/UI/Login" Browser( "sample").Page("sample ").WebEdit("html id:=IDToken1").Set "56793287" Browser("sample ").Page("sample ").WebEdit("html id:=IDToken2").Set "ranao2009" Browser("sample ").Page("sample ").WebButton("html id:=signIn").Click wait(10) Browser("sample ").Dialog("text:=Security Information").Winbutton("text:=&Yes").click If Browser("sample ").Page("sample ").Image("close_text_button").Exist(10) Then Browser("sample ").Page("sample ").Image("close_text_button").Click End if Set objLinkDesc=Description.Create objLinkDesc("micclass").value="Link" 'To count no of links in a web page Set objLinks = Browser("sample ").Page("sample ").ChildObjects(objLinkDesc) 'Set objLinks=Browser("sample ").page("sample ").childobjects(objLinkDesc) msgbox objLinks.count For i=1 to objLinks.count-187 step 1 strTargetUrl=Browser("title:=.*").Page("title:=.*").Link("text:=.*","index:="&i).GetRoProperty("url") print(strTargetUrl) ' Reporter.ReportEvent micDone,""&strTargetUrl,"" ' objLinks(i).click Browser("title:=.*").Page("title:=.*").Link("text:=.*","index:="&i).click Browser("title:=.*").Sync strActualUrl=Browser("title:=.*").GetROProperty("url") Print(strActualUrl) 'Verify Link is navigating into the correct page If instr(strTargetUrl,strActualUrl)>0 Then Reporter.ReportEvent micPass,"Navigate to correct page","The Actual URL is"& vbcrlf &strActualUrl& vbcrlf &"The Target URL is"& vbcrlf &strTargetUrl 'Report result to the QTP test log Else Reporter.ReportEvent micFail,"Navigate to wrong page","The Actual URL is"& vbcrlf &strActualUrl& vbcrlf &"The Target URL is"& vbcrlf &strTargetUrl 'Report result to the QTP test log
  • 19. End If Browser("title:=.*").Page("title:=.*").Link("name:=SampleHomeLogo").click Browser("title:=.*").Sync Next ‘************************************************************************* 'How to select specified checkbox in a web table ‘*************************************************************************** intRowcount = Browser("Inbox (477) - Yahoo! Mail").Page("Inbox (477) - Yahoo! Mail").WebTable("Inbox").RowCount() For i=2 to intRowcount strTxt=Browser("Inbox (477) - Yahoo! Mail").Page("Inbox (477) - Yahoo! Mail").WebTable("Inbox").GetCellData(i,5) If strcomp(strTxt,"FreeHotPasses")=0 Then set objChkBox=Browser("Inbox (477) - Yahoo! Mail").Page("Inbox (477) - Yahoo! Mail").WebTable("Inbox").ChildItem(i,2,"WebCheckBox",0) objChkBox.set "ON" End If Next ‘***************************************************************************** ***** ‘Sample script on registration in realtor application ‘***************************************************************************** ** systemutil.Run "iexplore","www.realtor.com"
  • 20. If Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").WebElement("Welcome | Sign In | Sign").Exist Then reporter.ReportEvent micPass,"Step 1","Test is Pass" Else Reporter.ReportEvent micFail,"Step 1","Test is Fail" End if Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").Link("Sign Up").Click If Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").WebElement("SIGN UP").Exist Then Reporter.ReportEvent micPass,"Step2","Test is Pass" else Reporter.ReportEvent micFail,"Step 2","Test is Fail" End if UserId="nagesh.rao49" Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").WebEdit("WebEdit").Set UserId&"@gmail.com" Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").WebEdit("WebEdit_2").SetSecure "4c697cca0717f1d0d617bead25615149f6b4" Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").WebEdit("WebEdit_3").SetSecure "4c697cce3c61c2ec9481da3cd6ab89da7bd9" Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").WebList("select").Select "Female" Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").WebEdit("WebEdit_4").Set "1980" Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").Link("Sign Up_2").Click
  • 21. If Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").WebElement("THANK YOU").Exist Then Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").Link("CLOSE").Click End if ‘*********************************************************************** ' How to delete cookies ‘************************************************************************* systemutil.Run "iexplore","www.realtor.com" webutil.DeleteCookies systemutil.CloseDescendentProcesses ‘************************************************************************ 'How to validate Links in specified web page ‘*************************************************************************** Set objLinkDesc=Description.Create objLinkDesc("micclass").value="Link" set objLinks=Browser("title:=.*").Page("title:=.*").ChildObjects(objLinkDesc) msgbox objLinks.count For i=0 to objLinks.count-5 strExpUrl= Browser("title:=.*").page("title:=.*").Link("text:=.*","index:="&i).Getroproperty("url") Browser("title:=.*").page("title:=.*").Link("text:=.*","index:="&i).click ' strExpUrl=objLinks(i).Getroproperty("url") 'Browser("title:=.*").page("title:=.*").Link("text:=.*","index:="&i).click
  • 22. 'objLinks(i).click Browser("title:=.*").Sync strActUrl=Browser("title:=.*").GetROProperty("url") If instr( strExpUrl,strActUrl)>0 Then Reporter.ReportEvent micPass,"Link validation","Test is pass" Else Reporter.ReportEvent micFail,"Link validation","Test is Fail" End If Browser("title:=.*").Back 'Browser("Commercial Real Estate").Page("Commercial Real Estate").Image("REALTOR.com® - Official").Click Browser("title:=.*").Sync 'wait(10) Next ‘**************************************************************** 'How to set link names of specified page and keep them into a excel file ‘**************************************************************** Set objExcel=Createobject("Excel.application") objExcel.Visible=True objExcel.Workbooks.Add set objsheet=objExcel.ActiveSheet objsheet.cells(1,1)="LinkName" set C=objsheet.cells(1,1) c.font.color=vbblue Set objLinkdesc=Description.Create
  • 23. objLinkdesc("micclass").value="Link" Set objLinks=Browser("title:=.*").Page("title:=.*").ChildObjects(objLinkdesc) For i=0 to objLinks.count-1 strLinkname=objLinks(i).GetRoproperty("name") objsheet.cells(i+2,1)=strLinkname Next set objWbook=objExcel.ActiveWorkbook objWbook.SaveAs("C:Demo.xls") objExcel.Quit Set objExcel=nothing ‘***************************************************************************** ********* p = Browser("Inbox (477) - Yahoo! Mail").Page("Real Estate Listings,").WebElement("Welcome, nagesh.rao48").GetROProperty("innertext") arr=split(p,",") If trim(arr(1))=UserId Then Reporter.ReportEvent micPass,"Step 3","Test is Pass" Else Reporter.ReportEvent micFail,"Step 3","Test is Fail"
  • 24. End If ‘*********************************************************************** ‘************************************************************************ 'How to focus the cursor on the object and howto select the itemsfrom dropdown ‘************************************************************************* x = Browser("Google").Page("Google").WebEdit("q").GetROProperty("abs_x") y=Browser("Google").Page("Google").WebEdit("q").GetROProperty("abs_y") ' Set objDevice=Createobject("mercury.Devicereplay") objDevice.Mouseclick x,y,0 Set objShell=Createobject("wscript.shell") objShell.SendKeys "q" wait(4) Set objDesc=Description.Create objDesc("micclass").value="WebElement" objDesc("name").value="Google Search" set objWele=Browser("Google").Page("Google").WebTable("qtp interview questions").ChildObjects(objDesc) msgbox objWele.count For i= 0 to objWele.count-1 step 1 objShell.SendKeys"{DOWN}"
  • 25. strName=objWele(i).GetRoproperty("innertext") Reporter.ReportEvent micDone,"Item Name--"&strName,"Item Captured" Next Set objDevice=Nothing Set objShell=nothing ****************************************************************************** ********************** 'How to focus the cursor on the object 'Browser("Google").Page("Welcome: Mercury Tours").Image("Desinations").Click 'x=Browser("Google").Page("Welcome: Mercury Tours").Image("Desinations").GetROProperty("abs_x") 'y=Browser("Google").Page("Welcome: Mercury Tours").Image("Desinations").GetROProperty("abs_y") ' ' Set objDevice=Createobject("Mercury.Devicereplay") ' objDevice.MouseMove x,y ' wait(10) ''***************************************************************************** *************************************