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

WPF: Retrieve Style information

9 Answers 33 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lorenz
Top achievements
Rank 1
Lorenz asked on 05 Dec 2014, 12:46 PM
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

9 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 10 Dec 2014, 09:06 AM
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
 
0
Lorenz
Top achievements
Rank 1
answered on 15 Dec 2014, 10:03 AM
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
0
Boyan Boev
Telerik team
answered on 18 Dec 2014, 07:49 AM
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
 
0
Lorenz
Top achievements
Rank 1
answered on 18 Dec 2014, 02:03 PM
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(????????)));
0
Lorenz
Top achievements
Rank 1
answered on 18 Dec 2014, 03:59 PM
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

0
Boyan Boev
Telerik team
answered on 23 Dec 2014, 01:34 PM
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
 
0
Lorenz
Top achievements
Rank 1
answered on 05 Jan 2015, 02:10 PM
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.
0
Boyan Boev
Telerik team
answered on 08 Jan 2015, 09:44 AM
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
 
0
Boyan Boev
Telerik team
answered on 16 Jan 2015, 08:46 AM
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
 
Tags
General Discussions
Asked by
Lorenz
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Lorenz
Top achievements
Rank 1
Share this question
or