Automation Testing, Manual Testing, QTP/UFT 11 , QC/ALM 11 ,SAP TAO, Unix, Selenium, Oracle SQL, Shell Scripting and For Online Trinings to contact me : Cell:+91-8897972059 , Email Id : quicktestprotech@gmail.com

Sunday, November 28, 2010

QTP Scripts

QTP Scripts


1) How to get google search items

Dim x,y,objDev,objShell,objDesc,objColl,i,strName

x=Browser(“Google”).Page(“Google”).WebEdit(“q”).GetROProperty(“abs_x”)
y=Browser(“Google”).Page(“Google”).WebEdit(“q”).GetROProperty(“abs_y”)

Set objDev=Createobject(“mercury.devicereplay”)
objDev.MouseClick x,y,LEFT_MOUSE_BUTTON  ‘To place mouse the cursor in the edit box

Set objShell=Createobject(“wscript.shell”)
objShell.SendKeys “QTP”  ‘To send data from keyboard”
wait(5)

Set objDesc=Description.Create
objDesc(“micclass”).value=”WebElement”
objDesc(“name”).value=”Google Search”

set objColl=Browser(“Google”).Page(“Google”).WebTable(“quotes”).ChildObjects(objDesc) ‘To get webelements in the webtable

msgbox objColl.count

For i=0 to objColl.count-1 step 1
objShell.SendKeys “{DOWN}”
strName=objColl(i).getroproperty(“innertext”)
Reporter.ReportEvent micDone,”Google Search Item “&strName,”Item captured”
Next

Set objDev=Nothing
Set objShell=Nothing

2) How to display dialog box and close it during run-time
x=”sai”

y=”SAI”

Set objShell=Createobject(“Wscript.shell”)

If strcomp(x,y,1)=0 Then

‘ msgbox “Both are equal”

objShell.Popup “Both are equal”,5,”Qtpthirupathi DialogBox”

else

‘ msgbox “Both are not equal”

objShell.Popup “Both are not eual”,5,”Qtpthirupathi DialogBox”

End If

3) 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:Qtpthirupathi.xls”

objExcel.Quit

Set objExcel=nothing

0 comments:

Post a Comment

Loading...