Ajax Testing

8 posts, 0 answers
  1. Ron Rudman
    Ron Rudman avatar
    5 posts
    Member since:
    Apr 2010

    Posted 03 May 2011 Link to this post

    I'm trying to test report pages generated by SQL Server Reporting Services 2008. With every navigational click, the pages render an Ajax "Loading" message. How do I wait until that message goes away?

    A related question: the WaitForElement() method wants a FindParam, but I thought that HtmlFindExpressions were the replacement for FindParams. Should I use FindParams anyway?
  2. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 06 May 2011 Link to this post

    Hello Ron Rudman,

    Watching and waiting for the Ajax Loading message to come and go is very problematic. The Testing Framework polls the browser on a 200ms cycle. If the loading message comes and goes away too quickly, in between the times we poll the browser, it can be missed all together which can cause your test to fail. We strongly recommend against using the Ajax loading message as a synchronization point.

    Instead we recommend watching for some change in the UI to appear, preferably some fixed static element/text that will always show up once the Loading message goes away. Alternatively you could simply take a snapshot of the data that's currently there, then wait for it to change.

    You should be using ActiveBrowser.WaitForElement which takes an HtmlFindExpression.

    Greetings,
    Cody
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Ron Rudman
    Ron Rudman avatar
    5 posts
    Member since:
    Apr 2010

    Posted 10 May 2011 Link to this post

    Even waiting for a known change to occur is giving me problems.  When the report window comes up, I can see the pager control at the top. This is an HtmlInputText control that displays the current page number. Initially, this control, although visible, displays no value until the Ajax is completed and the initial content is displayed.  At that point, the page field shows "1". So that's what I would like to wait for.

    HtmlInputText Pager = ActiveBrowser.Find.ByAttributes<HtmlInputText>("Title=Current Page");
    Pager.Wait.ForContent(FindContentType.TextContent, "1");

    I can see the report window open with a null page value, I can see the ajax control finally disappear, and I can see the page number change to 1. But then I see continued polling until I time out. 

    I have gone into Visual Studio and stopped at the Wait. Observing that the visual page did indeed show a value of "1", I executed "ActiveBrowser.Find.ByAttributes<HtmlInputText>("Title=Current Page").Value" in the immediate window and got null, which kind of explains why I would time out.  However, if I re-execute the same Immediate command, it then gives the expected value of "1". 

    I tried the following, thinking that maybe the wait would not be satisifed if the page were already 1, but even this doesn't work - the wait gets executed and always times out.
    .
    HtmlInputText Pager = ActiveBrowser.Find.ByAttributes<HtmlInputText>("Title=Current Page"); 
    if (Pager.value == null)
    {
          Pager.Wait.ForContent(FindContentType.TextContent, "1");
    }
  4. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 16 May 2011 Link to this post

    Hi Ron Rudman,

    Can you share with me the HTML surrounding your paging control? I did a quick test to verify Wait.ForContent works as expected. Here is the HTML sample I used:

    <div id="data" onclick="OnAjaxCall()" style="width: 200px; height: 100px; border: solid 1px black;
        text-align: center">
        <h3 id="status">Click me to start</h3>
    </div>

    And here's the sample code to work with it:

    HtmlDiv myDiv = Find.ById<HtmlDiv>("data");
    myDiv.Click();
     
    Element status = Find.ById("status");
    status.Wait.ForContent(FindContentType.TextContent, "Complete");

    I simulated an AJAX postback using JavaScript. After 1 second the text for the h3 tag will change to "Complete". The test successfully detects this with the proper timeout.

    Greetings,
    Cody
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Ron Rudman
    Ron Rudman avatar
    5 posts
    Member since:
    Apr 2010

    Posted 17 May 2011 Link to this post

    I was finally able to do this as follows:
    FindParam Pager = new FindParam("Title=Current Page", "Value=1");
    ActiveBrowser.Actions.WaitForElement(Pager, _TimeOut);

    In retrospect, this makes perfect sense. The page looks like this in a view source:
    <input type="text" maxlength="8" size="3" id="ctl00_ContentPlaceHolder1_rvMain_ctl06_ctl00_CurrentPage" 
    disabled="disabled" title="Current Page" />

    After the Ajax got through with it, "Value=1" was added, but that's not really content. The way I finally did it doesn't look for content but for an attribute value.
  6. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 18 May 2011 Link to this post

    Hello Ron Rudman,

    I am very glad you found a solution to this. Viewing the HTML involved makes a big difference on coming up with the right solution. Keep in mind we are deprecating the FindParam class. It is being replaced with HtmlFindExpression and XamlFindExpression. In a future version FindParam will be removed from the product. Here is equivalent code that will continue to work for you in the future.

    HtmlFindExpression Pager = new HtmlFindExpression("TagName=input", "Title=Current Page", "Value=1");
    ActiveBrowser.WaitForElement(Pager, _TimeOut, false);

    Regards,
    Cody
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Sambodhan
    Sambodhan avatar
    1 posts
    Member since:
    May 2014

    Posted 12 Aug 2014 in reply to Cody Link to this post

    Hi Cody,

    Say for example my another function creates object & add properties to it like this:
    HtmlInputText username = ActiveBrowser.Find.ByAttributes<HtmlInputText>("Title=Username"); 

    And now I have object Pager with me, in this case how I can find the different search attributes/search expression added to this object? I tried username.locateExpression(), but it returns null since it is from the abstract class.

    If I have this expression I can directly use it in below code snippet:

    HtmlFindExpression Pager = new HtmlFindExpression("TagName=input", "Title=Current Page", "Value=1");
    ActiveBrowser.WaitForElement(Pager, _TimeOut, false);


    Please suggest the way to fetch the HtmlFindExpression from an object

    Thanks
    SD
  8. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 14 Aug 2014 Link to this post

    Hello Sambodhan,

    In code, once you have an element object, such as an HtmlDiv type object, there are no find expressions attached to it. You can get at all the various properties of the elements e.g. the attributes, the class names, the absolute tag index, and so on. Any of these could be used to create a find expression... it's just that we don't save which find expression was used to find that particular element after it has been found.

    Now if you're using our Pages class, which is automatically generated by Test Studio, there is a way to get at the find expression Test Studio would use to locate the element the next time you ask it to. For example, let's say I have an element in my Pages class named Pages.HomePage.NextButton. I can fetch the find expression associated with that element definition using Pages.HomePage.Expressions.NextButton. This returns a HtmlFindExpression (or a XamlFindExpress if i'm testing a Silverlight application).

    Does this help or at least clarify?

    Regards,
    Cody
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
Back to Top