Im currently working on a platform that has multi-language options and also the language is defined by IP. So Im trying to build an architecture for testing both scenarios dynamically... The domain is always the same: Example: www.page.com (If you are logged in from Britain the web application is loaded in English, if you are visiting the page from France the page is loaded in French.)

I have an idea to make different abstract classes with error messages for example:

public class ErrorMessagesEN {

   public static final String MANDATORY_FIELD = "This field is mandatory...";
   public static final String SOME_OTHER_ERROR_MSG = "Some error message on english"

// etc.....


public class ErrorMessagesFR {

    public static final String MANDATORY_FIELD = "Error message in French"
    public static final String SOME_OTHER_ERROR_MSG = "Some error message on 

// etc.....

In the test method i provide parameter "EN" or "FR" for example:

homepage.signIn(String location)

So is there any option to make for example:

if (location=="EN") {
   // load the ErrorMessageEN
   // etc......

The keys for the Strings are the same but the classes are different, so how can I provide different imports of the classes by the location parameter for example? Or are there any better approaches for this situation? Any links or ideas?


PS. If you need more info to help me please ask! :)


Try avoid this conditional (if locations == "EN"), using dependency injection, on the code that is concerned with the application test itself.

You can:

  • Create a module to deal with the data;

  • Create an Interface to abstract the capabilities of this module (e.g. called Messages);

  • Have class for each language you want:

    public class final ErrorMessagesFR implements Messages

    public class final ErrorMessagesEN implements Messages

  • Choose the concrete object to be injected based on, for instance, command line arguments or environmental variables.

Then on the application test code, you can use like this:

public class HomePage {
   public HomePage(Message messages){ this.messages = messages; }


   public void signIn() { ... message.MANDATORY_FIELD...  }

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.