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

WaitUntilReady() is not working as expected

1 Answer 228 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Theja
Top achievements
Rank 1
Theja asked on 19 Apr 2013, 03:44 PM
I am using Telerik.Testing.Framework.2012.2.1527
I am using the below code. I am getting null for "findElem" all the time. but when I am in debug mode it is fine. WaitUntilReady(); is not working as expected for me. In my scenario I should not be using waitforelement and specify timeout.

public bool IsPresentbyInputId(string findCondition)
{
    Manager.ActiveBrowser.WaitUntilReady();
    Element findElem = Manager.ActiveBrowser.Find.ByExpression(new HtmlFindExpression("tagname=input", "id=" + findCondition));
    Manager.ActiveBrowser.WaitUntilReady();
    return findElem != null && !findElem.Attributes.Any(s => s.Value.Contains("display:none"));
}

If I set the Execution Delay to >500, my tests are running fine. But if I give it 0 they fail to find elements.
Manager.Settings.ExecutionDelay = 500;
Can you let m know what I am missing here?

1 Answer, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 24 Apr 2013, 07:51 PM
Hello Theja,

I apologize for the delay getting back to you on this.

One thing to keep in mind is that WaitUntilReady is monitoring the browsers "Ready" flag. This flag is set as soon as the browser is done the main HTML page (e.g. MyPage.html) plus any referenced resources (images, css files, js files, etc.). It does not take into account any Ajax Postbacks that are initiated as a result of the JavaScript getting control once the page is loaded.

Ajax Postbacks (usually shown visually via a some type of spinning circle as data is being fetched from the web server) can cause the DOM to be modified long after WaitUntilReady returns control to your test code. If setting Execution Delay > 500 makes your test work, it's my bet your application is doing Ajax Postbacks causing the DOM to change.

There are two possible ways to overcome this particular problem:
1) Add a ActiveBrowser.WaitForAjax() call right after the WaitUntilReady() call. This will cause your test to wait until all Ajax connections to your web server are closed.
2) Add a WaitForElement after the WaitUntilReady. For example:
ActiveBrowser.WaitForElement(new HtmlFindExpression("id=maindiv"), 30000, false);
This will cause your code to wait for an element matching the specified properties to exist before moving on.

I hope this helps.

Greetings,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Theja
Top achievements
Rank 1
Answers by
Cody
Telerik team
Share this question
or