Friday, 31 January 2014

Yahoo Mail Test Automation



Testing to find out Number of Unread Mails, Number of Mails Replied, Number of Mails with Attachments, and Number of Mails Forwarded :-)  Try It Yourself

Note:  Please ensure you check the values of properties correctly as they will change according to the yahoo mail versions that you are using

Option explicit
Dim ieo, nomp, noum, nofm, norm, noma, i, x, y, z

'launch yahoo mail websiteSet ieo=createobject("internetexplorer.application")
ieo.visible=true
ieo.navigate"http://www.mail.yahoo.com"

'login to yahoo mail
With browser("title:=.*")
        With .page("title:=.*")
            .webedit("name:=login").set "Enter a mail ID"
            .webedit("name:=passwd").setsecure "52eb84c9b61269a00a33b5b390e3f67da3ecc4f15"
            .webbutton("name:=Sign In").click
        End With
End With

'Find number of unread mails, number of mails with attachments, number of forwarded mails, and number of replied mails from the mail box
Noum=0
Norm=0
Nofm=0
Noma=0
Do
With browser("title:=.*")
          With .page("title:=.*")
          Nomp=.webtable("name:=toggleAll").rowcount
For i = 2 to Nomp step 1
    x=.webtable("name:=toggleAll").getcelldata(i,1)
    y=.webtable("name:=toggleAll").getcelldata(i,3)
    z=.webtable("name:=toggleAll").getcelldata(i,7)
    if x= "Unread" then
             noum=noum+1
    end if
    if y= " You replied to this message" then
             norm=norm+1
    end if
    if y= " You forwarded this message" then
             nofm=nofm+1
    end if
    if z= " Attachments" then
             noma=noma+1
    end if
Next

'Go to next page
If .link("name:= >", "index:=0").exist then
    .link("name:= >", "index:=0").click
    wait (3)
Else
Exit do 'statement to terminate infinite loopEnd if
End with
End with
Loop while 2>1

'Do logout With browser("title:=.*")
          With .page("title:=.*")
                    .link("name:=sign out").click
           End with
End with
set ieo=nothing

'Display output
Reporter.reportevent micdone, "Mailbox Testing",  "Get"&noum&"mails"
Reporter.reportevent micdone, "Mailbox Testing",  "Get"&norm&"mails"
Reporter.reportevent micdone, "Mailbox Testing",  "Get"&nofm&"mails"
Reporter.reportevent micdone, "Mailbox Testing",  "Get"&noma&"mails"

Thursday, 30 January 2014

Data Migration with QTP


DATA MIGRATION from Word and Text File to Excel file

Option explicit
Dim mswo, doco, pro, fso, fo, exo, wbo, wso, i
'open word document using VBScriptSet mswo=createobject("word.application")
Set doco=mswo.documents.open("C:\Documents and Settings\qa\Desktop\QTP Practice\PATH FILES\Word Grammercheck.doc")
Set pro=doco.paragraphs
'Open text file
Set fso=createobject("scripting.filesystemobject")
Set fo=fso.OpenTextFile("C:\Documents and Settings\qa\Desktop\QTP Practice\PATH FILES\Data.txt", 1)
'open new excel file
Set exo=createobject("excel.application")
Set wbo=exo.Workbooks.Add
Set wso=wbo.Worksheets("sheet1")
wso.cells(1,1)="Names"
wso.cells(1,2)="Paras"
'copy data from doc file and text file into excel file
For i = 1 to pro.count step 1
Wso.cells (i + 1, 1) = fo.readline
Wso.cells (I + 1, 2) = pro(i).range.text
next
'Close Text file
Fo.close
'Close word file
Doco.close(false)
Mswo.quit
'Save and Close excel file
Wso.rows.autofit
Wso.columns.autofit
Wso.saveas("C:\Documents and Settings\qa\Desktop\Test1.xls")
Exo.quit
Set fo=nothing
Set fso=nothing
Set pro=nothing
Set doco=nothing
Set mswo=nothing
Set wso=nothing
Set wbo=nothing
Set exo=nothing

Yahoo Mail Automation Using Excel and Word

Yahoo Mail Automation Using Excel and Word

Option explicit
Dim exo, wbo, wso, nor, i, ieo, mswo, doco, pro, t, c, s, b, wsho

