Hi, Is there a way we can write a common function for a sync operation... say we have Browser(x).Page(x).Obj1(x).sync and Browser(x).Page(x).Obj2(x).sync and so on.... Can we write one common statement and call the sync function by passing the object type. Appreciate all your help.. Thanks
Hi Martinangello,
Please find the below function which will work well only by passing the browser and page names.
Eg: f_waitForPage "x","x"
Code:
Public Function f_waitForPage(ByVal BrowserName, ByVal PageName)
Dim strSyncObject 'to hold page object description
Dim intCounter 'to store loop counter value
Dim strSyncDone 'to store page existence value
Dim strSyncObjectDesc 'to store object description
'Any error is handled by the calling function
On Error Resume Next
'verify whether the page name is specified or not.
If PageName <> vbNullString Then
Set strSyncObject=Browser(BrowserName).Page(PageName)
strSyncObjectDesc = "Browser " & BrowserName & ", Page " & PageName
Else
f_ReportFailure "Verify that the page", PageName& "Page is not displayed."
End If
'wait for the object in a loop, until the counter reaches the max
intCounter = 1
strSyncDone = strSyncObject.Exist
Do While Not strSyncDone
Wait gWebPageSyncTime
strSyncDone = strSyncObject.Exist
If intCounter = 10 Then Exit Do End If
intCounter = intCounter+1
Loop
'Error handling
If strSyncDone Then
Browser(BrowserName).Sync
f_waitForPage = micPass
Else
f_waitForPage = micFail
End If
End Function 'End of 'waitForPage' function.
Let me know if you need any more information.
QTP King,
Thanks for such a quick response... But sync is not my main objective... to write a generic function is what i'm breakin my head on.. well, lemme rephrase... say we have an imagebutton,link, webbutton... If i need to click on these, can i write a single click function which would work for all three( when i pass these values via a variable)... Aprreciate your help... thanks
Hi Martinangello,
yes we can write only one function which can work on different objects(Imagebuttons,webbuttons,links) based on the variables.
you can use "case" to handle this situation in while developing function.
Let me know if you wan me to devlop the function.
QTP King,
Yes please... Or gimme some hints if u r too busy... thanks so much
Hi Martin,
Pleae find the below LOC and let me know it's OK with you.
Code:
'LOC to click on the button
msgbox Click (Browser("Google").Page("Google"),"WebButton","Google Search")
'LOC to click on the Link
msgbox Click (Browser("Google").Page("Google"),"Link","Preferences")
'LOC to click on the Image
msgbox Click (Browser("Google").Page("Google"),"WebButton","ImageName")
Function Click (objPath,strObjType,strobj)
Click =True
Select Case strObjType
Case "WebButton"
objPath.WebButton(strobj).click
Case "Link"
objPath.Link(strobj).click
Case "ImageButton"
objPath.Image(strobj).click
Case Else
Click = False
End Select
End Function
Let me know if you need any more info.
What I have right now is a bit similar to this... but i'm tryin to write somethin more simpler/compact... well , lemme add more details... Browser(x).Page(y).Link(z).click... x,y,z are global variables and are read from an excel... every row in the excel has diff values for x,y,z... I use 'Execute' statement instead of the Call Function as the no of parameters to be passed varies from function to function... In the same way if i wanna hv a sync function (page sync alone wont work, as some objects load wel after the page has loaded) i'l hv several lines like
Browser(x).Page(y).Link(z).sync.......Browser(x).Page(y).Image(z).sync.....Browser(x).Page(y).weblist(z).click.... etc... Now can i handle these dynamically? like creating an object or something and just use obj.sync? Please advice... and sorry for dragging this thing....THANKS
One can also have different wait time defined in the environmental variable file and call it as appropriate.
Tarik,
Thanks... but instead of a wait function if i learn how to write a generic function, i'll be able to club so many things... like, i can use one click statement for link, button, image etc... one set statement for text and checkbox.. and so on... please help if u can... Thanks
Hi Martina,
try this script for click button
Eg:-
using the descriptive programming
Code:
Sub click_button()
Dim browser_session
If Browser("name:=google).page("index:=0" ,"name:=inbox").Exist Then
Set browser_session = Browser("name:=google).page("index:=0" ,"name:=inbox")
Else
Set browser_session = Browser("name:=google).page("index:=0" ,"name:=outbox")
End If
browser_session.SendKey ENTER
end sub
store it in function library
call the sub procedure in your test
click_button()
i am using some browser script for the example only , implement ur script like this
kindly let me know if u have any query
Regards
Bala