Skip to content

Commit

Permalink
Merge pull request #580 from seleniumbase/more-translations
Browse files Browse the repository at this point in the history
Add/update translations. Make get() more flexible.
  • Loading branch information
mdmintz committed May 24, 2020
2 parents 0329f3a + e03a5e3 commit 7063374
Show file tree
Hide file tree
Showing 24 changed files with 867 additions and 151 deletions.
Binary file modified docs/img/sb_logo_7.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/boilerplates/base_test_case.py
Expand Up @@ -3,6 +3,7 @@
Define your customized library methods in a master class like this.
Then have all your test classes inherit it.
BaseTestCase will inherit SeleniumBase methods from BaseCase.
With Python 3, simplify "super(...)" to super().setUp() and super().tearDown()
'''

from seleniumbase import BaseCase
Expand Down
2 changes: 1 addition & 1 deletion examples/translations/dutch_test_1.py
Expand Up @@ -5,7 +5,7 @@
class MijnTestklasse(Testgeval):

def test_voorbeeld_1(self):
self.url_openen("https://nl.wikipedia.org/wiki/Hoofdpagina")
self.openen("https://nl.wikipedia.org/wiki/Hoofdpagina")
self.controleren_element('a[title*="hoofdpagina gaan"]')
self.controleren_tekst("Welkom op Wikipedia", "td.hp-welkom")
self.tekst_bijwerken("#searchInput", "Stroopwafel")
Expand Down
22 changes: 11 additions & 11 deletions examples/translations/french_test_1.py
Expand Up @@ -5,18 +5,18 @@
class MaClasseDeTest(CasDeBase):

def test_exemple_1(self):
self.ouvrir_url("https://fr.wikipedia.org/wiki/")
self.vérifier_le_texte("Wikipédia") # noqa
self.vérifier_un_élément('[title="Visiter la page d’accueil"]')
self.modifier_le_texte("#searchInput", "Crème brûlée")
self.ouvrir("https://fr.wikipedia.org/wiki/")
self.vérifier_texte("Wikipédia") # noqa
self.vérifier_élément('[title="Visiter la page d’accueil"]')
self.modifier_texte("#searchInput", "Crème brûlée")
self.cliquez_sur("#searchButton")
self.vérifier_le_texte("Crème brûlée", "#firstHeading")
self.vérifier_un_élément('img[alt*="Crème brûlée"]')
self.modifier_le_texte("#searchInput", "Jardin des Tuileries")
self.vérifier_texte("Crème brûlée", "#firstHeading")
self.vérifier_élément('img[alt*="Crème brûlée"]')
self.modifier_texte("#searchInput", "Jardin des Tuileries")
self.cliquez_sur("#searchButton")
self.vérifier_le_texte("Jardin des Tuileries", "#firstHeading")
self.vérifier_un_élément('img[alt*="Jardin des Tuileries"]')
self.vérifier_texte("Jardin des Tuileries", "#firstHeading")
self.vérifier_élément('img[alt*="Jardin des Tuileries"]')
self.retour()
self.vérifier_la_vérité("brûlée" in self.obtenir_url_actuelle())
self.vérifier_vrai("brûlée" in self.obtenir_url_actuelle())
self.en_avant()
self.vérifier_la_vérité("Jardin" in self.obtenir_url_actuelle())
self.vérifier_vrai("Jardin" in self.obtenir_url_actuelle())
16 changes: 8 additions & 8 deletions examples/translations/italian_test_1.py
Expand Up @@ -5,18 +5,18 @@
class MiaClasseDiTest(CasoDiProva):

def test_esempio_1(self):
self.apri_url("https://it.wikipedia.org/wiki/")
self.verificare_il_testo("Wikipedia")
self.apri("https://it.wikipedia.org/wiki/")
self.verificare_testo("Wikipedia")
self.verificare_elemento('[title="Lingua italiana"]')
self.aggiornare_il_testo("#searchInput", "Pizza")
self.aggiornare_testo("#searchInput", "Pizza")
self.fare_clic("#searchButton")
self.verificare_il_testo("Pizza", "#firstHeading")
self.verificare_testo("Pizza", "#firstHeading")
self.verificare_elemento('img[alt*="Pizza"]')
self.aggiornare_il_testo("#searchInput", "Colosseo")
self.aggiornare_testo("#searchInput", "Colosseo")
self.fare_clic("#searchButton")
self.verificare_il_testo("Colosseo", "#firstHeading")
self.verificare_testo("Colosseo", "#firstHeading")
self.verificare_elemento('img[alt*="Colosse"]')
self.indietro()
self.verificare_correttezza("Pizza" in self.ottenere_url_corrente())
self.verificare_vero("Pizza" in self.ottenere_url_corrente())
self.avanti()
self.verificare_correttezza("Colosseo" in self.ottenere_url_corrente())
self.verificare_vero("Colosseo" in self.ottenere_url_corrente())
2 changes: 1 addition & 1 deletion examples/translations/japanese_test_1.py
Expand Up @@ -5,7 +5,7 @@
class 私のテストクラス(セレニウムテストケース):

def test_例1(self):
self.URLを開く("https://ja.wikipedia.org/wiki/")
self.を開く("https://ja.wikipedia.org/wiki/")
self.テキストを確認する("ウィキペディア")
self.要素を確認する('[title="メインページに移動する"]')
self.テキストを更新("#searchInput", "アニメ")
Expand Down
2 changes: 1 addition & 1 deletion examples/translations/korean_test_1.py
Expand Up @@ -5,7 +5,7 @@
class 테스트_클래스(셀레늄_테스트_케이스):

def test_실시예_1(self):
self.URL_열기("https://ko.wikipedia.org/wiki/")
self.열기("https://ko.wikipedia.org/wiki/")
self.텍스트_확인("위키백과")
self.요소_확인('[title="위키백과:소개"]')
self.텍스트를_업데이트("#searchInput", "김치")
Expand Down
2 changes: 1 addition & 1 deletion examples/translations/portuguese_test_1.py
Expand Up @@ -5,7 +5,7 @@
class MinhaClasseDeTeste(CasoDeTeste):

def test_exemplo_1(self):
self.abrir_url("https://pt.wikipedia.org/wiki/")
self.abrir("https://pt.wikipedia.org/wiki/")
self.verificar_texto("Wikipédia")
self.verificar_elemento('[title="Língua portuguesa"]')
self.atualizar_texto("#searchInput", "João Pessoa")
Expand Down
2 changes: 1 addition & 1 deletion examples/translations/spanish_test_1.py
Expand Up @@ -5,7 +5,7 @@
class MiClaseDePrueba(CasoDePrueba):

def test_ejemplo_1(self):
self.abrir_url("https://es.wikipedia.org/wiki/")
self.abrir("https://es.wikipedia.org/wiki/")
self.verificar_texto("Wikipedia")
self.verificar_elemento('[title="Visitar la página principal"]')
self.actualizar_texto("#searchInput", "Parc d'Atraccions Tibidabo")
Expand Down
16 changes: 10 additions & 6 deletions help_docs/method_summary.md
Expand Up @@ -8,8 +8,12 @@ For backwards compatibility, older versions of method names have remained to kee

```python
self.open(url)
# Duplicates: self.open_url(url), self.get(url)
# self.visit(url), self.goto(url), self.go_to(url)
# Duplicates: self.open_url(url), self.visit(url), visit_url(url),
# self.goto(url), self.go_to(url)

self.get(url)
# If the url parameter is a URL: Perform self.open(url)
# Otherwise: return self.get_element(URL_AS_A_SELECTOR)

self.click(selector, by=By.CSS_SELECTOR, timeout=None, delay=0)

Expand All @@ -29,8 +33,8 @@ self.add_text(selector, text, by=By.CSS_SELECTOR, timeout=None)

self.submit(selector, by=By.CSS_SELECTOR)

self.refresh()
# Duplicates: self.refresh_page()
self.refresh_page()
# Duplicates: self.refresh(), self.reload(), self.reload_page()

self.get_current_url()

Expand Down Expand Up @@ -62,8 +66,8 @@ self.get_link_attribute(link_text, attribute, hard_fail=True)

self.get_partial_link_text_attribute(link_text, attribute, hard_fail=True)

self.click_link(link_text, timeout=None)
# Duplicates: self.click_link_text(link_text, timeout=None)
self.click_link_text(link_text, timeout=None)
# Duplicates: self.click_link(link_text, timeout=None)

self.click_partial_link_text(partial_link_text, timeout=None)

Expand Down
31 changes: 24 additions & 7 deletions help_docs/mobile_testing.md
@@ -1,15 +1,30 @@
[<img src="https://cdn2.hubspot.net/hubfs/100006/images/SeleniumBaseText_F.png" title="SeleniumBase" align="center" width="290">](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md)
<p align="center"><a href="https://github.com/seleniumbase/SeleniumBase/blob/master/README.md"><img src="https://cdn2.hubspot.net/hubfs/100006/images/SeleniumBaseText_F.png" alt="SeleniumBase" title="SeleniumBase" width="290" /></a></p>

<h2><img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Mobile Testing</h2>

Use ``--mobile`` to run your SeleniumBase tests using Chrome's (or Edge's) mobile device emulator with default values for device metrics (CSS Width, CSS Height, Pixel-Ratio) and user agent.
Use ``--mobile`` to run your SeleniumBase tests using Chromium's mobile device emulator with default values for device metrics (CSS Width, CSS Height, Pixel-Ratio) and user agent.

To configure the mobile device metrics, use:
```bash
--metrics="CSS_Width,CSS_Height,Pixel_Ratio"
```

To configure the user agent, use:
```bash
--agent="USER-AGENT-STRING"
```

To configure the mobile device metrics, use ``--metrics="CSS_Width,CSS_Height,Pixel_Ratio"``. To configure the user agent, use ``--agent="USER-AGENT-STRING"``.
To find real values for device metrics, see:
* [Device Metrics List](https://gist.github.com/sidferreira/3f5fad525e99b395d8bd882ee0fd9d00)

To find real values for device metrics, [see this GitHub Gist](https://gist.github.com/sidferreira/3f5fad525e99b395d8bd882ee0fd9d00). For a list of available user agent strings, [check out this page](https://developers.whatismybrowser.com/useragents/explore/).
For a list of available user agent strings, see:
* [User Agent Strings List](https://developers.whatismybrowser.com/useragents/explore/)

--------

Here's an example of running a mobile test (See https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_skype_site.py):
Here's an example of running a mobile test:

* [SeleniumBase/examples/test_skype_site.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_skype_site.py)

```bash
pytest test_skype_site.py --mobile
Expand All @@ -18,7 +33,7 @@ pytest test_skype_site.py --mobile

--------

Here's another example of running a mobile test (https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_swag_labs.py), which demonstrates using ``--metrics`` and ``--agent`` with ``--mobile``:
Here's another example of running a mobile test ([SeleniumBase/examples/test_swag_labs.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_swag_labs.py)), which demonstrates using ``--metrics`` and ``--agent`` with ``--mobile``:

```bash
# Run tests using Chrome's mobile device emulator (default settings)
Expand All @@ -34,4 +49,6 @@ pytest test_swag_labs.py --mobile --agent="Mozilla/5.0 (Linux; Android 9; Pixel

--------

If you're new to SeleniumBase, read https://github.com/seleniumbase/SeleniumBase to help you get started.
<p align="center"><div align="center"><a href="https://seleniumbase.io">
<img src="https://img.shields.io/badge/docs-%20📓📖📚-11BBDD.svg" alt="SeleniumBase.io Docs" />
</a> <a href="https://github.com/seleniumbase/SeleniumBase"><img src="https://img.shields.io/badge/✅%20💛%20View%20Code-on%20GitHub%20🌎%20🚀-02A79E.svg" alt="SeleniumBase.io Docs" /></a></div></p>
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -42,7 +42,7 @@ pyotp==2.3.0
boto==2.49.0
cffi==1.14.0
flake8==3.7.9;python_version<"3.5"
flake8==3.8.1;python_version>="3.5"
flake8==3.8.2;python_version>="3.5"
pyflakes==2.1.1;python_version<"3.5"
pyflakes==2.2.0;python_version>="3.5"
certifi>=2020.4.5.1
Expand Down
42 changes: 35 additions & 7 deletions seleniumbase/fixtures/base_case.py
Expand Up @@ -105,6 +105,18 @@ def open(self, url):
self.wait_for_ready_state_complete()
self.__demo_mode_pause_if_active()

def get(self, url):
""" If url looks like a page URL, opens the URL in the web browser.
Otherwise, returns self.get_element(URL_AS_A_SELECTOR)
Examples:
self.get("https://seleniumbase.io") # Navigates to the URL
self.get("input.class") # Finds and returns the WebElement
"""
if self.__looks_like_a_page_url(url):
self.open(url)
else:
return self.get_element(url) # url is treated like a selector

def click(self, selector, by=By.CSS_SELECTOR, timeout=None, delay=0):
if not timeout:
timeout = settings.SMALL_TIMEOUT
Expand Down Expand Up @@ -2860,22 +2872,30 @@ def open_url(self, url):
""" Same as open() - Original saved for backwards compatibility. """
self.open(url)

def get(self, url):
""" Same as open() - WebDriver uses this method name. """
def visit(self, url):
""" Same as open() - Some test frameworks use this method name. """
self.open(url)

def visit(self, url):
""" Same as open() - Some JS frameworks use this method name. """
def visit_url(self, url):
""" Same as open() - Some test frameworks use this method name. """
self.open(url)

def goto(self, url):
""" Same as open() - Some JS frameworks use this method name. """
""" Same as open() - Some test frameworks use this method name. """
self.open(url)

def go_to(self, url):
""" Same as open() - Some test frameworks use this method name. """
self.open(url)

def reload(self):
""" Same as refresh_page() """
self.refresh_page()

def reload_page(self):
""" Same as refresh_page() """
self.refresh_page()

def type(self, selector, text, by=By.CSS_SELECTOR,
timeout=None, retry=False):
""" Same as update_text(). """
Expand Down Expand Up @@ -3607,9 +3627,10 @@ def get_element(self, selector, by=By.CSS_SELECTOR, timeout=None):
""" Same as wait_for_element_present() - returns the element.
The element does not need be visible (it may be hidden). """
if not timeout:
timeout = settings.LARGE_TIMEOUT
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
timeout = settings.SMALL_TIMEOUT
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
timeout = self.__get_new_timeout(timeout)
selector, by = self.__recalculate_selector(selector, by)
return self.wait_for_element_present(selector, by=by, timeout=timeout)

def assert_element_present(self, selector, by=By.CSS_SELECTOR,
Expand Down Expand Up @@ -4517,6 +4538,13 @@ def __recalculate_selector(self, selector, by):
by = By.CSS_SELECTOR
return (selector, by)

def __looks_like_a_page_url(self, url):
if (url.startswith("http://") or url.startswith("https://") or (
url.startswith("://") or page_utils.is_valid_url(url))):
return True
else:
return False

def __make_css_match_first_element_only(self, selector):
# Only get the first match
return page_utils.make_css_match_first_element_only(selector)
Expand Down
28 changes: 24 additions & 4 deletions seleniumbase/translate/chinese.py
Expand Up @@ -5,10 +5,14 @@

class 硒测试用例(BaseCase): # noqa

def 开启网址(self, *args, **kwargs):
def 开启(self, *args, **kwargs):
# open(url)
return self.open(*args, **kwargs)

def 开启网址(self, *args, **kwargs):
# open_url(url)
return self.open_url(*args, **kwargs)

def 单击(self, *args, **kwargs):
# click(selector)
return self.click(*args, **kwargs)
Expand Down Expand Up @@ -73,6 +77,10 @@ def 断言标题(self, *args, **kwargs):
# assert_title(title)
return self.assert_title(*args, **kwargs)

def 获取标题(self, *args, **kwargs):
# get_title()
return self.get_title(*args, **kwargs)

def 断言为真(self, *args, **kwargs):
# assert_true(expr)
return self.assert_true(*args, **kwargs)
Expand Down Expand Up @@ -310,14 +318,18 @@ def 失败(self, *args, **kwargs):
# fail(msg=None) # Inherited from "unittest"
return self.fail(*args, **kwargs)

def 获取网址(self, *args, **kwargs):
def 获取(self, *args, **kwargs):
# get(url) # Same as open(url)
return self.get(*args, **kwargs)

def 访问网址(self, *args, **kwargs):
def 访问(self, *args, **kwargs):
# visit(url) # Same as open(url)
return self.visit(*args, **kwargs)

def 访问网址(self, *args, **kwargs):
# visit_url(url) # Same as open(url)
return self.visit_url(*args, **kwargs)

def 获取元素(self, *args, **kwargs):
# get_element(selector) # Element can be hidden
return self.get_element(*args, **kwargs)
Expand All @@ -326,6 +338,10 @@ def 查找元素(self, *args, **kwargs):
# find_element(selector) # Element must be visible
return self.find_element(*args, **kwargs)

def 查找文本(self, *args, **kwargs):
# find_text(text, selector="html") # Same as wait_for_text
return self.find_text(*args, **kwargs)

def 获取属性(self, *args, **kwargs):
# get_attribute(selector, attribute)
return self.get_attribute(*args, **kwargs)
Expand All @@ -340,12 +356,16 @@ def 设置所有属性(self, *args, **kwargs):

def 输入文字(self, *args, **kwargs):
# input(selector, new_value) # Same as update_text()
return self.type(*args, **kwargs)
return self.input(*args, **kwargs)

def 写文字(self, *args, **kwargs):
# write(selector, new_value) # Same as update_text()
return self.write(*args, **kwargs)

def 显示讯息(self, *args, **kwargs):
# post_message(message, duration=None, pause=True, style="info")
return self.post_message(*args, **kwargs)

def 打印(self, *args, **kwargs):
# _print(msg) # Same as Python print()
return self._print(*args, **kwargs)
Expand Down

0 comments on commit 7063374

Please sign in to comment.