'exo for excel object
'wbo for work book object in excel
'wso for work sheet object in excel
'nor for number of rows in work sheet
'i for iteration or loop
'ieo for internet explorer object
'mswo for work object
'doco for document object in word
'pro for paragraph in document
't for to address from excel
'c for cc address from excel
's for subject from excel
'wsho for automating keyboard  to send the keys through automation

'open existing excel file using VBScript
Set exo= createobject("excel.application")
Set wbo= exo.workbooks.open ("C:\Documents and Settings\qa\Desktop\QTP Practice\PATH FILES\email list.xls")
Set wso= wbo.worksheets("sheet1")
Nor= wso.usedrange.rows.count
'open existing word document using VBScript Set Mswo= createobject("word.application")
Set Doco= mswo.documents.open("C:\Documents and Settings\qa\Desktop\QTP Practice\PATH FILES\Word Spellcheck.doc")
Set pro= doco.paragraphs
'launch yahoomail website using VBScript
Set ieo= createobject ("internetexplorer.application")
ieo.visible=true
ieo.navigate ("http://www.mail.yahoo.com")
'do login yahoo using QTPScript in DP
With browser ("title:=.*")
          With.page ("title:=.*")
    .webedit ("name:=login").set "prxxxxxxx"
    .webedit ("name:=passwd").setsecure "52ea325bd89a05e9260dad8411922dfe344ae65a"
    .webbutton("name:=Sign In").click
          End with
End with
For i = 2 to nor step 1
             T = wso.cells (i, 1)
             C = wso.cells (i, 2)
             S = wso.cells (i, 3)
             B = pro (i-1).range.text 'i=2 in this loop for excel cells, i-1 loop is for word of first paragraph
'go to mail compose page using QTPScript in 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 T
    .webedit("name:=cc").set C
    .webedit("name:=Subj").set S
 '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 (B)
           Set wsho = nothing 'Keyboard automation completed and destroyed
.webbutton("name:=Send", "index:=0").click
Wait (5)
         End with
End with
With browser ("title:=.*")
          With.page ("title:=.*")
.link("name:=Back to Inbox").click
end with
end with
Next
'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 VBScript
ieo.quit
'Close excel software using VBScript
Exo.quit
'close msword software using VBScript
Doco=close (False) 'False is for closing the document without saving
Mswo.quit
Set pro=nothing
Set doco=nothing
Set mswo=nothing
Set wbo=nothing
Set exo=nothing
Set ieo=nothing

QTP Charts


QTP CHARTS


Option explicit
Dim exo, wbo, wso, rngo, cho
'open new excel file sheet using VBScript
Set exo=createobject("excel.application")
Set wbo=exo.workbooks.open ("C:\Documents and Settings\qa\Desktop\QTP Practice\PATH FILES\Excel Charts Comparison1.xls")
Set wso=wbo.worksheets("sheet1")
Exo.visible=true
Set rngo= wso.range("B2", "C21")
'Create a new chart for selected data (“B2”, “C21”) using VBScript
Set cho= wbo.charts.add
Cho.name= "Run Rate"
Cho.charttype=65 'any number between 61-70
Cho.SetSourceData rngo, 2 '2 is the second component in sheet1, the 1st component is scores table
Cho.location 2, "sheet1"
'save excel file and close application
Wbo.save
Exo.quit
Set wso=nothing
Set wbo=nothing
Set exo=nothing
Set rngo=nothing
Set cho=nothing

Color Index in Excel with QTP

COLOR INDEX in Excel



HI Guyz, Hope you enjoy the below simple colourful program to get the COLOR INDEX in Excel

Note:  The default color index numbers are 1-56

Option explicit
Dim exo, wbo, wso, i
'open new excel file sheet using VBScriptSet exo=createobject("excel.application")
Exo.visible=true
Set wbo=exo.workbooks.add
Set wso=wbo.worksheets("sheet1")
 'perform getting color index using VBScript
For i = 1 to 56 step 1
        wso.cells(i,1)= "COLOR"
        wso.cells(i,1).font.colorindex= i
        wso.cells(i,1).font.bold=true   
        wso.cells(i,1).font.name="verdana"
        wso.cells(i,1).font.size=15
        wso.cells(i,2).interior.colorindex=i
        Next
'save excel file and close application
Wso.rows.autofit
Wso.columns.autofit
Wbo.saveas ("C:\Documents and Settings\qa\Desktop\cOLORiNDEX.XLS")
Exo.quit
Set wso=nothing
Set wbo=nothing
Set exo=nothing

Wednesday, 29 January 2014

EVAL Using QTP

EVAL 

