Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to write a genecric function for sync operation
#1
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
Reply
#2
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.
Thanks,
SUpputuri
Reply
#3
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
Reply
#4
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.
Thanks,
SUpputuri
Reply
#5
QTP King,
Yes please... Or gimme some hints if u r too busy... thanks so much
Reply
#6
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.
Thanks,
SUpputuri
Reply
#7
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
Reply
#8
One can also have different wait time defined in the environmental variable file and call it as appropriate.
Reply
#9
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
Reply
#10
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Cross Browser Sync Not Working geodude 0 2,339 04-07-2017, 08:43 AM
Last Post: geodude
  Calling a function in a Test Script from a function library anupam4j 3 6,993 06-26-2015, 12:31 AM
Last Post: babu123
  How to use sync function 22sumit 2 4,081 06-16-2015, 06:27 PM
Last Post: 22sumit
  The DataTable.ExportSheet operation failed. Invalid file. Niraj 2 6,976 05-05-2015, 11:40 PM
Last Post: babu123
  Excel operation - to find usedrange of rows & col pooja 1 10,375 02-19-2015, 04:06 AM
Last Post: supputuri

Forum Jump:


Users browsing this thread: 1 Guest(s)