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

Intermittent failure when FindStrategy.WhenNotVisibleReturnNull is used

10 Answers 34 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
kwee
Top achievements
Rank 1
kwee asked on 07 Sep 2014, 10:51 PM
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?

10 Answers, 1 is accepted

Sort by
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
Cody
Telerik team
answered on 10 Sep 2014, 08:59 PM
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
 
Quickly become an expert in Test Studio, check out our new training sessions!
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
0
Cody
Telerik team
answered on 11 Sep 2014, 11:22 PM
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
 
Quickly become an expert in Test Studio, check out our new training sessions!
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.
0
Cody
Telerik team
answered on 17 Sep 2014, 02:56 AM
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
 
Quickly become an expert in Test Studio, check out our new training sessions!
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.
0
Cody
Telerik team
answered on 22 Sep 2014, 09:42 PM
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
 
Quickly become an expert in Test Studio, check out our new training sessions!
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?
0
Cody
Telerik team
answered on 26 Sep 2014, 04:32 PM
Hi Kwee,

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