The below program is to EVAL values using QTP Tool using VBScript Discriptive Language and Excel File

1.  Create an excel file, in the first column add more than one values in the first column using additions, multiplications, substractions .etc. Example:  6*2
2.  In the second column, input the correct results of the first column Example:  First column 6*2. Second column would be 12. (This is your expected results)

3.  Now compare the actual results in column three with expected results in coloumn two
4. If the results match it must show PASSED else FAILED in fourth column

Option explicit
Dim exo, wbo, wso, nor, i, x, y, z
'open excel file sheet using VBScriptSet exo=createobject("excel.application")
Set wbo=exo.workbooks.open("C:\Documents and Settings\qa\Desktop\QTP Practice\PATH FILES\Excel Evaluations.xls")
Set wso=wbo.worksheets("sheet1")
Nor=wso.usedrange.rows.count
Exo.visible=true
'perform reading and writing from columns using VBScript
For i = 2 to nor step 1
X= wso.cells (i, 1)
Y= wso.cells (i, 2)
Z= eval(x)
Wso.cells (i, 3)=z
    If z=y then
        Wso.cells(i, 4) = "Passed"
   Else
        Wso.cells (i, 4) = "Failed"
   End if
Next
'save excel file and close application

Wbo.save
Exo.quit
Set wso=nothing
Set wbo=nothing
Set exo=nothing

Adding Columns in Excel Using QTP

The below program is used to add coloum values using QTP tool, VBScript Discriptive Language and Excel

1. Create an excel file with first four columns and six rows, give some values
2. Add the four column values and show the results in fifth column
3. Save and Close the excel file

Option explicit
Dim exo, wbo, wso, nor, i, a, b, c, d,T
'open excel file sheet using VBScriptSet exo=createobject("excel.application")
Set wbo=exo.workbooks.open("C:\Documents and Settings\qa\Desktop\QTP Practice\PATH FILES\Addition.xls")
Set wso=wbo.worksheets("sheet1")
Nor= wso.usedrange.rows.count
Exo.visible=true
'perform reading and writing from the excel file using VBScript
For i = 2 to nor step 1
a=wso.cells (i,1)  '(Reading)
b=wso.cells (i,2)
c=wso.cells (i,3)
d=wso.cells (i,4)  '(Reading)
T=cint(a)+cint(b)+cint(c)+cint(d)
Wso.cells(i,5)=T  '(Writing)
Next
'Save excel file and close application
Wbo.save
Exo.quit
Set wso=nothing
Set wbo=nothing
Set exo=nothing

Sending Multiple Emails At One Click Using QTP

Multiple Emails At One Click

Please find the below progam for sending number of mails at one go using QTP Tool, VBscript Discriptive Language, and Excel Document....Hope you will enjoy this :-)

NOTE:  Object Properties may change based on browser versions and OS

Option explicit
Dim bro, url, wsho, exo, wbo, wso, nor, i, T, C, B, F
 'open excel file sheet using VBScript
'Bro for browser
'url for website
'wsho for keyboard object
'exo for excel application
'wbo for excel work book
'wso for excel work sheet
'nor for number of rows count
'i for looping
'T for to addresses from excel sheet
'C for CC addresses from excel sheet
'B for mail body from excel sheet
'F for file path from excel sheet

Set exo=createobject ("Excel.application")
exo.visible=true
set wbo=exo.workbooks.open ("C:\Documents and Settings\qa\Desktop\QTP Practice\PATH FILES\email list.xls")
set wso=wbo.worksheets("sheet1")
nor=wso.usedrange.rows.count
for i = 2 to nor step 1 '(2 is used because first row is given for headings)
T=wso.cells (i, 1)
C=wso.cells (i, 2)
B=wso.cells (i, 3)
F=wso.cells (i, 4)
'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 DPWith browser ("title:=.*")
          With.page ("title:=.*")
    .webedit ("name:=login").set "prasadxxxxx"
    .webedit ("name:=passwd").setsecure "52e8ddowlf543cb5ec81f6e705d2ec5edc6f617883501c0445045f623"
    .webbutton("name:=Sign In").click
          End with
End with
With browser ("title:=.*")
          With.page ("title:=.*")
'Using analog i have avoided a dailogboxWindow("Microsoft Internet Explorer").RunAnalog "Track1"
end with
end with
'Go to compose a 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 T
    .webedit("name:=cc").set C
    .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 F
        .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 (B)
'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
next
'Close excel application
exo.Quit

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