๐ 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.ๅฆๆๅฏ่ง่ฏทๅๅป('button[aria-label="ๅ
ณ้ญ"]')
self.ๅฆๆๅฏ่ง่ฏทๅๅป('button[aria-label="้้"]')
self.ๆญ่จๅ
็ด ('span:contains("ๅๅปบ่ดฆๅท")')
self.ๆญ่จๅ
็ด ('span:contains("็ปๅฝ")')
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``.)