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

Incorrect code generated for wait step?

5 Answers 84 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris Johnson
Top achievements
Rank 1
Chris Johnson asked on 03 Aug 2010, 05:44 PM
I have an img element that's updated via an ajax call. I want to wait until the onclick attribute contains the text "OpenMailingList". I used the Verification Builder to create an attribute verification step, changed it to a Wait Step in Visual Studio, and finally changed it to a code-behind step. It generated the following code:

HtmlImage ListsLookupButton = Pages.PortalEditSegmentPage.ListsLookupButton;
Wait.For<HtmlImage>(c => c.AssertAttribute().Value("onclick", ArtOfTest.Common.StringCompareType.Contains, "OpenMailingList"), ListsLookupButton, 10000);

This code fails immediately at runtime because c.AssertAttribute throws an exception (the text doesn't match yet) and the For method apparently doesn't catch it.

Is the generated code wrong? Or is there a bug in the For method? (e.g., it should handle the exception.) Or maybe the bug is in my understanding of how Wait.For is supposed to work!

In the meantime, I replaced the generated code with this, which is working fine but is not a great solution because it doesn't leverage the element that is already defined in the element repository.

ActiveBrowser.WaitForElement(10000, "tagname=img", "onclick=~OpenMailingList");

Thanks for any clarification you can provide.

Chris

5 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 04 Aug 2010, 07:54 PM
Hello Chris Johnson,

Thank you for reporting this issue! You are correct, this is a bug in the product. I'm not sure if it's a code generation bug or an execution time bug. I've filed bug 70846 for this issue. Is the workound enough for you or do you need a build with this fixed? I've also awarded your account 500 Telerik points for being the first person to report this bug.

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
0
Chris Johnson
Top achievements
Rank 1
answered on 05 Aug 2010, 05:31 PM
Cody -

My workaround wasn't sufficient. I found I needed to refresh the dom while waiting, so I wrote the function below. But I feel as though I'm reinventing the wheel. Do you think I really needed to call RefreshDomTree, or is that already done inside HtmlContainer.Get? Is there some other API I can use to do this same thing?

/// <summary>
/// Wait for element to meet the criteria in the given clauses. Works for elements that already exist in 
/// DOM tree, or elements that do not yet exist.
/// 
///    WaitForAjaxUpdate<HtmlSpan>(10000, Pages.PortalNewEmailMessage, 
///         "tagname=span", "textcontent=Updated By Ajax");
///
/// Wrote this because there is a bug in the wait code generated by WebUI.
/// </summary>
public static TElement WaitForAjaxUpdate<TElement>(int timeoutMilliseconds, HtmlElementContainer container, params string[] clauses) where TElement : ArtOfTest.WebAii.Controls.Control, new()
{
    int msWaitedSoFar = 0;
    while (msWaitedSoFar < timeoutMilliseconds)
    {
        try
        
            TElement element = container.Get<TElement>(clauses);
            if (element != null)
            {
                return element;
            }
        }
        catch (TimeoutException)
        {
            Manager.Current.ActiveBrowser.RefreshDomTree();
            msWaitedSoFar += container.Timeout;
        }
    }
    throw new TimeoutException("Timed out waiting for ajax update");
}

Thanks!
Chris
0
Cody
Telerik team
answered on 09 Aug 2010, 05:15 PM
Hi Chris Johnson,

Good news. We fixed the bug. It was included in our latest internal build (2010.2.806). Please give it a try.

Sincerely yours,
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
0
Chris Johnson
Top achievements
Rank 1
answered on 10 Aug 2010, 07:28 PM
Cody -

I am interested in trying the latest build, but I need to keep things stable for a while. Can you tell me if the fix was to the generated code, and if so, what is the correct code? I wrote my own wait functions, and would like to remove them if there is a way to use the framework code correctly. If the change was to the framework, then I'll wait until I can update.

Thanks,
Chris
0
Cody
Telerik team
answered on 10 Aug 2010, 08:15 PM
Hello Chris Johnson,

The fix was to the framework so that the generated code works right. The generated code did not change.

Kind 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
Tags
General Discussions
Asked by
Chris Johnson
Top achievements
Rank 1
Answers by
Cody
Telerik team
Chris Johnson
Top achievements
Rank 1
Share this question
or