AttributeRegEx with variable

Ranorex Spy, Recorder, and Studio.
swmatisa
Posts: 122
Joined: Fri Aug 05, 2011 7:52 am

AttributeRegEx with variable

Post by swmatisa » Fri Nov 14, 2014 7:30 am

Win7 SP1 64 bits
Ranorex 5.2.0

*********************************
Hello,
I cannot use a variable in a regex for validation with AttributeRegEx.
Regex1.jpg
Regex1.jpg (127.91 KiB) Viewed 1252 times
The result:
Regex2.jpg
Regex2.jpg (173.49 KiB) Viewed 1252 times
I have a workaround (topic 4), but it is harder for my real test

Any idea?

Regards
Attachments
TestRegex.zip
(20.14 KiB) Downloaded 75 times
SW

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3922
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: AttributeRegEx with variable

Post by odklizec » Fri Nov 14, 2014 9:24 am

Hi,

I may be wrong, but it seems it's not possible to combine the variable and regex in Recording validation, using the AttributeRegEx option? There are two workarounds, both require the use of User Code action.

First, convert your AttributeRegEx action to user code, right click the converted step and select View Code. this should move you to just converted code. Then simply change the new Regex("(?i:'+$Var2+')") to new Regex("(?i:"+Var2+")"). This should do the trick ;)

Another option is to add the regex directly to variable, via a User Code step placed before the validation step. Then just validate the variable.
Example of user code:

Code: Select all

        public void SetVar()        	
        {
        	Var2 = "(?i:"+Var2+")";
        }
Hope this helps?
Attachments
TestRegex.zip
(20.71 KiB) Downloaded 86 times
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

swmatisa
Posts: 122
Joined: Fri Aug 05, 2011 7:52 am

Re: AttributeRegEx with variable

Post by swmatisa » Tue Nov 18, 2014 7:42 am

Hello odklizec,

Thanks for your suggestions. As I write in my first post I also have another workaround with the Regex in the repository.

It is strange (not orthogonal) to have the possibility to use a variable and Regex in the repository and not with Validate (AttributeRegEx) :(
SW