
A related question: the WaitForElement() method wants a FindParam, but I thought that HtmlFindExpressions were the replacement for FindParams. Should I use FindParams anyway?
7 Answers, 1 is accepted
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.
Cody
the Telerik team

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");
}
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

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.
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
);
Cody
the Telerik team

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
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
Test Studio Trainings