Forum Discussion

JDR2500's avatar
JDR2500
Frequent Contributor
17 days ago
Solved

Regular expressions in name mapping property values

Hi,
It seems I am too clueless to utilize a regular expression in a name mapping value. Obviously, I don't have much experience with regular expressions.

What I want is the mapping to match either of two integer values for an ID (e.g. "123" or "456").  I presume I should be entering something in the Value field seen below.  What should it be?

Again, what I'm going for is "23691" or "26710".

Thanks in advance,
John

    • JDR2500's avatar
      JDR2500
      Frequent Contributor

      This sounds very promising.  I'll give it a try.  Thanks!

  • scot1967's avatar
    scot1967
    Regular Contributor

    I use this site a lot to test and learn with.  https://regex101.com/

    \b(23691|26710)\b

    This will match one or the other.  

    I don't think you can use a regular expression in a  name map value however.

    There are scripting options that will accept regular expressions or string matches using contains.

    Otherwise you may be forced to map both values and then search for one and fail over to the other with an if block in your test.  This will get cumbersome if you need to repeat it regularly in other code.

    • JDR2500's avatar
      JDR2500
      Frequent Contributor

      Thanks for the suggestions.  I'll give them a try.  I have used regular expressions in name mapping properties at least once before successfully.  In that case it was a string property and I wanted to exclude a specific string.  The expression I used was "[^CWndPickColor]".  That worked like a champ. 

      Maybe it's not possible with integer properties?

      I'll play around with it a little more and see what I can figure out.  

  • Hassan_Ballan's avatar
    Hassan_Ballan
    Regular Contributor

    In NameMapping you could use wildcard https://support.smartbear.com/testcomplete/docs/reference/misc/using-wildcards.html for String, it can be * or 2???? rather than 23691 or 26710, but since it is an ControlID and in your case you are using Integer I am not sure your recognition will still work properly as you need something unique. Give it a try.

    Another alternative is to pass the value during run as a project variable, you will also need to use https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/refreshmappinginfo-method.html 

    • JDR2500's avatar
      JDR2500
      Frequent Contributor

      Thanks for the feedback.  The wildcard option won't work in this case because it's too broad.  There are other ControlIds in that range that I need to exclude.

      Passing the value as a variable is a good idea.  I'll look into that option.