Skip to main content

Test different browser locales in Chrome with Desired Capabilities in Katalon Studio

Chrome sets a default UI language with the first Chrome window that opens. In other words, if you alter browser locales, for example, with command line argument chrome.exe--lang=de to start Chrome in German, the Chrome driver still defines the default language from the Chrome browser.

To test different browser locales, you can instead configure Desired Capabilities. You can learn about this here: Desired Capabilities

Use Configured Desired Capability with Test Case Variables

In this section, we show you two possible approaches to alter browser locales while testing:

  • To test one specific language with a test case.
  • To test different languages with a test suite.
Note:

Create a test case to test one language

In the following example, we configure a test case with a specific browser locale, like French.

Do as follows:

  1. Create a New Test Case. Go to File > New > Test Case.

  2. Create Test Case Variables. See also: Test Case Variables.

    • Switch to the Variables tab of your Test Case.
    • Click Add. A new row appears in the variable list.
    • Input the "locale" variable like so:
    NameTypeDefault Value
    localeString"fr"
    • In our example, the Default Value is fr, the language code for French. You can find other language codes for Chrome here: language code.

      test case with variables

  3. After defining Test Case Variables, we override default language settings in Chrome by using Configured Desired Capabilities. You can learn more about this here: Configured Desired Capabilities

    • Switch to the Script tab of your Test Case.
    • Copy and paste the below code into your test script. With this code, you can manipulate the locales of the testing browsers.

      import com.kms.katalon.core.configuration.RunConfiguration

      Map prefs = [('intl.accept_languages') : locale]
      // Map preferences key to manipulate page's language.

      RunConfiguration.setWebDriverPreferencesProperty("prefs", prefs)
    • Continue writing the script or use Web Spy/Record Utility to complete your test case.

      Note:
      • In case you wish to alter browser locales with an existing test script, copy and paste the above sample code before the test script.

      Final results after configuring Desired Capabilities

    • Your Test Case is now ready to run with Chrome in French.

Important:
  • Make sure to configure all your test cases with Desired Capabilities as per Part 1.
Note:
  • Desired Capabilities can be reused across projects. You can refer to this document: Reuse Desired Capabilities for further details.

In the following example, we demonstrate how to create a Test Suite with Test case variables to test different browser locales. Here, we use French, English, and Spanish.

  1. Create a test suite. Go to File > New > Test Suite.
  2. Click Add in the command toolbar, then choose pre-configured test cases.

    New Test Suite

  3. Create a data file. Go to File > New > Test Data. Choose Data Type as Internal Data.

    You use this data file to input different language codes you want to test on browsers. For our example, we input fr,en,es.

    New Data file 2

    New Data file

  4. Manage Data Binding

    • Return to your test suite, click Show Data Binding to expand the Data Binding section. Make sure you click on the correct pre-configured test case beforehand.

      This step binds the New Data File from Step 3 with the Test Suite you want to run. See also Manage Data Binding.

      Show Data Binding section

    • The final results should show as below:

      Test Suite data

Use Custom Profiles in Desired Capabilities

You can also test different browser locales with a Remote Server. In this case, you can set Custom Desired Capabilities to alter the default language in Chrome.

Note:
Important:
  • Make sure that you are running Selenium Grid Hub & Node while executing the test.
  • Make sure to update the browser by clicking Tools > Update WebDrivers > Choose browser.

The following example shows you how to create a custom profile with Spanish as the testing language. Do as follows:

  1. Create a new custom profile in Desired Capabilities. Go to Project > Settings > Desired Capabilities > Custom.

    Project Settings dialog

  2. In the command toolbar, click Add to add a custom profile. In the newly added property line, change the name to spanish for better recognition, then click on More (...) under the Value column. A Custom Execution Configuration Builder dialog opens.

    Set value for custom Desired Capabilities

  3. In the Custom Execution Configuration Builder dialog, specify the Driver Name as Remote, then click on More (...) under the Preferences column. A Driver Builder dialog opens.

    Set value for custom Desired Capabilities

    Fill in the Driver Builder dialog as shown below:
    • Remote Server URL: http://localhost:port/wd/hub - the URL to the Remote server.
    • Remote Server Type: Choose Selenium.
    • Click Add on the command toolbar, then input the following values:

      Table 1
      NameTypeValue
      browserNamestringchrome
      goog:chromeOptions(*)Dictionary(**)Click More (...). In the pop-up Dictionary Property Builder dialog, click Add, then input values from Table 2.

      (*) goog:chromeOptions: Support passing the ChromeOptions object into the ChromeDriver constructor.

      (**) Dictionary: the data type permits you to input a collection of keys and values. You can learn more about this here: Data types.

      Table 2
      NameTypeValue
      prefsDictionaryClick More (...). In the pop-up Dictionary Property Builder dialog, click Add, then input values from Table 3.
      Table 3
      NameTypeValue
      intl.accept_languages(*)Stringes(**)

      (*) intl.accept_languages: Support passing preference key to manipulate a page's language.

      (**) es: the language code for Spanish.

      Set value for custom Desired Capabilities

      Note:
      • The capabilities properties are case-sensitive.
  4. Click OK to save the settings in each table. The above commands should result in the following:

    Results after setting up custom language Remote Control dialog

    Final Results