Intermittent failure when FindStrategy.WhenNotVisibleReturnNull is used

11 posts, 0 answers
  1. kwee
    kwee avatar
    28 posts
    Member since:
    Sep 2011

    Posted 07 Sep 2014 Link to this post

    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?
  2. kwee
    kwee avatar
    28 posts
    Member since:
    Sep 2011

    Posted 07 Sep 2014 in reply to kwee Link to this post

    Forgot to add: TTF 2014.2 and Visual Studio 2012.
  3. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 10 Sep 2014 Link to this post

    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
     
  4. kwee
    kwee avatar
    28 posts
    Member since:
    Sep 2011

    Posted 10 Sep 2014 in reply to Cody Link to this post

    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
  5. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 11 Sep 2014 Link to this post

    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
     
  6. kwee
    kwee avatar
    28 posts
    Member since:
    Sep 2011

    Posted 11 Sep 2014 in reply to Cody Link to this post

    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.
  7. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 16 Sep 2014 Link to this post

    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
     
  8. kwee
    kwee avatar
    28 posts
    Member since:
    Sep 2011

    Posted 17 Sep 2014 in reply to Cody Link to this post

    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.
  9. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 22 Sep 2014 Link to this post

    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
     
  10. kwee
    kwee avatar
    28 posts
    Member since:
    Sep 2011

    Posted 23 Sep 2014 in reply to Cody Link to this post

    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?
  11. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 26 Sep 2014 Link to this post

    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
     
Back to Top