Wednesday, 29 January 2014

Simple VB Script for QTP Beginners

A simple VB Script program for QTP beginners.

1. Open Yahoo mail
2. Insert your user name and password and click OK
3. Compose a new mail To yourself, CC yourself, BCC Yourself
4. Fill subject
5. Attach a file
6. Fill body as you wish
7. Click OK to send the mail
8. Signout
9. Close the browser

NOTE:  Properties of the objects might change based on the browser version and OS


Option explicit
Dim bro, url, wsho '(windows shell object)
'Launch Yahoomail website using VBscript
Bro= "C:\Program Files\Internet Explorer\iexplore.exe"
url= "http://www.yahoomail.com"
invokeapplication (bro&" "&url)
'Do login using QTPscript in DP
With browser ("title:=.*")
          With.page ("title:=.*")
    .webedit ("name:=login").set "mycompanysa"
    .webedit ("name:=passwd").setsecure "52e8d58e60e8ee8c73e9428a967f2c61dd45ba0da327a"
    .webbutton("name:=Sign In").click
          End with
End with
With browser ("title:=.*")
          With.page ("title:=.*")
'Using analog i have avoided a dailogbox
Window("Microsoft Internet Explorer").RunAnalog "Track1"
end with
end with
''Go to inbox link using QTPscript in Dp
With browser ("title:=.*")
          With.page ("title:=.*")
    .link("name:=inbox", "index:=0").click
          End with
End with
'Go to new message using QTPscript with DP
With browser ("title:=.*")
          With.page ("title:=.*")
    .webbutton("name:=Compose", "index:=0").click
          End with
End with
'Fill mail compose page using QTPscript with DP
With browser ("title:=.*")
          With.page ("title:=.*")
    .webedit("name:=to").set "prasadxxx@gmail.com"
    .webedit("name:=cc").set "prasadxxx@yahoo.com"
    .webedit("name:=subj").set "QTP Automation Tool"
    .webbutton("name:=Attach Files").Click
    end with
    end with
With browser ("title:=.*")
          With.page ("title:=.*")
        .webfile("name:=uploadfile").set "C:\Documents and Settings\qa\My Documents\Testfile.jpg"
        .webbutton("name:=Attach Files").Click
        end with
        end with
With browser ("title:=.*")
          With.page ("title:=.*")
 'Automate Keyboard input for filling body using VBScript
    .webedit("name:=subj").click
           Set wsho=createobject("wscript.shell")
           Wsho.sendkeys ("{TAB}")
           Wsho.sendkeys ("{TAB}")
           Wsho.sendkeys ("Hi There, How are you doing………")
'Keyboard automation completed
    .webbutton("name:=send", "index:=0").click          
            End with
End with
'Do logout using QTPscript in DP
With browser("title:=.*")
          With.page("title:=.*")
    .link("name:=Sign Out").click
            End with
End with
'Close Yahoo website using QTPscript in DP
Browser("title:=.*").close

No comments:

Post a Comment