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

RadTreeView.FindNodeByText - should return null if not found but throws exception

11 Answers 147 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dren
Top achievements
Rank 1
Dren asked on 05 Dec 2011, 07:13 AM
Hi,

I am looking at using FindNodeByText to test that an item ISN'T in the list. According to this page , it should return null if the item isn't in the list. But what happens now is that it throws an exception if the item isn't in the list.

This is a major obstacle in my testing so would appreciate any help or workarounds.

Thanks,
Dren

11 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 08 Dec 2011, 12:39 PM
Hello Dren,

Which version of Telerik Testing Framework you are currently using? I checked the source code for this method and tested it with our latest official SP1 release(2011.2.1117). It works as expected and returns null if the node doesn't exists.

Please upgrade to our latest release, you can download it from your Telerik account here: Public URL .

Best wishes,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dren
Top achievements
Rank 1
answered on 11 Dec 2011, 11:56 PM
Hi Plamen,

Thank you, I didn't realise there was a new framework (I thought I was subscribed to such notifications?)!

I've tried the new framework and it still doesn't work:

System.NullReferenceException: Object reference not set to an instance of an object.
at Telerik.WebAii.Controls.Xaml.RadTreeView.FindNode(Predicate`1 predicate)
at Telerik.WebAii.Controls.Xaml.RadTreeView.FindNodeByText(String nodeText)
etc.

Thanks,
Dren
0
Cody
Telerik team
answered on 12 Dec 2011, 12:31 AM
Hello Dren,

I am a little confused and not certain you're in the right place for your question. The page you reference is for ASP.NET programming using our Rad controls. However this forum is dedicated to our Free Testing Framework which can be used for writing your own coded unit test for functional testing of web pages, such as ASP.NET pages that include our Rad Controls.

All the best,
Cody
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dren
Top achievements
Rank 1
answered on 12 Dec 2011, 12:39 AM
Hi Cody,

I am writing an automated test harness in C# to enable the testing of our Silverlight application (which uses telerik rad controls), using the telerik free testing framework (which I'm ever so grateful to have found!).

I must have just linked to the wrong page in my initial post, sorry about that. This is what I'm trying to do: (Note that FindNodeByText works just fine when the node exists)

public bool DoesItemExist(string item)
{
    if (Control.FindNodeByText(item) == null)            // Control is a RadTreeView object
    {
        return false;
    }
    else
    {
        return true;
    }
}



Thanks,
Dren
0
Plamen
Telerik team
answered on 12 Dec 2011, 02:56 PM
Hi Dren,

Which version of Test Studio you are currently using? Please upgrade to our latest internal build (2011.2.1209). You can download it from your Telerik account here: Public URL (see screenshot).  

Also, you will receive a compilation error trying to get the RadTreeView using code similar to the following:
RadTreeView val = Pages.ASPNETTreeViewDemo.RadTreeView1Div;

You need to specify the complete namespace, because we have the same control for Html, Xaml and WPF. Here's the correct way to do it:
Telerik.WebAii.Controls.Html.RadTreeView val = Pages.ASPNETTreeViewDemo.RadTreeView1Div;
 
Check out this video:
http://screencast.com/t/gZgsbw0g .

If you need further assistance, please let me know!

All the best,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Plamen
Telerik team
answered on 12 Dec 2011, 03:39 PM
Hi Dren,

I apologize I sent this by mistake. Last response was for another question from someone else that has a similar problem.

As for your problem, I was not able to reproduce it against our demo here. Here is a video showing that the FindNodeByText method returns null if the node doesn't exists. 
 
I've attached the sample project. Could you please try to replicate your problem against the same demo site? Send us the project(into a zip file), so we can find what is wrong and fix it. 

Hope to hear from you soon!

Kind regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dren
Top achievements
Rank 1
answered on 13 Dec 2011, 12:35 AM
Hi Plamen,

Thanks for your help. Using the demo site, I was able to reproduce my problem.

Please note I don't have TestStudio. I am using Visual Studio and coding the test harness by hand.

In the video you linked to me, I noticed you used Telerik.WebAii.Controls.Html.RadTreeView for the control, however, I am using Telerik.WebAii.Controls.Xaml.RadTreeView. I found the object using:

Manager

.Current.ActiveBrowser.SilverlightApps()[0].Find.ByName<RadTreeView>("radTreeView");

 

(in the above, RadTreeView = Telerik.WebAii.Controls.Xaml.RadTreeView)

And it's not possible to cast the found control to the Html version of the control - only the Xaml version.

I'm a bit confused.

Many thanks,
Dren
0
Plamen
Telerik team
answered on 14 Dec 2011, 11:31 AM
Hello Dren,

Thank you for the additional information.

I was a little confused from your first post and was not aware that this is a Silverlight app you are testing. I was able to replicate the problem and logged it as a bug. You can track its progress in our PITS system here: Public URL .

I have added Telerik Points to your account for discovering this bug for us.

In the meantime, as a workaround, you can use the following code:
RadTreeView Control = new RadTreeView();
 
public bool DoesItemExist(string item)
{
    if (Control.AllNodeElements.FirstOrDefault(node => node.ItemText.Equals(item)) == null)            // Control is a RadTreeView object
    {
        return false;
    }
    else
    {
        return true;
    }
}
  
Control = Manager.Current.ActiveBrowser.SilverlightApps()[0].Find.ByName<RadTreeView>("radTreeView");
 
Log.WriteLine(DoesItemExist("xxx").ToString());


Hope this helps!

Best wishes,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dren
Top achievements
Rank 1
answered on 14 Dec 2011, 11:37 PM
Thanks very much Plamen for raising both the bug and the workaround.

I've tried the workaround and I get the following error:

System.InvalidCastException: Unable to cast object of type 'ArtOfTest.WebAii.Silverlight.UI.HeaderedItemsControl' to type 'Telerik.WebAii.Controls.Xaml.IRadTreeViewItem'.
at ArtOfTest.WebAii.Silverlight.FrameworkElement.CastAs()
at Telerik.WebAii.Controls.Xaml.RadTreeView.get_AllNodeElements()
...

Thanks,
Dren
0
Plamen
Telerik team
answered on 15 Dec 2011, 11:12 AM
Hi Dren,

I was not able to reproduce this problem. Are you sure this is a RadGridView that you are testing or this is a custom control that inherits from RadGridView? Could you please try to test against this Telerik demo and let me know the result?

If your application is publicly accessible, the best way for us to troubleshoot the issue is to see it first-hand. If you consider the info too sensitive for the forum then please go ahead and file a support ticket on this. A support ticket is completely confidential.

Regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Plamen
Telerik team
answered on 15 Dec 2011, 05:34 PM
Hello Dren,

Sorry, I meant to say RadTreeView, not RadGridView.

Regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Dren
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Dren
Top achievements
Rank 1
Cody
Telerik team
Share this question
or