REQUEST: XPath regex operator for escaping the string

Bug reports.
krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

REQUEST: XPath regex operator for escaping the string

Post by krstcs » Mon Aug 12, 2013 5:16 pm

When using variables in a regular expression in the XPath for a repository object, the variable is not being escaped.

My variable in this instance is a US phone number "(NNN) NNN-NNNN".

The XPath is "//select[#'phone']//option[@innertext~$phoneNumber]"

The XPath is seeing the parenthesis as a regular expression group, and, in this case, it should not.

There is no way to tell Ranorex to escape the variable, and I must use RegEx because the innertext actually might contain more than the phone number, but will ALWAYS contain AT LEAST the phone number, such as:

"Work - (NNN) NNN-NNNN"
and
"(NNN) NNN-NNNN"

The problem here is that I have other people working on the data sets for this test and I can't expect them to remember to escape the strings in the database.

It would be nice if there was another operator that tells the XPath to treat the sequence as an escaped literal.

EDIT TO ADD: How about "[email protected]" or "@~"? .NET uses "@" for explicit literal strings.
Shortcuts usually aren't...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: REQUEST: XPath regex operator for escaping the string

Post by Support Team » Fri Aug 16, 2013 5:03 pm

Hi,

In order to escape the value of the repository variable, you need to copy the variable to the module where the actions are located in using the specific repo item. After you copied it you need to escape the value of the variable as follows:
YourVariable = Regex.Escape(YourVariable);
Please let me know if this works for you!

Regards,
Markus
.
Image

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: REQUEST: XPath regex operator for escaping the string

Post by krstcs » Fri Aug 16, 2013 6:13 pm

Markus,

Thank you for the reply. I am very familiar with the .NET Regex library.

My request was for the addition of an XPath operator like "~" (such as "@~") that tells Ranorex to escape the given string as a literal, just like .NET uses "@".

I know I can do this in code using the Regex.Escape() function, for a given module, but what if I need to escape a variable in the repository? Your suggestion would require that I (or, more likely, someone else in my QA dept. who isn't a .NET coder) have to add the escape and more user code in every module that the object is used in.

If Ranorex had the capability to do this through an operator in the XPath it would mean I could do it ONCE in the REPO instead of having to remember it everywhere the repo object is used.


The other side to this is that the value doesn't need to be escaped every time it is used. I will use the same value as a text input in some cases, and then in a following case, search for that value (escaped) in the SUT. It would just be much easier if we could just tell XPath to use the variable as an escaped literal for Regex matches.


Thanks!!
Shortcuts usually aren't...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: REQUEST: XPath regex operator for escaping the string

Post by Support Team » Tue Aug 20, 2013 3:54 pm

Hi,

Thanks for the clarification!
I already forwarded this issue and we will discuss how such an feature can be implemented in the best way.

Regards,
Markus
.
Image