4

Our application is available in German and English, other languages may follow. Given I have an XPath like /form/button[@text="Login"], is there a convenient way to have it translated?

At the moment I'm trying with SAP GUI like this:

Screenshot

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 /form/button[@text="{0}"] and then use a string.Format() call, but that's absolutely inconvenient because the "Highlight element" feature gets broken.

I have tried:

  • looking at the properties of the .rxrep file, but it does not have a property that is related to my issue.
  • introducing a variable, which basically works. The XPath is then /form/button[@text=$Variable] but I could not find a way of translating the variables.
  • Can you please share your screenshot of your elements Html code. Which you want to translate? – Shailendra Rathore Sep 7 '16 at 7:05
  • @ShailendraRathore: added a Screenshot. It's not HTML, it's SAP – Thomas Weller Sep 7 '16 at 7:09
  • Although this is a very valid question I think if you want it answered quickly I would also ask it at the Ranorex forums: ranorex.com/forum/automation-tools-f16.html or ask Ranorex support which should be included in your license. – Niels van Reijmersdal Sep 7 '16 at 12:03
  • @NielsvanReijmersdal: Thanks for the link to the forum. I don't have a license yet. I'm still in the evaluation phase. – Thomas Weller Sep 7 '16 at 13:03
  • 1
    Even more reason for support to assist you, possible leads should always have high priority, maybe they can suggest a solution another direction in the hope you will license the software. – Niels van Reijmersdal Sep 7 '16 at 13:06
2

Sure there is you can use xpath wih logical OR and have all transaltions inside the XPath expression.

For example you can use

/form/button[@text="Login" or @text="Eingeben" or  @text="შესვლის"]

3rd is Georgian :c). Risk of choosing different functionality due to translation, is very low.

Update: using the contains(A,B) can move it to higher level. Usually contains is used as

/form/button[contains(@text,"Login")]

but can be used oppositely

/form/button[contains("Login | Eingeben | შესვლის",@text)]

where you are free to choose the delimiter. It would work even with comas, simple spaces, or whatever you like

"Login , Eingeben , შესვლის"
"Login # Eingeben # შესვლის"

and then it could be just copypasted from csv or generated to a text array.

#end of update

But I recommend to glue your tests to other parameters than texts if available. This will be then translation independent. Application under development can change texts rapidly.

If design of the application is already fixed, you can use simple numbers, as

/form/button[3]

is a 3rd button in the form. This is not possible to use when application is still under development.

  • Doing it with OR has the disadvantage that I cannot find out which texts I already have translated and which I don't. I have to go through all XPaths and check. If it were in a different file like RESX, it's immediately clear which ones are missing. – Thomas Weller Sep 8 '16 at 8:51
  • Another disadvantage of the OR approach is that you cannot enforce the condition that the very same language is matched in each label's translation. Might become an issue with languages that are similar. – Richard Kiefer Nov 18 '16 at 9:57
  • @OR, true, but in reality I'm giving parameters like translation to data sources, usually XML or JSON and testing is then datadriven. – Dee Nov 18 '16 at 12:53
1

Using text values to identify elements is not good practice for this very reason. (And because the text may be changed later in the development life cycle of your product)

The best way to solve this is to get your developers to assign a unique identifier to the control. The exact property to set will depend on platform/UI library. On Windows you might use the AutomationId or tag property, on Android it would be rId.

Assuming a change was made to your unit under test to add a proper identifier, your new XPath might look something like:

/form/text[@tag='signInText']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.