Thursday 16 May 2013

Differences between Wait, Wait Property and Exist


1. Wait Statement: It will wait for the specified amount of time. We can specify the time in both seconds and milliseconds. But its necessary to define time in the wait statement even it is zero otherwise it will give you an error.

Example: wait, wait () both will give errors
while wait(0), wait 0, wait 0, 10000 are valid statements.

also wait (0, 10000) will give an error and wait 0,10000 is a valid statement.

The disadvantage of wait statements is that it is not applied on a condition. If this statements is encountered by the compiler then it will wait for the specified amount of time.

2. Exist Property: A very useful property when dealing with the dynamic objects which takes time to download on the web pages.As the name suggests this property checks if a objects exist before doing operations on the object. This property can be used almost all the objects. It is used as follows:

A=Browser("").Page("").Frame("").webedit("Login").exist(09)

The above exist statement will check if the "Login" object exists on the WebPage or not. If it exist then it return True to "A: and if not then it will return False to "A". In real time we generally checks if some objects exist or not before doing some operation on it.

Example:

If Browser("JobCenter").Page("JobCenter").WebButton(strKeywordName).Exist(10) then Browser("JobCenter").Page("JobCenter").WebButton(strKeywordName).Click end if

Difference between wait and Exist Statement:

1. Execution will wait specifically for the amount specified in Wait statement. If wait(10) is define then the QTP will wait for 10 seconds. No matter what happens. So if we have a script which run 100 time then naturally it is going to increase the run time significantly.
Exist: Execution will move to next statement as soon as Exist return a True. So if Exist(10) is specified and the condition become true on the very first second then QTP will move to next statement. Thus we have directly saved the 9 second.

2. Wait is a statement while Exist is a property. By then help of wait we pause the execution for certain amount of time while Exist checks if a specified objects exists or not for the specified time.

3. 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
Here name is - property name , Welcome: Mercury Tours is - property value, 5000 - number of milli seconds to wait

No comments:

Post a Comment