Selenium Java best practices for handling different languages and locations, and setting dynamic architecture?

Hi everyone!

I m currently working on a platform that has multi-language options and also the language is defined by IP. So I m 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 French"
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?

Thanks!

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

3 Likes

If it was me I wouldn’t be splitting the error messages into different classes.

I would keep them in one class and pass in the locale value as a parameter in the class constructor. You can then have some logic in the class itself that sets the correct error messages based on that value. That would help keep logic out the tests and conform to the idea of “Tell, don’t ask”.

So in the test an assertion that used the error message would look something like this:
assertTrue(new ErrorMessages("EN").MANDTORY_FIELD);

2 Likes