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

WPF element with Visibility.Collapsed is giving "Wait for condition has timed out." when not shown

5 Answers 461 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lyudmil
Top achievements
Rank 1
Lyudmil asked on 29 Jan 2013, 02:09 PM
Hello Telerik Team
I'm automating WPF application with Telerik Testing Framework (2012_2_1204). Great framework!.
Shown in the attachment is DockPanel with 3 buttons inside. Buttons are shown on application based on business logic. Currently only Edit is shown. Other two buttons are hidden with Visibility=Collapsed. I want to verify that specific button is not shown on application window.
Having sample code structure:
Application:
namespace Test
{
    public class AppName
    {
        public ArtOfTest.WebAii.Wpf.WpfApplication ApplicationWebAii { get; private set; }
        public AppName(ArtOfTest.WebAii.Wpf.WpfApplication webAiiApp) { ApplicationWebAii = webAiiApp; }
        public WindowName WindowName { get { return new WindowName(ApplicationWebAii.WaitForWindow("WindowName").Find); } }
    }
}

Window class containing buttons. Buttons are located by exact XamlPath:
using ArtOfTest.WebAii.Controls.Xaml.Wpf;
using ArtOfTest.WebAii.Silverlight;
using ArtOfTest.WebAii.TestTemplates;

namespace Test
{
    public class WindowName : XamlElementContainer
    {
        public WindowName(VisualFind find) : base(find) { }
        public Button OK { get { return Get<Button>("XamlPath=/DockPanel[0]/Button[0]"); } }
        public Button Edit { get { return Get<Button>("XamlPath=/DockPanel[0]/Button[1]"); } }
    }
}

Trying to access button OK in my test class code: AppName.WindowName.OK gives exception:
Wait for condition has timed out:
   at ArtOfTest.Common.WaitSync.CheckResult(WaitSync wait, String extraExceptionInfo, Object target)
   at ArtOfTest.Common.WaitSync.For[T](Predicate`1 predicate, T target, Boolean invertCondition, Int32 timeout, WaitResultType errorResultType)
   at ArtOfTest.Common.WaitSync.For[T](Predicate`1 predicate, T target, Boolean invertCondition, Int32 timeout)
   at ArtOfTest.WebAii.Silverlight.VisualWait.ForVisible(Int32 timeout)
   at ArtOfTest.WebAii.TestTemplates.XamlElementContainer.Get(XamlFindExpression expr, Boolean waitOnElement, Int32 timeout)
   at ArtOfTest.WebAii.TestTemplates.XamlElementContainer.Get(XamlFindExpression expr)
   at ArtOfTest.WebAii.TestTemplates.XamlElementContainer.Get[TControl](XamlFindExpression expr)
   at ArtOfTest.WebAii.TestTemplates.XamlElementContainer.Get[TControl](String[] clauses)

This exception is thrown after ~10 seconds and is in case of Visibility=Collapsed. If button is shown then there is no exception and element is located.

I'm handling this by "try {AppName.WindowName.OK} catch (System.Exception) {} and if element is not found taking appropriate actions in catch. This work for me with the limitation that it slows down my test with 10 seconds for each hidden element invocation.

I wonder is this issue with Telerik Testing Framework or me using it incorrectly :-) Thanks for your support.

5 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 01 Feb 2013, 04:59 PM
Hi Lyudmil,

You should be able to find the buttons even if the Visibility is Collapsed. I have created a simple WPF project with two buttons(one Collapsed and one Visible) to test this scenario, however as you can see in this video I was able to find them both as expected. Could you create a small sample WPF application and a sample test that reproduces this problem which we can execute here and study this behavior? Once we can observe the problem happening first hand then we can analyze it and determine the root cause.

Regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Lyudmil
Top achievements
Rank 1
answered on 05 Feb 2013, 10:04 AM
Hi Plamen

I'm attaching a project that reproduces the case. Visibility is being toggled with binding. I've taken sample application given in this example http://davidsandor.com/post/2010/05/05/WPF-Databinding-visibility-of-a-control-to-your-ViewModel-DataContext-boolean-value.aspx and added some automation to it.
When checkbox in application is unchecked the button is with Visibility Collapsed. On checking the checkbox button is shown.
When button is hidden there is System.TimeoutException when try to locate it.

Hope that helps.

Regards Lyudmil
0
Plamen
Telerik team
answered on 08 Feb 2013, 11:06 AM
Hi Lyudmil,

Thank you for providing the project. You are not getting System.TimeoutException because your code failed to find the element, you are getting it because your code timed out when trying to click on that element. This is expected behavior when the button Visibility is Collapsed. I have recorded this short video to demonstrate that the button actually exists and I'm able to find it using the following line of code.
Button button = Manager.Current.ActiveApplication.MainWindow.Find.ByName<Button>("button1");


Regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Lyudmil
Top achievements
Rank 1
answered on 12 Feb 2013, 10:14 AM
Hi Plamen

You are absolutely right. I've given incorrect information and not proper definition of the situation.
In my tests I'm using:
public TControl Get<TControl>(params string[] clauses) where TControl : ArtOfTest.WebAii.Controls.Xaml.IFrameworkElement;

method of ArtOfTest.WebAii.TestTemplates.XamlElementContainer class to locate elements by XamlPath.

As you suggested I've tried locating them by XamlPath with
public virtual T ByExpression(V expression);

method of ArtOfTest.WebAii.Silverlight.VisualFind class and element is found successfully.

So I restate the original post. Problem is in Get method giving TimeoutException trying to locate the element while Find.ByExpression method locates it correctly.

I'm attaching screenshot trying to visualise code I'm using and where exception is thrown. When button is shown both Find and Get are able to locate element and get its IsVisible property. When element is hidden Find is able to locate the element and gets its IsVisible property while Get fails giving an exception.

Regard Lyudmil
0
Plamen
Telerik team
answered on 13 Feb 2013, 03:52 PM
Hi Lyudmil,

Thanks for the additional info. Yes you are right, the Get method checks the visibility and throws TimeoutException exception if the Visibility is Collapsed. I filed a bug on this behavior which you can track here: Public URL.

I have also updated your Telerik points for discovering the issue.

Regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Lyudmil
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Lyudmil
Top achievements
Rank 1
Share this question
or