Skip to content

๐ŸŒ Translations

๐ŸŒ Translated Tests ๐Ÿˆบ

SeleniumBase supports the following 10 languages: English, Chinese, Dutch, French, Italian, Japanese, Korean, Portuguese, Russian, and Spanish. (Examples can be found in SeleniumBase/examples/translations)

Multi-language tests run with pytest like other tests. Test methods have a one-to-one mapping to supported languages. Here's an example of a translated test:

# Chinese Translation
from seleniumbase.translate.chinese import ็ก’ๆต‹่ฏ•็”จไพ‹

class ๆˆ‘็š„ๆต‹่ฏ•็ฑป(็ก’ๆต‹่ฏ•็”จไพ‹):
    def test_ไพ‹ๅญ1(self):
        self.ๅผ€ๅฏ("https://zh.wikipedia.org/wiki/")
        self.ๆ–ญ่จ€ๆ ‡้ข˜("็ปดๅŸบ็™พ็ง‘๏ผŒ่‡ช็”ฑ็š„็™พ็ง‘ๅ…จไนฆ")
        self.ๆ–ญ่จ€ๅ…ƒ็ด ('a[title="Wikipedia:ๅ…ณไบŽ"]')
        self.ๆ–ญ่จ€ๅ…ƒ็ด ('span:contains("ๅˆ›ๅปบ่ดฆๅท")')
        self.ๆ–ญ่จ€ๅ…ƒ็ด ('span:contains("็™ปๅฝ•")')
        self.ๆ–ญ่จ€ๆ–‡ๆœฌ("ๆ–ฐ้—ปๅŠจๆ€", "span#ๆ–ฐ้—ปๅŠจๆ€")
        self.่พ“ๅ…ฅๆ–‡ๆœฌ('input[name="search"]', "่ˆž้พ")
        self.ๅ•ๅ‡ป('button:contains("ๆœ็ดข")')
        self.ๆ–ญ่จ€ๆ–‡ๆœฌ("่ˆž้พ", "#firstHeading")
        self.ๆ–ญ่จ€ๅ…ƒ็ด ('img[src*="Chinese_draak.jpg"]')

Here's another example:

# Japanese Translation
from seleniumbase.translate.japanese import ใ‚ปใƒฌใƒ‹ใ‚ฆใƒ ใƒ†ใ‚นใƒˆใ‚ฑใƒผใ‚น

class ็งใฎใƒ†ใ‚นใƒˆใ‚ฏใƒฉใ‚น(ใ‚ปใƒฌใƒ‹ใ‚ฆใƒ ใƒ†ใ‚นใƒˆใ‚ฑใƒผใ‚น):
    def test_ไพ‹1(self):
        self.ใ‚’้–‹ใ("https://ja.wikipedia.org/wiki/")
        self.ใƒ†ใ‚ญใ‚นใƒˆใ‚’็ขบ่ชใ™ใ‚‹("ใ‚ฆใ‚ฃใ‚ญใƒšใƒ‡ใ‚ฃใ‚ข")
        self.่ฆ็ด ใ‚’็ขบ่ชใ™ใ‚‹('[title*="ใ‚ฆใ‚ฃใ‚ญใƒšใƒ‡ใ‚ฃใ‚ขใธใ‚ˆใ†ใ“ใ"]')
        self.JSๅ…ฅๅŠ›('input[name="search"]', "ใ‚ขใƒ‹ใƒก")
        self.ใ‚ฏใƒชใƒƒใ‚ฏใ—ใฆ("#searchform button")
        self.ใƒ†ใ‚ญใ‚นใƒˆใ‚’็ขบ่ชใ™ใ‚‹("ใ‚ขใƒ‹ใƒก", "#firstHeading")
        self.JSๅ…ฅๅŠ›('input[name="search"]', "ๅฏฟๅธ")
        self.ใ‚ฏใƒชใƒƒใ‚ฏใ—ใฆ("#searchform button")
        self.ใƒ†ใ‚ญใ‚นใƒˆใ‚’็ขบ่ชใ™ใ‚‹("ๅฏฟๅธ", "#firstHeading")
        self.่ฆ็ด ใ‚’็ขบ่ชใ™ใ‚‹('img[src*="Various_sushi"]')

Translation API ๐Ÿˆบ

You can use SeleniumBase to selectively translate the method names of any test from one language to another with the console scripts interface. Additionally, the import line at the top of the Python file will change to import the new BaseCase. Example: BaseCase becomes CasoDeTeste when a test is translated into Portuguese.

seleniumbase translate
* Usage:
seleniumbase translate [SB_FILE.py] [LANGUAGE] [ACTION]

* Languages:
``--en`` / ``--English``  |  ``--zh`` / ``--Chinese``
``--nl`` / ``--Dutch``    |  ``--fr`` / ``--French``
``--it`` / ``--Italian``  |  ``--ja`` / ``--Japanese``
``--ko`` / ``--Korean``   |  ``--pt`` / ``--Portuguese``
``--ru`` / ``--Russian``  |  ``--es`` / ``--Spanish``

* Actions:
``-p`` / ``--print``  (Print translation output to the screen)
``-o`` / ``--overwrite``  (Overwrite the file being translated)
``-c`` / ``--copy``  (Copy the translation to a new ``.py`` file)

* Options:
``-n``  (include line Numbers when using the Print action)

* Examples:
Translate test_1.py into Chinese and only print the output:
>>> seleniumbase translate test_1.py --zh  -p
Translate test_2.py into Portuguese and overwrite the file:
>>> seleniumbase translate test_2.py --pt  -o
Translate test_3.py into Dutch and make a copy of the file:
>>> seleniumbase translate test_3.py --nl  -c

* Output:
Translates a SeleniumBase Python file into the language
specified. Method calls and ``import`` lines get swapped.
Both a language and an action must be specified.
The ``-p`` action can be paired with one other action.
When running with ``-c`` (or ``--copy``) the new file name
will be the original name appended with an underscore
plus the 2-letter language code of the new language.
(Example: Translating ``test_1.py`` into Japanese with
``-c`` will create a new file called ``test_1_ja.py``.)