开发者

Issue related to Exist method

I am facing issues while using Exist method in QTP..As if i use Exist with If else then it is working fine...but if used directly then not working...

Ex:

Browser("Home").Page("Home_2").WebEdit("ctl00$uxMNJDefaultContentPlace").Click
Browser("Home").Page("Home_2").WebEdit("ctl00$uxMNJDefaultContentPlace").Set DataTable("mfgpartnumber", dtGlobalSheet)  ''#Read mfg# from datasheet

Browser("Home").Page("Home_2").Image("ctl00$uxMNJDefaultContentPlace").FireEvent "onmouseover"

Browser("Home").Page("Home_2").Image("ctl00$uxMNJDefaultContentPlace").Click 31,11
wait(15)

Browser("Home").Page("Shopping Cart").WebElement("$3.99").Output CheckPoint("Shop开发者_运维知识库pingcart_subtotal")

Browser("Home").Page("Shopping Cart").Check CheckPoint("Shopping Cart_price_2")

''#Browser("Home").Page("Shopping Cart").WebElement("$3.99").Output CheckPoint("$3.99")

Browser("Home").Page("Shopping Cart").Image("ctl00$uxMNJDefaultContentPlace").FireEvent "onmouseover"

Browser("Home").Page("Shopping Cart").Image("ctl00$uxMNJDefaultContentPlace").Click 66,10
wait(5)

Browser("Home").Page("Edit Shipping Address").Link("Continue").Click
wait(5)

Browser("Home").Page("Order Shipping Method").Link("Continue").Click
wait(5)

Here i want to replace wait(_ to some another method like Exist to improve performance...

Can anybody help me to sort it out..,.

Thanks, Guddu G


@guddu

Since you wait for the browser to load another page, use Browser.Sync where applicable.
If an object does not appear right after a page is reloaded, use .Exist method with a parameter.
Example:

boolRC = Browser("Home").Page("Shopping Cart").WebElement("$3.99").Exist(15)  

This way, you give up to 15 seconds for an object to appear. If the object appears earlier, your script moves on faster.
If the object becomes available for operating with a delay after it's appeared, use WaitProperty method, as @katmoon pointed out.

Finally, you can implement your own synchronization function with customizable parameters like event (appear/disappear, etc.), time-out, property to check...

Example: http://automation-beyond.com/2009/08/20/gui-object-synchronization-custom-function/

Thank you,
Albert Gareev
http://automation-beyond.com/


Wait – method is used to instruct the QTP to wait the execution process based on the specified time only but not on any condition E.g. Wait 5 (or) Wait(5) ‘5 Seconds

This method is not advisable.Always use dynamic wait to speed up the execution.

WaitProperty – method is used to instruct QTP to wait the execution process until it matches with the object property value based on the specified time.

E.g. Browser("Welcome: Mercury Tours").WaitProperty "name" "Welcome: Mercury Tours" 5000

  1. property name - "name"
  2. property value - "Welcome: Mercury Tours"
  3. 5000 - number of milli seconds to wait

    Dim i=0 do i=i+1

    bstatus = browser().exist(1) ' "1" means it will wait max 1 sec then it will proceed further

    if i>15 then 'here specify the wait time(i mentioned 15 sec)

    exit do
    

    End if

    loop until bstatus=true

By providing synchronization point tester tries to match the execution speed of QTP and Application because it may happen that the next operation that you are performing is depending on previous result and it is not generated yet. Default wait time for any object is 20 second and object is not appearing in 20 second than that may fail script. So to avoid such condition we use Synchronization Points

Always use Waitproperty Don't use hardcoded wait

Exist method will always return boolean value

Object.exist or Browser().page().exist() this will return a boolean value say true or false

blnStatus = Browser().exist()

msgbox blnstatus 'return true or false


Hi This Is a simple function I'm using instead of wait and disabled property i think it may help.. Thank You..

Set NavigationTab = Browser ().Page().WebElement()
PerformWait ( 10 , 10 , NavigationTab )


Function PerformWait ( intDisableTime , intDelay , object )

if CheckExist ( intDelay , object ) Then

if ValidateDisabled ( object , intDisableTime ) Then

    object.Sync
    Reporter.ReportEvent 0 , "Element is ready to use" , "The  specified element is ready to use" & Date & Time


  Else

   Reporter.ReportEvent 3 , "Object Disabled." , "Object remains disabled after specified time : " & refDisableTime & Date & Time   

End If

Else

Reporter.ReportEvent 3 , "Element not present." , "The specified element not present : " & Date & Time

End If

End Function

Function CheckExist ( intDelay , object )

object.RefreshObject

' -- validating the object is exist or not.
If object.Exist ( intDelay ) Then

 CheckExist = True

Else

 CheckExist = False

 End If

End Function


Function ValidateDisabled ( object , intDisableTime )


For Iterator = 1 To intDisableTime Step 1

' -- validating the object is disabled or not.
If object.GetROProperty ( "disabled" ) = 1 Then

    wait 1  
    ValidateDisabled = False

Else

    ValidateDisabled = True
    Exit For    

End If

Iterator = Iterator + 1
Next

End Function
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