WPF: Retrieve Style information

10 posts, 0 answers
  1. Benoit
    Benoit avatar
    17 posts
    Member since:
    Oct 2014

    Posted 05 Dec 2014 Link to this post

    Hi

    How can I retrieve Style properties like 'Fill', 'Background', ... from Rectangle or Canvas ?
    I tried to retrieve the Fill property with the following code:

    var fillBrush = networkOverlay.GetProperty(new AutomationProperty("Fill", typeof(System.Windows.Media.Brush)))

    But I get the follwing exception:

    [WPF Extension Error] Details: System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
       bei System.Windows.Threading.Dispatcher.VerifyAccess()
       bei System.Windows.Freezable.ReadPreamble()
       bei System.Windows.Media.Brush.ToString()
       bei Telerik.TestingFramework.XamlExtension.ClientProcessor.ObjectToString(Object obj, Boolean isAutomationPeer, Type objType)
       bei Telerik.TestingFramework.XamlExtension.ClientProcessor.ProcessCommand(String command)

    When I tried to directly retrieve the Fill property:

    var fillBrush = myRectangle.Fill;

    I get the following exception:

    [WPF Extension Error] Details: System.ArgumentException: Object of type 'ArtOfTest.WebAii.Controls.Xaml.Wpf.Canvas' cannot be converted to type 'ArtOfTest.WebAii.Controls.Xaml.Wpf.Visual'.
       bei Telerik.TestingFramework.XamlExtension.TechSpecific.DispatcherInvoke(Dispatcher dispatcher, Delegate call, Object[] args)
       bei Telerik.TestingFramework.XamlExtension.ClientProcessor.ObjectToString(Object obj, Boolean isAutomationPeer, Type objType)
       bei Telerik.TestingFramework.XamlExtension.ClientProcessor.ProcessCommand(String command)

    Thank your for your assistance.
    Benoît
  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 10 Dec 2014 Link to this post

    Hi Benoit,

    Please try out this code:

    var fill = (ArtOfTest.WebAii.Controls.Xaml.Wpf.SolidColorBrush)rec.GetProperty(newArtOfTest.WebAii.Silverlight.AutomationProperty("Fill", typeof(ArtOfTest.WebAii.Controls.Xaml.Wpf.SolidColorBrush)));

    Let me know if this helps.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  3. Benoit
    Benoit avatar
    17 posts
    Member since:
    Oct 2014

    Posted 15 Dec 2014 in reply to Boyan Boev Link to this post

    Hi Boyan,

    Thank your for your answer.
    Unfortunately, i have the same exception with wour code:

    var fill = (ArtOfTest.WebAii.Controls.Xaml.Wpf.SolidColorBrush)networkOverlay.GetProperty(new ArtOfTest.WebAii.Silverlight.AutomationProperty("Fill", typeof(ArtOfTest.WebAii.Controls.Xaml.Wpf.SolidColorBrush)));


    [WPF Extension Error] Details: System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
       bei Telerik.TestingFramework.XamlExtension.TechSpecific.DispatcherInvoke(Dispatcher dispatcher, Delegate call, Object[] args)
       bei Telerik.TestingFramework.XamlExtension.ClientProcessor.ObjectToString(Object obj, Boolean isAutomationPeer, Type objType)
       bei Telerik.TestingFramework.XamlExtension.ClientProcessor.ProcessCommand(String command)

    Kind regards,
    Benoît
  4. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 18 Dec 2014 Link to this post

    Hi Benoit,

    In order to assist you best we need to see your application. Could you please grant an access to your application so we can help you with the code?

    You can also send us some screen shots of the DOM and application.

    Hope to hear from you soon.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  5. Benoit
    Benoit avatar
    17 posts
    Member since:
    Oct 2014

    Posted 18 Dec 2014 in reply to Boyan Boev Link to this post

    Hi Boyan,

    I will prepare a sample project.

    In the meantime, can I ask you something else ?
    Is there a way to retrieve resources ?

    something like:
    frameworkElement.GetProperty(new ArtOfTest.WebAii.Silverlight.AutomationProperty("Resources", typeof(????????)));
  6. Benoit
    Benoit avatar
    17 posts
    Member since:
    Oct 2014

    Posted 18 Dec 2014 in reply to Benoit Link to this post

    Ho Boyan,

    Please find attached a VS solution containing a small WPF application, and some UI Automation tests (in UiAutomationTest.cs):
    1. When_RetrieveBackgroundProperty: succeed
    2. When_RetrieveFillProperty: failed

    After further investigation the problem seems to be the VisualBrush (defined in Resources.xaml with key DisabledNetworkBrush)

    Thanks for your support
    Benoît

  7. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 23 Dec 2014 Link to this post

    Hi Benoit,

    Thank you for the sample.

    I see two problems here:

    1. You haven't set Fill property.

    2. You should get this property with this code: 

    var background = (ArtOfTest.WebAii.Controls.Xaml.Wpf.SolidColorBrush)networkOverlay.GetProperty(new AutomationProperty("Fill", typeof(ArtOfTest.WebAii.Controls.Xaml.Wpf.SolidColorBrush)));

    After I set the Brush Fill property the test was executed correctly.

    Let me know if this works on your side.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  8. Benoit
    Benoit avatar
    17 posts
    Member since:
    Oct 2014

    Posted 05 Jan 2015 in reply to Boyan Boev Link to this post

    Hi Boyan,

    The fill property is set using the style DisabledNetworkBrush:

        <VisualBrush x:Key="DisabledNetworkBrush"
                     TileMode="Tile"
                     Viewbox="0,5,10,5"
                     ViewboxUnits="Absolute"
                     Viewport="0,0,5,5"
                     ViewportUnits="Absolute">
            <VisualBrush.Visual>
                <Path Data="M 0 5 l 5 0" Stroke="Black" />
            </VisualBrush.Visual>
        </VisualBrush>

        <Style x:Key="NetworkOverlayStyle" TargetType="{x:Type Rectangle}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsDisabled}" Value="True">
                    <Setter Property="Fill" Value="{StaticResource DisabledNetworkBrush}" />
                    <Setter Property="Visibility" Value="Visible" />
                    <Setter Property="Opacity" Value="0.8" />
                </DataTrigger>
                <DataTrigger Binding="{Binding IsDisabled}" Value="False">
                    <Setter Property="Fill" Value="Transparent" />
                    <Setter Property="Visibility" Value="Collapsed" />
                    <Setter Property="Opacity" Value="0" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

    As you can see, there is a trigger to change the Fill property to the Transparent color or to a VisualBrush.
  9. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 08 Jan 2015 Link to this post

    Hi Benoit,

    I will consult this with our QA department whether it is a bug and will let you know.

    Thank you for your understanding.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  10. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 16 Jan 2015 Link to this post

    Hi Benoit,

    It seems that Test Studio cannot verify the style when it is set this way. We will look into this.

    If you set the style via property bar it is able to verify it. Unfortunately until the issue is debugged you should use this way.

    Thank you for your understanding.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
Back to Top