Results 1 to 3 of 3
  1. #1

    Wait command vs. Custom sync Function

    To speed up the WR script
    6) Avoid the wait command for synchorization. Write custom sync functions when necessary. I can't tell you how many scripts I have reviewed that are just littered with wait commands because the user struggled with synchronization.
    I picked up this from Speed .... discussion topic in Mercury Support, written by Rich.

    I am wondering what would be the custom sync functions. What exactly goes in this function. I have wasted time by using wait command. Most of the time, I don't need to use but always put to be on safer side.

    If anyone could tell me or give the script of a custom sync function, it would be highly appreciated.


  2. #2
    SQA Knight
    Join Date
    Jun 2002
    Cupertino, CA, USA

    Re: Wait command vs. Custom sync Function

    The most important thing to learn is when a custom sync function is necessary. WinRunner comes equipt with built in synchronization, which many new users are not aware of. I often see novice scripters using wait statements, or writing custom sync functions when waiting for windows / objects to appear - totally unecessary.

    set_window -

    will wait for a window to appear.
    The second parameter, when added to the global timeout, specifies the maximum amount of time to wait.
    If the Window is found before the maximum time is reached, the test continues to run.
    If second parameter is not specified,, WinRunner will still wait for the global timeout to elapse before flagging an error.


    will wait for an object to appear.
    The second parameter, when added to the global timeout, specifies the maximum amount of time to wait.
    If second parameter is not specified, WinRunner will not wait for the global timeout to elapse before returning E_NOT_FOUND.

    Then, of course, there are the functions catagorized as synchronization. These involve waiting for a window or object to reach a specified state. These are the _wait_info functions:


    The time specified in these functions is not added to the global timeout.

    So with all this built in synchronization, when do you need a custom function? One common scenario is waiting for an object or window to disappear. Here is an example of such a function:

    </font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">function obj_wait_dissapear(in object, in MaxWaitTime)
    auto InitialTime = get_time();
    if(obj_exists(object) != E_OK)
    return E_OK;
    wait (1);
    if ( (get_time() - InitialTime) &gt; MaxWaitTime)
    tl_step(&quot;obj_wait_dissapear&quot;,FAIL,&quot; Object: \&quot;&quot; &amp; object &amp; &quot;\&quot; was still present after &quot; &amp; MaxWaitTime &amp; &quot; seconds.&quot;
    return -1;

    if(obj_wait_dissapear(&quot;YourObject&quot;,5) != E_OK)
    #Continue with script</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">

  3. #3

    Re: Wait command vs. Custom sync Function

    Mr P, this is good stuff... but what about synch for menu_ - see my post asking how to wait for a menu item to be enabled. Because


    gives an error unless the menu item referred to is enabled.

    Having read your post I hopefully tried "obj_exists" on the menu item, with a timeout parameter, but that just passed immediately and moved straight on to the menu_select_item statement which then failed because it wasn't enabled.

    So I am still looking to work out how to do the "custom synch function" to replace the misbehaving(?) menu_wait_info...




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
BetaSoft Inc.
All times are GMT -8. The time now is 04:07 PM.

Copyright BetaSoft Inc.