This is a migrated thread and some comments may be shown as answers.

Is there a way to wait for the page is loaded using testing framework

9 Answers 1000 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Surya
Top achievements
Rank 1
Surya asked on 30 Sep 2011, 04:14 PM
I am using Testing Framework Telerik_Testing_Framework_2011_2_928_FREE_EDITION with c# for chrome browser.
When i click some thing on the page to navigate to other page it is taking longer time to load the page.
Is there any method is to wait until the page is loaded ? and do the next steps..
_WebAiiBrowser.IsReady() -->is not working

  Manager _MyManager = null;
            Browser _WebAiiBrowser = null;
            string str = "";
            ArtOfTest.WebAii.Core.Settings aSettings = new ArtOfTest.WebAii.Core.Settings(new Settings.WebSettings(BrowserType.Chrome ));
            _MyManager = new Manager(aSettings);
            _MyManager.Start();

            _MyManager.LaunchNewBrowser();
            _WebAiiBrowser = _MyManager.ActiveBrowser;
 
            // Navigate to a certain web page
           _WebAiiBrowser.NavigateTo("http://www.yahoo.com");
           try
           {
               str = _WebAiiBrowser.Find.ByTagIndex("body", 0).InnerMarkup;
               str=_WebAiiBrowser.ViewSourceString;
               _WebAiiBrowser.IsReady ();
str=_WebAiiBrowser.ViewSourceString; // this line is hitting before the page renders..

9 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 30 Sep 2011, 11:15 PM
Hi Surya,

Here's some sample code:

// After performing a mouse click you may need to explicitly wait  
// for the browser to be ready. You very rarely would need to
// call this function when using the Actions methods. 
ActiveBrowser.WaitUntilReady();
  For more information please see this page. Keep in mind that the WaitUntilReady line is only useful for HTML pages. Silverlight apps will not sync with the browser's state and will often still be loading while the browser displays "Ready". In that case you'll need to single out one or more of the slowest loading elements and perform individual Waits on them. As a last resort you can always use a fixed Execution Delay.

You can also wait on a specific known element to appear.

Or you may be dealing with an AJAX Postback.

Greetings,
Anthony
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Saket
Top achievements
Rank 1
answered on 03 Nov 2011, 10:40 AM
Hi,
I am facing the same issue, in my case the page rendering is composed of multiple frames. I want it to be connected only when all the frames are loaded completely
0
Anthony
Telerik team
answered on 03 Nov 2011, 02:49 PM
Hi Saket,

Try this line of code:

ActiveBrowser.Frames.WaitAllUntilReady();

Also see our page on Frames Support in code. 

Best wishes,
Anthony
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ryan
Top achievements
Rank 2
answered on 02 Jan 2013, 10:19 PM
Perform individual waits on the slowest elements?? Waiting for the page to be ready is like the most fundamental function in UI automation and you have to use a hack? There must be a better way.
0
Konstantin Petkov
Telerik team
answered on 10 Jan 2013, 08:18 AM
Hi Ryan,

In general the framework (as well as Test Studio) handles that internally. If you get any particular failure please share the details and we will do our best to help.

Kind regards,
Konstantin Petkov
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Cody
Telerik team
answered on 10 Jan 2013, 06:42 PM
Hi Ryan,

Do you know if you're dealing a page that has at least one Ajax postback event during the page loading? If this is the case you can take advantage of our WaitForAjax API call, like this:

ActiveBrowser.WaitForAjax(30000);

The above will cause the test script to wait up to 30 seconds for all Ajax post backs to finish. When the limit is reached (whatever the limit is set to) the test won't fail, it will simply continue to the next line of code.

Greetings,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Ryan
Top achievements
Rank 2
answered on 10 Jan 2013, 09:30 PM
I'm working with a pure Silverlight application.

I'm having some success with a combination of FindStrategy.AlwaysWaitForElementsVisible and using my own .Click() method that waits for all the 'loading' elements to disappear. It still sometimes tries to interact with the page before it's ready, but here's a snippet in case it helps someone:

public static void Click(this FrameworkElement element)
        {            
            var app = (SilverlightApp)element.Host;
            app.WaitForPageToLoad();
            element.User.Click();
            app.WaitForPageToLoad();
            app.RefreshVisualTrees();
        }

public static void WaitForPageToLoad(this SilverlightApp app)
        {
            //Get all of the loading messages on the page
            var loadingElements = app.Find.AllByTextContent("~Loading");

            //Check if any are visible
            foreach (var loadingElement in loadingElements)
            {
                try
                {
                    //Wait for it to disappear or fail to find it
                    while (loadingElement.IsVisible)
                        Thread.Sleep(1000);
                }
                catch (FindElementException)
                { }
            }
       }
0
Manjunath
Top achievements
Rank 1
answered on 26 Dec 2013, 10:53 AM
Is there any other  solution to wait untill the page load in IE with out specifying time in ActiveBrowser.WaitUntilReady() and ActiveBrowser.WaitForAjax()?
0
Cody
Telerik team
answered on 26 Dec 2013, 07:59 PM
Hi Manjunath,

The short answer is no there isn't a better way. Allow me to explain the technical challenges involved with the loading of pages.

IE (and all browsers) do have a "ready" indicator. This indicator is "true" when the browser is done loading the main HTLM page plus all the resources referenced by that page (css files, image files, JavaScript files, etc.). This is great and very reliable for very static pages. The browser loads the HTML, plus all the needed resource files and nothing more happens. Anyone would declare that "the page is loaded" at this point.

Now we move into the realm of "Web 2.0" with dynamic pages and content. Once the JavaScript files are loaded the JavaScript engine fires up and begins executing the code and following the instructions contained in that code. Because JavaScript is an actual programming language, the web developer can tell it to do anything the developer wants it to do (within the limitations of the JavaScript sandbox). This includes:
  • Modifying the already loaded HTML page
  • Downloading additional HTML content
  • Sending data to the web server
  • Calling a web service, getting data and displaying that data
Here is where the real complication comes in. What is "done" in this realm? The JavaScript engine continuously runs in the background and can do anything it's programmed to do at anytime without "asking permission" or telling anyone it's "done" or about to do something more. A web page with constantly rotating/changing data (imagine a stock ticker site) or advertisements or "latest news developments" is a prime example of this.

AJAX is a JavaScript library that is popular and widely used. It has a defined structure which we can count on. Because its structure is defined we can monitor it. But if the web developer does something completely different, there's no simple definition which the test can count on of when the page is "done".

I hope this explanation sheds some light on the problem of "when is the page done loading" problem. 


Regards,
Cody
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Surya
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Saket
Top achievements
Rank 1
Ryan
Top achievements
Rank 2
Konstantin Petkov
Telerik team
Cody
Telerik team
Manjunath
Top achievements
Rank 1
Share this question
or