Hi,
I am using Find Strategy in the manner described in http://www.telerik.com/forums/how-to-judge-whether-the-element-exists
However, in a repeated set of runs, sometimes line 175 below fails with the traceback below. Sometimes this exception occurs
in run 10, sometimes in run 6 etc.
> public void SanitizedFunction()
> {
>
> FindStrategy originalStrategy = wpfClient.MainWindow.Find.Strategy;
> wpfClient.MainWindow.Find.Strategy = FindStrategy.WhenNotVisibleReturnNull;
> try
> {
> wpfClient.MainWindow.Window.SetFocus();
> wpfClient.MainWindow.RefreshVisualTrees();
line 175 > var dvGrid = wpfClient.MainWindow.Find.ByAutomationId("RadGridView"); // telerik control with AutomationId added
> if(dvGrid!=null)
> {
> // real work here ...
> }
> else
> {
> Assert.IsTrue(dvGrid!=null,"dvGrid should not be null");
> }
> }
> finally
> {
> wpfClient.MainWindow.Find.Strategy = originalStrategy;
> }
> }
>
The traceback :
> at ArtOfTest.WebAii.Wpf.WpfProxy.ExecuteSLCommand(SilverlightCommand cmd)
> at ArtOfTest.WebAii.Wpf.WpfProxy.GetVisibility(IAutomationPeer peer)
> at ArtOfTest.WebAii.Silverlight.FrameworkElement.get_Visibility()
> at ArtOfTest.WebAii.Silverlight.FrameworkElement.get_IsVisible()
> at Telerik.XamlAutomation.SteelThread.TelerikSteelThread.SanitizedFunction() in TelerikSteelThread.cs: line 175
> at Telerik.XamlAutomation.SteelThread.TelerikSteelThread.Execute(IEnumerable`1 funcs) in TelerikSteelThread.cs: line 268
> at Telerik.XamlAutomation.SteelThread.TelerikSteelThread.OneRunNotamSteelThread() in TelerikSteelThread.cs: line 402
> at Telerik.XamlAutomation.SteelThread.TelerikSteelThread.<TestLoop>b__3(Int32 i) in TelerikSteelThread.cs: line 427
> at Jeppesen.MarineOperations.DotnetUtils.LinqUtils.ForEach(IEnumerable`1 enumeration, Action`1 action) in LinqUtils.cs: line 21
> at Telerik.XamlAutomation.SteelThread.TelerikSteelThread.TestLoop() in TelerikSteelThread.cs: line 424
>
The traceback seems to say that FindByAutomationId fails because dvGrid is not visible, right in the Find itself, so the check
for dvGrid==null is too late, ocassionally.
Any ideas why this is so?
I am using Find Strategy in the manner described in http://www.telerik.com/forums/how-to-judge-whether-the-element-exists
However, in a repeated set of runs, sometimes line 175 below fails with the traceback below. Sometimes this exception occurs
in run 10, sometimes in run 6 etc.
> public void SanitizedFunction()
> {
>
> FindStrategy originalStrategy = wpfClient.MainWindow.Find.Strategy;
> wpfClient.MainWindow.Find.Strategy = FindStrategy.WhenNotVisibleReturnNull;
> try
> {
> wpfClient.MainWindow.Window.SetFocus();
> wpfClient.MainWindow.RefreshVisualTrees();
line 175 > var dvGrid = wpfClient.MainWindow.Find.ByAutomationId("RadGridView"); // telerik control with AutomationId added
> if(dvGrid!=null)
> {
> // real work here ...
> }
> else
> {
> Assert.IsTrue(dvGrid!=null,"dvGrid should not be null");
> }
> }
> finally
> {
> wpfClient.MainWindow.Find.Strategy = originalStrategy;
> }
> }
>
The traceback :
> at ArtOfTest.WebAii.Wpf.WpfProxy.ExecuteSLCommand(SilverlightCommand cmd)
> at ArtOfTest.WebAii.Wpf.WpfProxy.GetVisibility(IAutomationPeer peer)
> at ArtOfTest.WebAii.Silverlight.FrameworkElement.get_Visibility()
> at ArtOfTest.WebAii.Silverlight.FrameworkElement.get_IsVisible()
> at Telerik.XamlAutomation.SteelThread.TelerikSteelThread.SanitizedFunction() in TelerikSteelThread.cs: line 175
> at Telerik.XamlAutomation.SteelThread.TelerikSteelThread.Execute(IEnumerable`1 funcs) in TelerikSteelThread.cs: line 268
> at Telerik.XamlAutomation.SteelThread.TelerikSteelThread.OneRunNotamSteelThread() in TelerikSteelThread.cs: line 402
> at Telerik.XamlAutomation.SteelThread.TelerikSteelThread.<TestLoop>b__3(Int32 i) in TelerikSteelThread.cs: line 427
> at Jeppesen.MarineOperations.DotnetUtils.LinqUtils.ForEach(IEnumerable`1 enumeration, Action`1 action) in LinqUtils.cs: line 21
> at Telerik.XamlAutomation.SteelThread.TelerikSteelThread.TestLoop() in TelerikSteelThread.cs: line 424
>
The traceback seems to say that FindByAutomationId fails because dvGrid is not visible, right in the Find itself, so the check
for dvGrid==null is too late, ocassionally.
Any ideas why this is so?
10 Answers, 1 is accepted
0
kwee
Top achievements
Rank 1
answered on 07 Sep 2014, 11:08 PM
Forgot to add: TTF 2014.2 and Visual Studio 2012.
0
Hello Kwee,
What exception is being reported (e.g. NullReferenceException)? The stack trace you provided is helpful, after we know what specific exception was reported.
Regards,
Cody
Telerik
What exception is being reported (e.g. NullReferenceException)? The stack trace you provided is helpful, after we know what specific exception was reported.
Regards,
Cody
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings
0
kwee
Top achievements
Rank 1
answered on 10 Sep 2014, 09:20 PM
Hi Cody,
Thanks for taking a look.
The exception is :
Test method Telerik.XamlAutomation.SteelThread.TelerikSteelThread.TestLoop threw exception:
ArtOfTest.Common.Exceptions.FindElementException: Unable to find the specified element: Unable to find the element of type: radgridview
Thanks for taking a look.
The exception is :
Test method Telerik.XamlAutomation.SteelThread.TelerikSteelThread.TestLoop threw exception:
ArtOfTest.Common.Exceptions.FindElementException: Unable to find the specified element: Unable to find the element of type: radgridview
0
Hi Kwee,
Thank you for that additional detail. It seems unlikely that the automation ID for your RadGridView is "RadGridView". For example, in our own online demo the automation ID is set using the x:Name attribute placed in the XAML, like this:
<telerik:RadGridView x:Name="RadGridView1"
If you look in your XAML what do you see?
Regards,
Cody
Telerik
Thank you for that additional detail. It seems unlikely that the automation ID for your RadGridView is "RadGridView". For example, in our own online demo the automation ID is set using the x:Name attribute placed in the XAML, like this:
<telerik:RadGridView x:Name="RadGridView1"
Regards,
Cody
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings
0
kwee
Top achievements
Rank 1
answered on 12 Sep 2014, 04:25 AM
Hi Cody,
1) I have access to the source .xaml file, and "RadGridView" was added by myself as AutomationProperties.AutomationId.
2) The test runs correctly most of the time, ie RadGridView is found without problems. Once in a while, this failure occurs.
It does seem strange, but I'm open to ideas to help narrow it further. The failure frequency is sporadic. I had a good run of successes, but later when I clean and rebuild ( no code change ), I would get failure on the first run. Basically, it is intermittently failing.
Also, if I run it in the debugger ( Run Test in Debug, without any breakpoints ), failure rate is less but still occurs.
1) I have access to the source .xaml file, and "RadGridView" was added by myself as AutomationProperties.AutomationId.
2) The test runs correctly most of the time, ie RadGridView is found without problems. Once in a while, this failure occurs.
It does seem strange, but I'm open to ideas to help narrow it further. The failure frequency is sporadic. I had a good run of successes, but later when I clean and rebuild ( no code change ), I would get failure on the first run. Basically, it is intermittently failing.
Also, if I run it in the debugger ( Run Test in Debug, without any breakpoints ), failure rate is less but still occurs.
0
Hi Kwee,
Since it is an intermittent failure, it sounds like a problem of the test trying to act on the grid too soon. Perhaps you need to add a Wait For Exists step before the failing step. Wait for the rad grid view to exist before trying to interact with it. Let me know if you need help adding this type of test step.
Regards,
Cody
Telerik
Since it is an intermittent failure, it sounds like a problem of the test trying to act on the grid too soon. Perhaps you need to add a Wait For Exists step before the failing step. Wait for the rad grid view to exist before trying to interact with it. Let me know if you need help adding this type of test step.
Regards,
Cody
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings
0
kwee
Top achievements
Rank 1
answered on 18 Sep 2014, 02:38 AM
Hi Cody,
The intermittent failure is in line 175:
var dvGrid = wpfClient.MainWindow.Find.ByAutomationId("RadGridView");
It is too late to call dvGrid.Wait.ForVisible(2000) because the exception is thrown before dvGrid value is obtained.
Also, the FindStrategy is set to Always Wait For Elements Visible.
The intermittent failure is in line 175:
var dvGrid = wpfClient.MainWindow.Find.ByAutomationId("RadGridView");
It is too late to call dvGrid.Wait.ForVisible(2000) because the exception is thrown before dvGrid value is obtained.
Also, the FindStrategy is set to Always Wait For Elements Visible.
0
Hello Kwee,
Maybe the problem is that our cached copy of the Silverlight visual tree is out of date. Try refreshing it before the .Find using this code:
wpfClient.MainWindow.RefreshVisualTrees();
Regards,
Cody
Telerik
Maybe the problem is that our cached copy of the Silverlight visual tree is out of date. Try refreshing it before the .Find using this code:
wpfClient.MainWindow.RefreshVisualTrees();
Regards,
Cody
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings
0
kwee
Top achievements
Rank 1
answered on 23 Sep 2014, 08:13 PM
Hi Cody,
If you look at the sample code in the first post, I already call RefreshVisualTrees() just before calling Find. Good idea but it didn't help.
If we take a different approach, when the FindStrategy is set to WhenNotVisibleReturnNull, I would expect dvGrid to be set to null
instead of an exception inside Find itself. Why is the strategy not being honored?
If you look at the sample code in the first post, I already call RefreshVisualTrees() just before calling Find. Good idea but it didn't help.
If we take a different approach, when the FindStrategy is set to WhenNotVisibleReturnNull, I would expect dvGrid to be set to null
instead of an exception inside Find itself. Why is the strategy not being honored?
0
Hi Kwee,
Here is an example of the correct method to wait for an element to exist:
Regards,
Cody
Telerik
Here is an example of the correct method to wait for an element to exist:
SilverlightApp slapp = ActiveBrowser.SilverlightApps()[0];slapp.Find.Strategy = FindStrategy.WhenNotVisibleReturnElementProxy;TextBox tb = slapp.Find.ByAutomationId<TextBox>("tbAddedTextBox");tb.Wait.ForExists(60000);Regards,
Cody
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings