Web Scripts
1) Count all opened Browsers on desktop and close them all?
Set oDesc = Description.Create()
oDesc("micclass").Value = "Browser"
Set Browsers =Desktop.ChildObjects (oDesc)
NumberofBrowsers = Browsers.Count()
Reporter.ReportEvent 2,"Res","Number of Browsers are: "&NumberOfBrowsers
For Counter=0 to NumberofBrowsers-1
Browsers(Counter).Close
Next
2) Count, how many links available in Mercury Tours Home Page.
Set oDesc = Description.Create()
oDesc("micclass").Value = "Link"
Set Lists = Browser("Welcome: Mercury").Page("Welcome: Mercury").ChildObjects (oDesc)
NumberOfLinks = Lists.Count()
Reporter.ReportEvent 2,"Res","Number of Links are: "&NumberOfLinks
3) Verify whether the 'Gmail' link available or not on Google Homepage
Option explicit
Dim oLink, Links, TotLinks, i, myLink
Set oLink = description.Create
oLink("micclass").value = "Link"
SystemUtil.Run "D:\Program Files\Internet Explorer\IEXPLORE.EXE"
set Links = Browser("name:=Google").page("title:=Google").ChildObjects(oLink)
TotLinks = Links.count
For i =0 to TotLinks-1
myLink = Links(i).getroproperty("innertext")
If mylink = "Gmail" Then
reporter.ReportEvent 0,"res","Link Gmail available"
End If
Next
4) Count number of Links, Edit Boxes available on Google Homepage?
Dim oLink
Set oLink=description.Create
Set oEdit=description.Create
oLink("micclass").value="Link"
oEdit("micclass").value="WebEdit"
Set Links=browser("name:=Google").page("title:=Google").ChildObjects(oLink)
Set EditBoxes=browser("name:=Google").page("title:=Google").ChildObjects(oEdit)
TotLinks= Links.count
TotEditBoxes=EditBoxes.count
msgbox TotLinks
msgbox TotEditBoxes
Reporter.ReportEvent 0,"Result","Total Links are: "&TotLinks&"Total edit Boxes are: "&TotEditBoxes
5) Count how many links available in a Web Page(any web page, using Regular Expressions)
Dim oLink,Links, TotLinks
Set oLink=Description.Create
oLink("micclass").value="Link"
Set Links=Browser("title:=.*").page("title:=.*").ChildObjects(oLink)
TotLinks=Links.count
msgbox TotLinks
Reporter.ReportEvent 2,"Res","Total Links are: "&TotLinks
6) Verify Cost in jjperfumes.com
'Test Flow
'i) Launch jjperfumes.com
'ii) Select a product and enter some quantity
'iii) select Add to Cart, capture Unit price, Quantity and Cost
'iV) Remove $ symbols and compare
'---------------------------------- -----
SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe","","C:\Documents and Settings\gcr.GCRC-9A12FBD3D9","open"
Browser("Google").Page("Google").Sync
Browser("Google").Navigate "http://www.jjperfumes.com/"
Browser("Google").Page("JJ Perfumes-Discount perfume").Image("thumb_1845_WLINP50PSW").Click
Browser("Google").Page("JJ Perfumes-Discount perfume_2").WebEdit("quantity").Set "4"
Browser("Google").Page("JJ Perfumes-Discount perfume_2").WebButton("Add To Cart").Click
Unit_Price = Browser("Google").Page("JJ Perfumes-Discount perfume_3").WebElement("[Remove]").GetROProperty("innertext")
Qty = Browser("Google").Page("JJ Perfumes-Discount perfume_3").WebEdit("quantity[]").GetROProperty("value")
Cost = Browser("Google").Page("JJ Perfumes-Discount perfume_3").WebElement("[Remove]_2").GetROProperty("innertext")
Qty=Cint(Qty)
Unit_Price=Cdbl (Mid (Unit_Price,3))
Cost=Cdbl (Mid (Cost, 3))
'Msgbox Unit_Price: Msgbox Qty: Msgbox Cost
If Cost=Qty * Unit_Price Then
Reporter.ReportEvent micPass,"Res","Cost is Correct"
Else
Reporter.ReportEvent micFail,"Res","Cost is InCorrect"
End If
Function To Create HTML Report
Option explicit
Dim oLink, Links, TotLinks, i, myLink
Set oLink = description.Create
oLink("micclass").value = "Link"
SystemUtil.Run "D:\Program Files\Internet Explorer\IEXPLORE.EXE"
set Links = Browser("name:=Google").page("title:=Google").ChildObjects(oLink)
TotLinks = Links.count
For i =0 to TotLinks-1
myLink = Links(i).getroproperty("innertext")
If mylink = "Gmail" Then
reporter.ReportEvent 0,"res","Link Gmail available"
End If
Next
4) Count number of Links, Edit Boxes available on Google Homepage?
Dim oLink
Set oLink=description.Create
Set oEdit=description.Create
oLink("micclass").value="Link"
oEdit("micclass").value="WebEdit"
Set Links=browser("name:=Google").page("title:=Google").ChildObjects(oLink)
Set EditBoxes=browser("name:=Google").page("title:=Google").ChildObjects(oEdit)
TotLinks= Links.count
TotEditBoxes=EditBoxes.count
msgbox TotLinks
msgbox TotEditBoxes
Reporter.ReportEvent 0,"Result","Total Links are: "&TotLinks&"Total edit Boxes are: "&TotEditBoxes
5) Count how many links available in a Web Page(any web page, using Regular Expressions)
Dim oLink,Links, TotLinks
Set oLink=Description.Create
oLink("micclass").value="Link"
Set Links=Browser("title:=.*").page("title:=.*").ChildObjects(oLink)
TotLinks=Links.count
msgbox TotLinks
Reporter.ReportEvent 2,"Res","Total Links are: "&TotLinks
6) Verify Cost in jjperfumes.com
'Test Flow
'i) Launch jjperfumes.com
'ii) Select a product and enter some quantity
'iii) select Add to Cart, capture Unit price, Quantity and Cost
'iV) Remove $ symbols and compare
'---------------------------------- -----
SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe","","C:\Documents and Settings\gcr.GCRC-9A12FBD3D9","open"
Browser("Google").Page("Google").Sync
Browser("Google").Navigate "http://www.jjperfumes.com/"
Browser("Google").Page("JJ Perfumes-Discount perfume").Image("thumb_1845_WLINP50PSW").Click
Browser("Google").Page("JJ Perfumes-Discount perfume_2").WebEdit("quantity").Set "4"
Browser("Google").Page("JJ Perfumes-Discount perfume_2").WebButton("Add To Cart").Click
Unit_Price = Browser("Google").Page("JJ Perfumes-Discount perfume_3").WebElement("[Remove]").GetROProperty("innertext")
Qty = Browser("Google").Page("JJ Perfumes-Discount perfume_3").WebEdit("quantity[]").GetROProperty("value")
Cost = Browser("Google").Page("JJ Perfumes-Discount perfume_3").WebElement("[Remove]_2").GetROProperty("innertext")
Qty=Cint(Qty)
Unit_Price=Cdbl (Mid (Unit_Price,3))
Cost=Cdbl (Mid (Cost, 3))
'Msgbox Unit_Price: Msgbox Qty: Msgbox Cost
If Cost=Qty * Unit_Price Then
Reporter.ReportEvent micPass,"Res","Cost is Correct"
Else
Reporter.ReportEvent micFail,"Res","Cost is InCorrect"
End If
Function To Create HTML Report
Dim StartTime,stTime, enTime
Dim fso, ts,intCnt, intPass,intFail
intPass=0
intFail=0
Const ForWriting = 2
Function OpenFile (strFileName)
StartTime = Timer
stTime = Time
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(strFileName,2)
'OpenFile = strFileURL
CreateHeader
End Function
*****************************
Function To Close File
Dim objIE,strFileURL
Function CloseFile ( strFileURL,strEnv )
Footer(strEnv)
ts.close()
Set objIE = CreateObject("InternetExplorer.Application")
objIE.visible = True
objIE.Navigate strFileURL
wait(5)
Set objIE=nothing
End Function
***********************
Function to Clear Cookies()
Function ClearCookies()
SystemUtil.Run "iexplore.exe"
WebUtil.DeleteCookies
Set objBrowser=Description.Create
objBrowser("micclass").value="Browser"
Set objBCount = Desktop.ChildObjects(objBrowser)
intBrowserCount = objBCount.Count
strHwnd=Browser("creationtime:=" & intBrowserCount).GetROProperty("hwnd")
SystemUtil.CloseProcessByHwnd(strHwnd)
End Function
***********************
Function to send Email
Function SendMail()
If k=0 Then
'Nothing
Else
msgsub = " Geo_PostalCode pattern searchTest Results:" &vbcrLf &"One or more of the Test Cases Failed." &vbcrLf &"See attachment for details."
End If
Set objConf = CreateObject("CDO.Configuration")
cdoSendUsingPort=2
sMailServerName="smtp.phx.move.com"
cdoAnonymous=cdoNONE
objConf.fields.item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
objConf.fields.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sMailServerName
objConf.fields.item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous 'cdoBasic
objConf.fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
objConf.fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'objConf.fields.item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "corp\ NRaoJ "
'objConf.fields.item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "123K!r45"
objConf.fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objConf.fields.Update
Set objMsg = CreateObject("CDO.Message")
objMsg.Configuration = objConf
objMsg.to = "gcreddy@gmail.com"
objMsg.From = "gcreddy@gmail.com"
objMsg.Subject = "~Geo_PostalCode pattern search"
objMsg.TextBody =msgsub
doc=strFilepath
objMsg.AddAttachment(doc)
objMsg.Send
Set objMsg = Nothing
NewMail = True
End Function
***********************
Function to create append excel
Function LogFile
Set objExcel=CreateObject("Excel.Application")
objExcel.visible=False
objExcel.workbooks.open(strFilePath)
r=1
Do Until len(objExcel.cells(r,1))=0
r=r+1
Loop
objExcel.cells(r,1).value="Step Name"
objExcel.cells(r,2).value="Step Description"
objExcel.cells(r,3).value="Test Results"
objExcel.DisplayAlerts = False
objExcel.Save
objExcel.Quit
Set objExcel = Nothing
End Function
***********************
Function to get the Application Environment on which the script is running
Function GetEnv()
Set fso=Createobject("Scripting.FileSystemObject")
sFile="C:\WINDOWS\system32\drivers\etc\hosts"
Set MyFile=fso.OpenTextFile(sFile,1, True)
Do
sEnv=MyFile.ReadLine
If instr(sEnv,"PRODUCTION")>0 Then
GetEnv="Production"
Exit do
Elseif instr(sEnv,"Staging")>0 Then
GetEnv="Staging"
Exit do
Elseif instr(sEnv,"QA MAINTENANCE")>0 Then
GetEnv="QAM"
Exit do
Elseif instr(sEnv,"qap.")>0 Then
GetEnv="qap"
Exit do
End If
Loop While MyFile.AtEndOfStream=False
End Function
***********************
Function To Create HTML Report
Dim StartTime,stTime, enTime
Dim fso, ts,intCnt, intPass,intFail
intPass=0
intFail=0
Const ForWriting = 2
Function OpenFile (strFileName)
StartTime = Timer
stTime = Time
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(strFileName,2)
'OpenFile = strFileURL
CreateHeader
End Function
***********************
No comments:
Post a Comment