locked
Unable to automate custom controls using Coded UI Test RRS feed

  • Question

  • Hi,

    I am trying to automate a WPF application which has one custom control (Button) added on top of calendar control using Coded UI tests. However, I am unable to find the control properties using Coded UI Test Builder. The control has automation ID too, but still I couldn't find any.

    Please let me know if we can really automate custom controls using Coded UI and what are the points to be noted before starting with the same.

    Thanks,

    Srikanth

    Thursday, November 24, 2016 11:24 AM

Answers

  • Hi Srikanth,

    Thanks for your posting.

    According to your description, it’s probably the custom control that caused this issue. I tested in my machine and found out that if customize a button without being set its name it would not show up the AutomationId value in coded UI test builder. So I suggest you look into XAML where the custom control locates and make sure its x: Name has a value.

    >> Please let me know if we can really automate custom controls using Coded UI and what are the points to be noted before starting with the same.

    About Coded UI for custom control, you could refer to the following MSDN document.

    https://msdn.microsoft.com/en-us/library/hh552522.aspx?f=255&MSPPError=-2147217396

    Hope it helpful for you.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by SrikEMP Wednesday, December 14, 2016 9:47 AM
    Friday, November 25, 2016 5:40 AM
  • Hi SrikEMP,

    Please try the following code to observe the results:

                WpfButton button = new WpfButton(your application);
    
                button.SearchProperties[WpfList.PropertyNames.AutomationId] = "ButtonToday";
    
                button.DrawHighlight();

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Oscar_Wu Saturday, November 26, 2016 3:21 AM
    • Marked as answer by SrikEMP Wednesday, December 14, 2016 9:47 AM
    Saturday, November 26, 2016 3:20 AM
  • Hi Srikanth,

    As I tested your code and still could find the AutomationId on my machine using Coded UI test builder. But the static resource referenced by content which you defined is not found in my side.

    So now I suggest you remove the content and give it a try.

    Also, I’d like to have a look at the static resource that you’ve referenced. Please post the details of the errors message to help us further troubleshot this issue.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by SrikEMP Wednesday, December 14, 2016 9:47 AM
    Monday, November 28, 2016 9:49 AM

All replies

  • Hi Srikanth,

    Thanks for your posting.

    According to your description, it’s probably the custom control that caused this issue. I tested in my machine and found out that if customize a button without being set its name it would not show up the AutomationId value in coded UI test builder. So I suggest you look into XAML where the custom control locates and make sure its x: Name has a value.

    >> Please let me know if we can really automate custom controls using Coded UI and what are the points to be noted before starting with the same.

    About Coded UI for custom control, you could refer to the following MSDN document.

    https://msdn.microsoft.com/en-us/library/hh552522.aspx?f=255&MSPPError=-2147217396

    Hope it helpful for you.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by SrikEMP Wednesday, December 14, 2016 9:47 AM
    Friday, November 25, 2016 5:40 AM
  • Here is the XAML which I already have.

    <Button x:Name="PART_ButtonToday" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="2" Click="PART_ButtonToday_OnClick"
                                                        HorizontalAlignment="Right" Margin="0,0,10,10" Width="87" Height="28"
                                                        AutomationProperties.AutomationId="ButtonToday"
                                                        Content="{x:Static res:Global.Today}" />

    Please let me know if I need to add any more .

    Thanks,

    Srikanth

    Friday, November 25, 2016 2:41 PM
  • Hi SrikEMP,

    Please try the following code to observe the results:

                WpfButton button = new WpfButton(your application);
    
                button.SearchProperties[WpfList.PropertyNames.AutomationId] = "ButtonToday";
    
                button.DrawHighlight();

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Oscar_Wu Saturday, November 26, 2016 3:21 AM
    • Marked as answer by SrikEMP Wednesday, December 14, 2016 9:47 AM
    Saturday, November 26, 2016 3:20 AM
  • Hi Srikanth,

    As I tested your code and still could find the AutomationId on my machine using Coded UI test builder. But the static resource referenced by content which you defined is not found in my side.

    So now I suggest you remove the content and give it a try.

    Also, I’d like to have a look at the static resource that you’ve referenced. Please post the details of the errors message to help us further troubleshot this issue.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by SrikEMP Wednesday, December 14, 2016 9:47 AM
    Monday, November 28, 2016 9:49 AM