locked
Regular expression in coded ui beyond .contains RRS feed

  • Question

  • Hi All,

    Its understood that apart from .contains there is no way in UI control maps for regexp.

    Is there any other way to use the regular expression, to identity a control like from standard .net APIs?  can any one provide an example?

    like the one mentioned in the following blog,

    http://blogs.msdn.com/b/anutthara/archive/2009/08/19/using-regular-expressions-to-locate-controls-in-coded-ui-test.aspx

    where it is mentioned like 

    "However, you can write code to find the set of labels that are under a given hierarchy and match each of their inner text properties against a regular expression of your choice using the standard .NET APIs"

    Thank You!

    Wednesday, December 12, 2012 11:50 AM

Answers

  • Your can use the various SearchProperties and FilterProperties and then call FindMatchingControls to get a collection (ie a list) of controls that might match. You can then use your own regular expression to filter out the controls of interest.

    UITestControlCollection controls = xxx.FindMatchingControls();
    foreach ( UITestControl con in controls ) {
        if ( ... con ... regular expression ... ) {
            // Process con...
        }
    }

    Regards

    Adrian

    • Marked as answer by deepakguna Thursday, December 13, 2012 10:16 AM
    Wednesday, December 12, 2012 12:47 PM

All replies

  • Your can use the various SearchProperties and FilterProperties and then call FindMatchingControls to get a collection (ie a list) of controls that might match. You can then use your own regular expression to filter out the controls of interest.

    UITestControlCollection controls = xxx.FindMatchingControls();
    foreach ( UITestControl con in controls ) {
        if ( ... con ... regular expression ... ) {
            // Process con...
        }
    }

    Regards

    Adrian

    • Marked as answer by deepakguna Thursday, December 13, 2012 10:16 AM
    Wednesday, December 12, 2012 12:47 PM
  • Thank Adrian’s friendly help.

    Hello Deepparkguna,

    Thank you for your post.

    I think that Adrian’s suggestion is useful and you can try it.

    In addition, I do a research and I don’t find some articles about support for Regular Expression.

    And you can see the following thread:

    http://social.msdn.microsoft.com/Forums/en-US/vsautotest/thread/3a55986d-f75f-4c31-864d-49fa81762943

    As Gautam said, we don't have full support for Regex but do have Contains operator and you can try to use the Contains operator.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 13, 2012 4:32 AM
    Moderator
  • Thank you Adrian!

    Thursday, December 13, 2012 10:17 AM