Localization of Ranorex XPaths

Ranorex Spy, Recorder, and Studio.
twdoka
Posts: 2
Joined: Wed Sep 07, 2016 2:23 pm

Localization of Ranorex XPaths

Post by twdoka » Wed Sep 07, 2016 2:31 pm

Our application is available in German and English, other languages may follow. Given I have an XPath like

Code: Select all

/form/button[@text="Login"]
, is there a convenient way to have it translated?

I wonder whether there's a concept like .NET Resources where you can have a Resources.resx file and a Resources.de.resx file.

Of course I could use

Code: Select all

/form/button[@text="{0}"]
and then use a

Code: Select all

string.Format()
call, but that's absolutely inconvenient because the "Highlight element" feature gets broken.

I have tried:

a) looking at the properties of the .rxrep file, but it does not have a property that is related to my issue.
b) introducing a variable, which basically works. The XPath is then

Code: Select all

/form/button[@text=$Variable]
but I could not find a way of translating the variables.

Langrisser
Posts: 4
Joined: Tue Jun 21, 2016 1:53 pm
Location: Germany

Re: Localization of Ranorex XPaths

Post by Langrisser » Thu Sep 08, 2016 9:37 am

hello twdoka,

I encountered the same issue, long story short:

The repository item itself is not "smart enough" to change itself to your desired testing language.

Here some solutions I am trying myself at the moment:

1. using repository variable
Edit the xpath of your item like this

Code: Select all

/form/button[@text=$repoLoginLabel]
With this change you are able to assign different variables (e.g. different translations for login) to $repoLoginLabel. you can do this, using an data table, that contains the translations.

You can now create a usercode function to go through your data table, until you found the fitting translation.

(I am currently using this solution mainly, if needed )

2. reflection
Instead of @text attribute you can try to use another, more general variable of your current application code. you might have to change your production code to make this one work.

A very simple example from java:

Code: Select all

// global parameter that will later holds the label text of your button, like login
protected string aLabel;
The usercode class for your module can now find the "wanted" button via .getattributevaluetext("aLabel") function.

User avatar
Stub
Posts: 173
Joined: Fri Jul 15, 2016 1:35 pm

Re: Localization of Ranorex XPaths

Post by Stub » Thu Sep 08, 2016 9:51 am

I was also thinking of using the $variable trick in the XPath that you mention. I've been fiddling with something along these lines myself:

Code: Select all

.//treeitem[@text=$varCalendarName]
You could then execute some code at some point to prime these variables from a set of foreign resources:

Code: Select all

Repo.varCalendarName = some_value_from_resource_dll;
Where Repo is just a Property to the Repository instance in my Ranorex project.

But I'd also be curious to know how others tackle this problem and whether we're on the right lines here.

User avatar
Vega
Posts: 109
Joined: Mon Jul 11, 2016 2:15 pm

Re: Localization of Ranorex XPaths

Post by Vega » Fri Sep 09, 2016 5:49 pm

Sure you could use a variable and use data binding to achieve the desired result, but I would strongly recommend identifying objects with a unique identifier or a language independent attribute.

Example:

Code: Select all

/form[@title='Untitled - Notepad' or @class='Notepad']
The above Ranorex path will find the Notepad window based on title first (In English of course) or will go off of the class name which should not be dependent on language. I would use the path editor within Ranorex Spy and see which attributes would be best to use.

Another way you could approach the variable route would be:

Code: Select all

/form/button[@text=$Variable_EN or @text=$Variable_GR]
I hope this helps!

twdoka
Posts: 2
Joined: Wed Sep 07, 2016 2:23 pm

Re: Localization of Ranorex XPaths

Post by twdoka » Mon Sep 19, 2016 8:35 am

I'm not sure whether I really like the "or" approach:
  • with many languages, the XPath becomes longer and longer and thus unmaintainable. I'd like to write as clean code as I expect it from our developers
  • it will find buttons that have not been translated, because it matches the English default text then

User avatar
Vega
Posts: 109
Joined: Mon Jul 11, 2016 2:15 pm

Re: Localization of Ranorex XPaths

Post by Vega » Tue Sep 20, 2016 3:54 pm

I agree the OR approach is probably not the best, just wanted to provide you with some options. Would it be a problem that it recognized buttons that have not been translated?

Maybe I'm not sure what the goal of your testing is... Is it to verify the language of controls or test the functionality of the application?

If you are doing functional testing:

As suggested in my previous post I highly recommend using a language independent attribute for your RanorexPath. This way your RanorexPaths are short and very robust/work across all languages.

If you are verifying the translated language for each control, you will likely end up with a very bulky repository / RanorexPath.