Topic
  • 6 replies
  • Latest Post - ‏2013-09-18T11:08:50Z by cagin.uludamar
TonyNGAN
TonyNGAN
34 Posts

Pinned topic Wait Until Browser Finish Loading

‏2013-09-12T10:03:32Z |

Dear All,

May I know if RFT able to handle "Wait" action?

I want to perform some clicks on a webpage, but since the network is not stable, sometime the webpage needs around 2 minutes to finish the loading.

So, I would like to have a code to wait the "Browser" (E.G: IE8) loading status is done before perform next action.

Would someone can give me some tips :)?

Many Thanks!

Best Regards

Tony

  • Y5QY_gerben_delange
    Y5QY_gerben_delange
    34 Posts
    ACCEPTED ANSWER

    Re: Wait Until Browser Finish Loading

    ‏2013-09-12T10:32:55Z  

    This should get you started. Good luck!

    g

     

    public voidtestMain(Object[] args) {

                waitForAllBrowsers(10);

          }

     

     

          public static booleanwaitForAllBrowsers(inttimeOut) {

                booleanret = false;

                TestObject[] browsers = getRootTestObject().find(

                            atChild(".class", "Html.HtmlBrowser", ".processName",

                                       "iexplore.exe"));

                if((browsers != null) && (browsers.length> 0)) {

                      System.out.println("Number of browsers found: "+ browsers.length);

                     

                      intsecondsPassed = 0;

                      for(inti = 0; i < browsers.length; i++) {

     

                            while((Integer.parseInt(browsers[i].getProperty(".readyState")

                                       .toString()) != 4) && (secondsPassed < timeOut)) {

                                 System.out.println("Browser loading..");

                                 sleep(1);

                                 secondsPassed++;

                            }

     

                      }

                      if(secondsPassed <= timeOut){

                            System.out.println("Al browsers have been loaded within timeout; seconds passed: "+secondsPassed);

                            ret = true;

                                

                      }

                      unregister(browsers);

                } else{

                      System.out.println("no browsers found");

                }

               

     

                returnret;

     

          }

  • MrCoolK
    MrCoolK
    66 Posts
    ACCEPTED ANSWER

    Re: Wait Until Browser Finish Loading

    ‏2013-09-12T12:42:20Z  

    Hi

    Why don't you use wait for existence method.

    For example after the page loads object1 is displayed.

    what you can do is

    screen2.waitForExistence();

    object.waitForExistence();

    what this will do is it will wait until this screen/object exists.

     

     

    Thanks

    Cool K

  • Y5QY_gerben_delange
    Y5QY_gerben_delange
    34 Posts

    Re: Wait Until Browser Finish Loading

    ‏2013-09-12T10:32:55Z  

    This should get you started. Good luck!

    g

     

    public voidtestMain(Object[] args) {

                waitForAllBrowsers(10);

          }

     

     

          public static booleanwaitForAllBrowsers(inttimeOut) {

                booleanret = false;

                TestObject[] browsers = getRootTestObject().find(

                            atChild(".class", "Html.HtmlBrowser", ".processName",

                                       "iexplore.exe"));

                if((browsers != null) && (browsers.length> 0)) {

                      System.out.println("Number of browsers found: "+ browsers.length);

                     

                      intsecondsPassed = 0;

                      for(inti = 0; i < browsers.length; i++) {

     

                            while((Integer.parseInt(browsers[i].getProperty(".readyState")

                                       .toString()) != 4) && (secondsPassed < timeOut)) {

                                 System.out.println("Browser loading..");

                                 sleep(1);

                                 secondsPassed++;

                            }

     

                      }

                      if(secondsPassed <= timeOut){

                            System.out.println("Al browsers have been loaded within timeout; seconds passed: "+secondsPassed);

                            ret = true;

                                

                      }

                      unregister(browsers);

                } else{

                      System.out.println("no browsers found");

                }

               

     

                returnret;

     

          }

  • MrCoolK
    MrCoolK
    66 Posts

    Re: Wait Until Browser Finish Loading

    ‏2013-09-12T12:42:20Z  

    Hi

    Why don't you use wait for existence method.

    For example after the page loads object1 is displayed.

    what you can do is

    screen2.waitForExistence();

    object.waitForExistence();

    what this will do is it will wait until this screen/object exists.

     

     

    Thanks

    Cool K

  • TonyNGAN
    TonyNGAN
    34 Posts

    Re: Wait Until Browser Finish Loading

    ‏2013-09-13T01:02:53Z  
    • MrCoolK
    • ‏2013-09-12T12:42:20Z

    Hi

    Why don't you use wait for existence method.

    For example after the page loads object1 is displayed.

    what you can do is

    screen2.waitForExistence();

    object.waitForExistence();

    what this will do is it will wait until this screen/object exists.

     

     

    Thanks

    Cool K

    Hi MrCoolK,

    Since my testing webpage need to connect to backend.

    In some case, all image of the page will be loaded completely but the webpage status is still waiting for the backend.

    In such case, I don't want my script to run next action, that's why I need the above code to determine the browser status is "Done"

    This is to avoid all image loaded but backend connection is not ready.

    Anyway, many thanks for your kindly suggestion and reply :)

    Regards

    Tony

    Updated on 2013-09-13T03:19:29Z at 2013-09-13T03:19:29Z by TonyNGAN
  • TonyNGAN
    TonyNGAN
    34 Posts

    Re: Wait Until Browser Finish Loading

    ‏2013-09-13T01:57:52Z  

    This should get you started. Good luck!

    g

     

    public voidtestMain(Object[] args) {

                waitForAllBrowsers(10);

          }

     

     

          public static booleanwaitForAllBrowsers(inttimeOut) {

                booleanret = false;

                TestObject[] browsers = getRootTestObject().find(

                            atChild(".class", "Html.HtmlBrowser", ".processName",

                                       "iexplore.exe"));

                if((browsers != null) && (browsers.length> 0)) {

                      System.out.println("Number of browsers found: "+ browsers.length);

                     

                      intsecondsPassed = 0;

                      for(inti = 0; i < browsers.length; i++) {

     

                            while((Integer.parseInt(browsers[i].getProperty(".readyState")

                                       .toString()) != 4) && (secondsPassed < timeOut)) {

                                 System.out.println("Browser loading..");

                                 sleep(1);

                                 secondsPassed++;

                            }

     

                      }

                      if(secondsPassed <= timeOut){

                            System.out.println("Al browsers have been loaded within timeout; seconds passed: "+secondsPassed);

                            ret = true;

                                

                      }

                      unregister(browsers);

                } else{

                      System.out.println("no browsers found");

                }

               

     

                returnret;

     

          }

    Hi G,

    Thanks for your reply!

    I've tested the code and its working great!!!!

    Many Thanks!

    Best Regards!

    Tony

    Updated on 2013-09-13T03:13:54Z at 2013-09-13T03:13:54Z by TonyNGAN
  • Jiri_Mundl
    Jiri_Mundl
    17 Posts

    Re: Wait Until Browser Finish Loading

    ‏2013-09-13T11:50:30Z  

    Hi,

    I think  better is to use variable "readyState". This variable describes process loading web page to the browser.

    See http://msdn.microsoft.com/library/ie/ms534361.aspx

     

    Regards, Jiri

     

  • cagin.uludamar
    cagin.uludamar
    66 Posts

    Re: Wait Until Browser Finish Loading

    ‏2013-09-18T11:08:50Z  

    Hi,

    I think  better is to use variable "readyState". This variable describes process loading web page to the browser.

    See http://msdn.microsoft.com/library/ie/ms534361.aspx

     

    Regards, Jiri

     

    In IE, browser().waitForExistance() waits until the page is loaded. But in FF or chrome, this doesn't work.

    I opened a PMR (70796,001,862) and made an online meeting with IBM staff. They saw the issue and working on it. But it is not accepted as a product bug yet.