How to have language-independent UI tests with SWTBot and NLS

aurelien.pupier's picture
aurelien.pupier
Blog Categories: 

To make sure you have UI tests that will evolve seamlessly with UI naming modification, use the Internationalized String and not the hardcoded value of text displayed in the UI. Even if hardcoding seems simpler at test writing time!

Here's how you can implement it with SWTBot and NLS.

Each plugin needs to export the package containing the NLS class to use it in the test plugin. To avoid polluting the completion of your IDE, and making some classes visible at runtime that you don't want, follow these three points:

  • Isolate your NLS class
  • Use x-friends directive
  • Use Internationalized String

Let’s explain these points!

Isolate your NLS class

Isolate the class responsible for translation in a specific package. At Bonitasoft, we call this package i18n.

Isolated Messages class

It will export only classes which are related to translation.

Use x-friends directive

Open the MANIFEST.MF with the PDE editor. Then export the i18n package and specify the Package Visibility to your test plugin:

Package Visibility Reduced to specific plugins

If you look at the textual content of MANIFEST.MF, you will notice that an x-friends directive has been added:

x-friends directive in MANIFEST.MF

Use Internationalized String

Finally, in your test code write something like:

import org.bonitasoft.actors.i18n.Messages;


bot.button(Messages.addActor).click();

This good practice will improve the robustness of your test and save a lot of time.

Notifications