# How to design test cases for multi-language UI

**URL:** <https://forum.robotframework.org/t/how-to-design-test-cases-for-multi-language-ui/1339>\
**Category:** Robot Framework\
**Created:** [16 February 2021 15:04 UTC](https://forum.robotframework.org/t/how-to-design-test-cases-for-multi-language-ui/1339 "2021-02-16T15:04:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![detlefs](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/detlefs/32/612_2.png) [@detlefs](https://forum.robotframework.org/u/detlefs)\
**Post date:** [16 February 2021 15:04 UTC](https://forum.robotframework.org/t/how-to-design-test-cases-for-multi-language-ui/1339/1 "2021-02-16T15:04:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Noordsestern](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/noordsestern/32/4270_2.png) [@Noordsestern](https://forum.robotframework.org/u/Noordsestern)\
**Post date:** [17 February 2021 19:17 UTC](https://forum.robotframework.org/t/how-to-design-test-cases-for-multi-language-ui/1339/2 "2021-02-17T19:17:28Z")

</div>

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:

```python
    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:

```python
WEBAPPLICATION= {
    'URL': 'http://my-application/index.html',
    'USER': 'service-robot',
    'PASSWORD': '123456,
    'PAGE_OBJECT_ELEMENT' : {
        '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 page_object_elements.py my_testcase.robot`

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

```python
***Variables***
${PO_LOGIN_SCREEN} ${WEBAPPLICATION}[PAGE_OBJECT_ELEMENT][LOGIN_SCREEEN]

***Test Cases***
Test Login
    Open Browser ${WEBAPPLICATION}[URL]
    Input Text ${PO_LOGIN_SCREEN}[INPUT_NAME] ${WEBAPPLICATION}[USER]
    Input Password ${PO_LOGIN_SCREEN}[INPUT_PASSWORD] ${WEBAPPLICATION}[PASSWORD]
    Click ${PO_LOGIN_SCREEN}[BUTTON_ANMELDEN]    

```

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,  
Markus

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [17 February 2021 21:57 UTC](https://forum.robotframework.org/t/how-to-design-test-cases-for-multi-language-ui/1339/3 "2021-02-17T21:57:09Z")

</div>

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.

Dave.

---

<div class="post-metadata">

**Author:** ![detlefs](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/detlefs/32/612_2.png) [@detlefs](https://forum.robotframework.org/u/detlefs)\
**Post date:** [18 February 2021 14:00 UTC](https://forum.robotframework.org/t/how-to-design-test-cases-for-multi-language-ui/1339/4 "2021-02-18T14:00:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![leorush](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/leorush/32/84_2.png) [@leorush](https://forum.robotframework.org/u/leorush)\
**Post date:** [22 February 2021 07:26 UTC](https://forum.robotframework.org/t/how-to-design-test-cases-for-multi-language-ui/1339/5 "2021-02-22T07:26:37Z")

</div>

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

```
login_form:
    # 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

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

```

---

<div class="post-metadata">

**Author:** ![Noordsestern](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/noordsestern/32/4270_2.png) [@Noordsestern](https://forum.robotframework.org/u/Noordsestern)\
**Post date:** [22 February 2021 10:17 UTC](https://forum.robotframework.org/t/how-to-design-test-cases-for-multi-language-ui/1339/6 "2021-02-22T10:17:26Z")

</div>

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 😉

---

<div class="post-metadata">

**Author:** ![leorush](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/leorush/32/84_2.png) [@leorush](https://forum.robotframework.org/u/leorush)\
**Post date:** [22 February 2021 14:51 UTC](https://forum.robotframework.org/t/how-to-design-test-cases-for-multi-language-ui/1339/7 "2021-02-22T14:51:47Z")

</div>

Oh, i’ve forgot to mention nice feature of YAML - anchors.  
Here a blog post about [daemonl](https://blog.daemonl.com/2016/02/yaml.html)
