Page 1 of 1

AttributeRegEx with variable

Posted: Fri Nov 14, 2014 7:30 am
by swmatisa
Win7 SP1 64 bits
Ranorex 5.2.0

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

Any idea?

Regards

Re: AttributeRegEx with variable

Posted: Fri Nov 14, 2014 9:24 am
by odklizec
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?

Re: AttributeRegEx with variable

Posted: Tue Nov 18, 2014 7:42 am
by swmatisa
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) :(