Topic
  • 10 replies
  • Latest Post - ‏2013-09-09T08:26:42Z by Y5QY_gerben_delange
5KUK_Mike_Ramsey
5KUK_Mike_Ramsey
12 Posts

Pinned topic Wait for one or the other browser

‏2013-08-30T16:54:11Z |

I have a situation where a script presses a button and either a window of the same title is displayed or a different Html.HtmlDocument instance is displayed.  I manage the differences by "living outside of the object map".  When I know which instance is supposed to appear my solution works fine. However, when the choice can be one of two, I get null object exceptions when I test for existence.

Is there a standard pattern to wait for one or the other Html.HtmlDocument instances to be ready? 

This has all been complicated by a recent change in the application under test.  With the last build, two browser windows are created and both have the same process id.  I am fighting ambiguous recognition errors as I try various options.  It has been frustrating.

Thank you.

"Topic Tag" section finally came up.  I added  tag rft.

Added: I am using RFT 8.1.1.3

Updated on 2013-08-30T17:34:24Z at 2013-08-30T17:34:24Z by 5KUK_Mike_Ramsey
  • Y5QY_gerben_delange
    Y5QY_gerben_delange
    34 Posts
    ACCEPTED ANSWER

    Re: Wait for one or the other browser

    ‏2013-09-05T00:26:37Z  

    I though along similar lines (i.e. bad object map).  I went through an exercise where I:

    1)  Renamed existing scripts to ....Old

    2) Created a new empty script with the same name (sans Old)

    3) Recorded to create a minimal Object map (browser objects and high level html objects)

    4) Copied code from ...Old to new

    The code dynamically searches the DOM from fairly high level html div objects from the map to find elements.  That is, I treat the Html as dynamic which it mostly is.

    There are two scripts out of 40 or so in the run that recently started giving me problems.  I don't know why exists() should raise an exception.

    To answer your other question, the two scripts are doing rather complex things and it wouldn't make a lot of sense to isolate out just this part.  But I will think about it.  It is always a good idea to get the smallest code that replicates the problem.

    I hope the attached script will help.

    .exsists method is flawed like you experienced, so best not to use it. It's not necessary to use the IWindow interface to determine browser title, you can do it using the TestObject interface.

    Im not a big fan of static testobjects, i never use them anymore..

     

    good luck

    ps script hasn't been tested ;)

    Attachments

  • 5KUK_Mike_Ramsey
    5KUK_Mike_Ramsey
    12 Posts

    Re: Wait for one or the other browser

    ‏2013-08-30T20:39:15Z  

    I came up with the attached which at least has the virtue of working.  There has got to be a simpler way.

     

    Attachments

  • cagin.uludamar
    cagin.uludamar
    66 Posts

    Re: Wait for one or the other browser

    ‏2013-09-02T12:40:39Z  

    I came up with the attached which at least has the virtue of working.  There has got to be a simpler way.

     

    Hi,

    I didn't understand your algorithm, code is too long for me to inspect.

    Did you try to define 2 test objects from these different HTML documents? Then you can test their existence such as:

    if (testObj1().exists())
      doc1IsOpen();

    if (testObj2().exists())
      doc2IsOpen();

    This should work if you play a bit with recognition weights of different properties of the objects.

  • 5KUK_Mike_Ramsey
    5KUK_Mike_Ramsey
    12 Posts

    Re: Wait for one or the other browser

    ‏2013-09-03T15:28:57Z  

    Hi,

    I didn't understand your algorithm, code is too long for me to inspect.

    Did you try to define 2 test objects from these different HTML documents? Then you can test their existence such as:

    if (testObj1().exists())
      doc1IsOpen();

    if (testObj2().exists())
      doc2IsOpen();

    This should work if you play a bit with recognition weights of different properties of the objects.

    I played extensively with the object recognition properties.  No matter what I tried, an object recognition exception is always raised on the first pass through the loop.  If I catch that exception, it eventually works.

    I did define the two objects as you suggest.  The test for existence always triggers an exception.  That is why I switched to using IWindow to test for the existence of the browser.

    Sorry that my code was hard to follow. That code was arrived at by a process of elimination.

     

  • cagin.uludamar
    cagin.uludamar
    66 Posts

    Re: Wait for one or the other browser

    ‏2013-09-04T06:01:34Z  

    I played extensively with the object recognition properties.  No matter what I tried, an object recognition exception is always raised on the first pass through the loop.  If I catch that exception, it eventually works.

    I did define the two objects as you suggest.  The test for existence always triggers an exception.  That is why I switched to using IWindow to test for the existence of the browser.

    Sorry that my code was hard to follow. That code was arrived at by a process of elimination.

     

    Hi Mike,

    exists() method should not throw any exception, even if the test object does not exist. Could there be a problem with your object map? Did you try to write a separate simple script (with a separate obj map) which has only these 2 test objects and checks their existance?

  • Y5QY_gerben_delange
    Y5QY_gerben_delange
    34 Posts

    Re: Wait for one or the other browser

    ‏2013-09-04T21:28:35Z  

    you could try something like this as a work-around:

     

    public static boolean ex(TestObject x) {
    try {
    if(x.exists()){
    return true;
    }
    return false;
    } catch (Exception e) {
    return false;
    }
    }
  • 5KUK_Mike_Ramsey
    5KUK_Mike_Ramsey
    12 Posts

    Re: Wait for one or the other browser

    ‏2013-09-04T22:53:12Z  

    Hi Mike,

    exists() method should not throw any exception, even if the test object does not exist. Could there be a problem with your object map? Did you try to write a separate simple script (with a separate obj map) which has only these 2 test objects and checks their existance?

    I though along similar lines (i.e. bad object map).  I went through an exercise where I:

    1)  Renamed existing scripts to ....Old

    2) Created a new empty script with the same name (sans Old)

    3) Recorded to create a minimal Object map (browser objects and high level html objects)

    4) Copied code from ...Old to new

    The code dynamically searches the DOM from fairly high level html div objects from the map to find elements.  That is, I treat the Html as dynamic which it mostly is.

    There are two scripts out of 40 or so in the run that recently started giving me problems.  I don't know why exists() should raise an exception.

    To answer your other question, the two scripts are doing rather complex things and it wouldn't make a lot of sense to isolate out just this part.  But I will think about it.  It is always a good idea to get the smallest code that replicates the problem.

  • Y5QY_gerben_delange
    Y5QY_gerben_delange
    34 Posts

    Re: Wait for one or the other browser

    ‏2013-09-05T00:26:37Z  

    I though along similar lines (i.e. bad object map).  I went through an exercise where I:

    1)  Renamed existing scripts to ....Old

    2) Created a new empty script with the same name (sans Old)

    3) Recorded to create a minimal Object map (browser objects and high level html objects)

    4) Copied code from ...Old to new

    The code dynamically searches the DOM from fairly high level html div objects from the map to find elements.  That is, I treat the Html as dynamic which it mostly is.

    There are two scripts out of 40 or so in the run that recently started giving me problems.  I don't know why exists() should raise an exception.

    To answer your other question, the two scripts are doing rather complex things and it wouldn't make a lot of sense to isolate out just this part.  But I will think about it.  It is always a good idea to get the smallest code that replicates the problem.

    I hope the attached script will help.

    .exsists method is flawed like you experienced, so best not to use it. It's not necessary to use the IWindow interface to determine browser title, you can do it using the TestObject interface.

    Im not a big fan of static testobjects, i never use them anymore..

     

    good luck

    ps script hasn't been tested ;)

    Attachments

  • cagin.uludamar
    cagin.uludamar
    66 Posts

    Re: Wait for one or the other browser

    ‏2013-09-05T05:24:21Z  

    I though along similar lines (i.e. bad object map).  I went through an exercise where I:

    1)  Renamed existing scripts to ....Old

    2) Created a new empty script with the same name (sans Old)

    3) Recorded to create a minimal Object map (browser objects and high level html objects)

    4) Copied code from ...Old to new

    The code dynamically searches the DOM from fairly high level html div objects from the map to find elements.  That is, I treat the Html as dynamic which it mostly is.

    There are two scripts out of 40 or so in the run that recently started giving me problems.  I don't know why exists() should raise an exception.

    To answer your other question, the two scripts are doing rather complex things and it wouldn't make a lot of sense to isolate out just this part.  But I will think about it.  It is always a good idea to get the smallest code that replicates the problem.

    I'd recommend to discard the old code for a moment and write a simple script which only tests objects for existance. Test objects can be defined as static test objects.

    I re-read your first post and recognized that you get null pointer exceptions when calling exists(). This means the dynamic object which is calling exists() is actually null. If you send stack trace, I can make a better guess I hope.

    @Y5QY_gerben_delange: We mostly use static test objects in our scripts since the old versions of RFT (v6.1 as far as I remember); and never encountered any problem with exists() method. Sometimes it returns true although the object doesn't appear in the page, but I guess it is because it is only hidden dynamically.

  • 5KUK_Mike_Ramsey
    5KUK_Mike_Ramsey
    12 Posts

    Re: Wait for one or the other browser

    ‏2013-09-06T14:11:50Z  

    I hope the attached script will help.

    .exsists method is flawed like you experienced, so best not to use it. It's not necessary to use the IWindow interface to determine browser title, you can do it using the TestObject interface.

    Im not a big fan of static testobjects, i never use them anymore..

     

    good luck

    ps script hasn't been tested ;)

    Gerben,
    I took Cagin's advice and created a small test script to capture the problem.  I had come up with an approach late Wednesday and it tracks pretty close to what your code fragment suggested (see attached).  When I restructure the solution for actual use in my other scripts I will follow your packaging approach.  I am in the middle of leading a system test so I apologize for the time lag in my responses.

    Attachments

  • Y5QY_gerben_delange
    Y5QY_gerben_delange
    34 Posts

    Re: Wait for one or the other browser

    ‏2013-09-09T08:26:42Z  
    Gerben,
    I took Cagin's advice and created a small test script to capture the problem.  I had come up with an approach late Wednesday and it tracks pretty close to what your code fragment suggested (see attached).  When I restructure the solution for actual use in my other scripts I will follow your packaging approach.  I am in the middle of leading a system test so I apologize for the time lag in my responses.

    Hi Mike,

    Glad I could help. Be carefull with the following lines, this is a potentially infinite loop:

     

     while (Integer.parseInt(browsers[k].getProperty(".readyState").toString()) < 4)  {
        sleep(2.0);
       }

     

    good luck