AttributeRegEx with variable

Ranorex Studio, Spy, Recorder, and Driver.
swmatisa
Posts: 123
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
The result:
Regex2.jpg
I have a workaround (topic 4), but it is harder for my real test

Any idea?

Regards
You do not have the required permissions to view the files attached to this post.
SW

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
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?
You do not have the required permissions to view the files attached to this post.
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: 123
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