How to design test cases for multi-language UI

Hi there,

what would be a good way to create keywords/testcases that need to run against a website that can be in several languages?

E.g. to write a keyword “Klick Login Button”, where the button label can be either “Log In” or “Anmelden”. What would be a smart way to make it working with both UI languages?

Hi @detlefs ,

I think, the language only plays a role, if you use the text of the button as locator strategy. If use, for example, the ID and xpath as locator, you should be fine:

    Click     xpath://*[@id='login']

So you usually should not have any difficulties with the language.

Furthermore, since locators are hard to interpret, you could extract them in a configuration file:

    'URL': 'http://my-application/index.html',
    'USER': 'service-robot',
    'PASSWORD': '123456,
        'MAIN_MENU' : 'xpath://*[@id="navigationTree"]',
        'LOGIN_SCREEEN' : {
            'INPUT_NAME' : 'xpath://*[@id="loginName"]',
            'INPUT_PASSWORD' : 'xpath://*[@id="password"]',
            'BUTTON_ANMELDEN' : 'xpath://*[@id="anmeldenButton"]'

When starting the test case, you pass the configuration file with --variablefile on to robot:
robot --variablefile my_testcase.robot

In you test case, you then reference your page object elements:

*** Variables ***

*** Test Cases ***
Test Login
    Open  Browser    ${WEBAPPLICATION}[URL]

If you have any difficulties with the UI language after all, maybe you can adopt the pageobject-pattern in your favor, for instance replacing IDs with localization keys.

Best regards,

1 Like

Hi Detlef,

Markus’ solution above it what I would recommend for most applications, there are exceptions, I have seen applications where all the id fields were dynamically generated and changed depending on on how you navigated to the screen and were different if you returned to the same screen in the same session so could not be relied on.

In this case, still use the structure Markus suggested, but replace PAGE_OBJECT_ELEMENT with PO_ (i.e. PO_EN, PO_DE, PO_ES, etc) the structure under PAGE_OBJECT_ELEMENT would remain the same and the field names the same, just the xpath’s would be replaced with the words used in each language.

If you can do it with xpath’s that will be less maintenance for you so is still better, but this gives you another option.


Hi guys,

thanks for your ideas. I like the configuration file approach with xpath. This kind of file could probably be auto-generated from source code quite easily

1 Like

RF has native YAML import. I use it to store locators

    # Username input
    username_field: css:[placeholder="Username"]
    # Password input
    password_field: css:[placeholder="Password"]
    # Submit button
    submit_button: css:[name="submit-button"]

then use this variable file

Variables                       Locators/website.yaml
Click Element      ${login_form.submit_button}

1 Like

Keep in mind, that you need to install pyyaml for RF yaml support:

pip install pyyaml

Otherwise robot will tell you that pyyaml is missing right on start :wink:

Oh, i’ve forgot to mention nice feature of YAML - anchors.
Here a blog post about daemonl