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

Coded UI: Get custom properties

2 Answers 223 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 25 May 2016, 09:14 AM

Hi, I was posting here as well because I can't manage to get custom properties of Telerik WPF controls in Coded UI tests. I am working with the latest version of UI for WPF.

According to the information given here, most of the controls have support for Coded UI tests on level 2 and 3. That would mean that it is possible to get the value of custom properties during a Coded UI test.

In order to do this, I installed the UITest extension dll according to the instructions. I am working with Visual Studio 2015, so I placed the dll into the "%CommonProgramFiles(x86)%\Microsoft Shared\VSTT\14.0\UITestExtensionPackages" folder and stored it into the GAC as well.

Now I am able to use Telerik UI control classes in my test. The test runs fine as long as I don't work with any custom properties. If I open the Coded UI test builder (which I normally don't use for writing tests), I can pull the crosshair over a Telerik control like a RadButton and the test builder will show me its custom properties with value (i.e. IsBackgroundVisible for RadButton).

However, if I try getting the same property from within my test, it fails with the exception:

"System.NotSupportedException: GetProperty of "IsBackgroundVisible" is not supported on control type: Button"

The MainWindow XAML code of an example application:

<Window x:Class="TelerikCustomPropertiesApp.MainWindow"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                Title="MainWindow" Height="350" Width="525"
                AutomationProperties.AutomationId="Window_Test">
    <Grid>
        <telerik:RadButton
                Width="120"
                Height="35"
                AutomationProperties.AutomationId="Button_Test"
                Content="Test" />
    </Grid>
</Window>

My test code:

ApplicationUnderTest.Launch(@"..\TelerikCustomPropertiesApp.exe");
WpfWindow mainWindow = new WpfWindow();
mainWindow.SearchProperties[WpfControl.PropertyNames.AutomationId] = "Window_Test";
mainWindow.Find();
WpfRadButton button = new WpfRadButton(mainWindow);
button.SearchProperties[WpfControl.PropertyNames.AutomationId] = "Button_Test";
button.DrawHighlight();
// from here the test fails
bool test = button.IsBackgroundVisible;

Having a look at this MSDN article, can it be that there is no implementation of GetPropertyNames() in the PropertyProvider of the UITest extension. Or there is a problem with identifying the control type. Am I missing something important in order to make this work?

2 Answers, 1 is accepted

Sort by
0
Accepted
Peshito
Telerik team
answered on 26 May 2016, 01:12 PM
Hello Daniel,

I was able to reproduce the issue you have. However the reason why you get this error is because the element is not properly identified. In order to do so, please use the "HelpText" search property to help you with the identification. This is required for the CodedUI level 2 and 3 support.

For instance this is a sample test method using your own code as a start point:
[TestMethod]
public void CodedUITestMethod2()
{
    this.UIMap.Start();
    this.UIMap.Checks();
    this.UIMap.HeightAsserts();
    WpfWindow mainWindow = new WpfWindow();
    mainWindow.SearchProperties[WpfControl.PropertyNames.Name] = "MainWindow";
 
    WpfRadButton button1 = new WpfRadButton(mainWindow);
    button1.SearchProperties["AutomationId"] = "Button_Test";
    button1.SearchProperties["HelpText"] = "RadButton";
 
    WpfRadButton button2 = new WpfRadButton(new UIMainWindowWindow());
    button2.SearchProperties["AutomationId"] = "Button_Test2";
    button2.SearchProperties["HelpText"] = "RadButton";
 
    double height1 = button1.ActualHeight;
    double height2 = button2.ActualHeight;
    //this.UIMap.ChecksCustom();
    this.UIMap.Close();
 
}
I tried with a test application having two buttons with different AutomationIDs, so in case you have more buttons you will easily be able to distinguish them.

Hope this helps.

Regards,
Peshito
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Daniel
Top achievements
Rank 1
answered on 26 May 2016, 02:19 PM
Thank you, this solves the problem. It seems that multiple search properties are required to correctly identify the control and use it.
 
I used ClassName instead of HelpText as additional property which works fine as well.
Tags
General Discussions
Asked by
Daniel
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or