Web Scripts-II

Web Scripts-II
Web Application Testing using QTP.
Web forms verification, Object state verification, Database Testing and Links verification.
1) 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
2) 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

3) 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
4) 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(“[email protected]”,”hi”,”This is test mail for tsting”,””)
Adv VBScripts

5) Open Internet Explorer and navigate to yahoo mail
===================================

Dim ie
Set ie=CreateObject(“InternetExplorer.Application”)
ie.Visible=True
ie.Navigate “www.yahoomail.com”
x=Browser(“CreationTime:=0″).GetROProperty(“title”)
msgbox x
6) Function for Counting Objects from any opened web page
Function Objects_Count(myObject)
   Dim Objects
   Set Objects=Description.Create
 Objects(“micclass”).value=myObject
 Set Object=Browser(“title:=.*”).Page(“title:=.*”).ChildObjects(Objects)
 TotObjects=Object.Count
 Msgbox TotObjects
End Function
Call Objects_Count(“WebButton”)
7) Create script for links validation and set results into an excel file


Set objDesc=Description.Create

objDesc(“micclass”).value=”Link”

Set objColl=Browser(“title:=.*”).page(“title:=.*”).ChildObjects(objDesc)

msgbox objColl.count

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)=”TargetUrl”

Set c2=objSheet.cells(1,2)

c2.font.color=vbBlue

objSheet.cells(1,3)=”ActualUrl”

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

For i=0 to objColl.count-37 step 1

strName=Browser(“title:=.*”).page(“title:=.*”).Link(“index:=”&i).GetRoProperty(“name”)

TargetUrl=Browser(“title:=.*”).page(“title:=.*”).Link(“index:=”&i).GetRoProperty(“url”)

msgbox TargetUrl

Browser(“title:=.*”).page(“title:=.*”).Link(“index:=”&i).click

wait(4)

ActualUrl=Browser(“title:=.*”).GetRoProperty(“url”)

msgbox  ActualUrl

If instr (1,TargetUrl,ActualUrl,1) > 0 Then

Reporter.ReportEvent micPass,”Link Name  “&strName,”Link Validation done”

objSheet.cells(i+2,1)=strName

objsheet.cells(i+2,2)=TargetUrl

objsheet.cells(i+2,3)=ActualUrl

objsheet.cells(i+2,4)=”Link Validation done”

Set c5= objsheet.cells(i+2,4)

c5.font.color=vbGreen

Else

Reporter.ReportEvent micFail,”Link Name   “&strName,”Link validation fail”

objSheet.cells(i+2,1)=strName

objsheet.cells(i+2,2)=TargetUrl

objsheet.cells(i+2,3)=ActualUrl

objsheet.cells(i+2,4)=”Link Validation fail”

Set c5= objsheet.cells(i+2,4)

c5.font.color=vbRed

End If

Browser(“title:=.*”).Back

Next

Set objWbook=objExcel.ActiveWorkbook

objWbook.SaveAs “E:gcreddy.xls”

objExcel.Quit

Set objExcel=nothing

 

 

Comments