'How do I know which resource bundle (more over, which language) I'm using? (Java)
So, I want to write some tests in selenium. At one point I get a message from a dialog and I want to know if the used text in the dialog is the right one. So I want to check it out in my resource bundle and set the strings both equal. The problem I got is, that the text from the dialog is english and the one from my bundle is german, because that's the default language from my bundle. I know I can just change the local, but someone else might has a different language setting, when they want to run my tests, so they need to adjust the code. But that is not the solution I want.
So my question is: How do I know which language my (I guess) browser is using, so I can get the right value from my bundle?
Heres the I code I use to get the value from my resource bundle.
/**
* Returns a value from the resource bundle. If the bundle doesn't contain the key, the method will fail.
*
* @param key The key.
* @return The value to the key.
*/
protected String getValueFromResourceBundle(final String key) {
final ResourceBundle bundle = ResourceBundle.getBundle("base_example_name", Locale.getDefault());
if (!bundle.containsKey(key)) {
fail(String.format("The following key could not be found: %s", key));
}
return bundle.getString(key);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
