Skip to content

Commit 90b7bea

Browse files
authored
Merge pull request #561 from seleniumbase/translations-and-refactoring
Update Translations and some refactoring
2 parents 360412c + df80dc9 commit 90b7bea

File tree

16 files changed

+516
-72
lines changed

16 files changed

+516
-72
lines changed

examples/tour_examples/xkcd_tour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class MyTestClass(BaseCase):
66
def test_basic(self):
77
self.open('https://xkcd.com/1117/')
88
self.assert_element('img[alt="My Sky"]')
9-
self.create_shepherd_tour()
9+
self.create_tour(theme="dark")
1010
self.add_tour_step("Welcome to XKCD!")
1111
self.add_tour_step("This is the XKCD logo.", "#masthead img")
1212
self.add_tour_step("Here's the daily webcomic.", "#comic img")

help_docs/method_summary.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ For backwards compatibility, older versions of method names have remained to kee
77

88
```python
99
self.open(url)
10-
# Duplicates: self.open_url(url), self.get(url), self.visit(url)
10+
# Duplicates: self.open_url(url), self.get(url)
11+
# self.visit(url), self.goto(url), self.go_to(url)
1112

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

@@ -20,6 +21,7 @@ self.click_chain(selectors_list, by=By.CSS_SELECTOR, timeout=None, spacing=0)
2021
self.update_text(selector, new_value, by=By.CSS_SELECTOR, timeout=None, retry=False)
2122
# Duplicates: self.type(selector, text, by=By.CSS_SELECTOR, timeout=None, retry=False)
2223
# self.input(selector, text, by=By.CSS_SELECTOR, timeout=None, retry=False)
24+
# self.write(selector, text, by=By.CSS_SELECTOR, timeout=None, retry=False)
2325

2426
self.add_text(selector, text, by=By.CSS_SELECTOR, timeout=None)
2527
# Duplicates: self.send_keys(selector, text, by=By.CSS_SELECTOR, timeout=None)

requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ pytest-metadata==1.8.0
2323
pytest-ordering==0.6
2424
pytest-rerunfailures==8.0;python_version<"3.6"
2525
pytest-rerunfailures==9.0;python_version>="3.6"
26-
pytest-xdist==1.31.0
26+
pytest-xdist==1.32.0
2727
parameterized==0.7.4
2828
soupsieve==1.9.5;python_version<"3.5"
2929
soupsieve==2.0;python_version>="3.5"
3030
beautifulsoup4==4.9.0
31-
atomicwrites==1.3.0
3231
cryptography==2.9.2
3332
pyopenssl==19.1.0
3433
pygments==2.5.2;python_version<"3.5"
@@ -41,7 +40,6 @@ coverage==5.1
4140
pyotp==2.3.0
4241
boto==2.49.0
4342
cffi==1.14.0
44-
tqdm==4.45.0
4543
flake8==3.7.9
4644
pyflakes==2.1.1
4745
certifi>=2020.4.5.1

seleniumbase/utilities/selenium_ide/objectify.py renamed to seleniumbase/console_scripts/objectify.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,129 @@ def process_test_file(
670670
seleniumbase_lines.append(command)
671671
continue
672672

673+
# Handle self.input(SELECTOR, TEXT)
674+
if not object_dict:
675+
data = re.match(
676+
r'''^(\s*)self\.input'''
677+
r'''\((r?['"][\S\s]+['"]),\s?([\S\s]+)\)([\S\s]*)'''
678+
r'''$''', line)
679+
else:
680+
data = re.match(
681+
r'''^(\s*)self\.input'''
682+
r'''\(([\S\s]+),\s?([\S\s]+)\)([\S\s]*)'''
683+
r'''$''', line)
684+
if data:
685+
whitespace = data.group(1)
686+
selector = '%s' % data.group(2)
687+
selector = remove_extra_slashes(selector)
688+
page_selectors.append(selector)
689+
text = data.group(3)
690+
comments = data.group(4)
691+
command = '''%sself.input(%s, %s)%s''' % (
692+
whitespace, selector, text, comments)
693+
if selector_dict:
694+
if add_comments:
695+
comments = " # %s" % selector
696+
selector = optimize_selector(selector)
697+
if selector in selector_dict.keys():
698+
selector_object = selector_dict[selector]
699+
changed.append(selector_object.split('.')[0])
700+
command = '''%sself.input(%s, %s)%s''' % (
701+
whitespace, selector_object, text, comments)
702+
if object_dict:
703+
if not add_comments:
704+
comments = ""
705+
object_name = selector
706+
if object_name in object_dict.keys():
707+
selector_object = object_dict[object_name]
708+
changed.append(object_name.split('.')[0])
709+
command = '''%sself.input(%s, %s)%s''' % (
710+
whitespace, selector_object, text, comments)
711+
seleniumbase_lines.append(command)
712+
continue
713+
714+
# Handle self.write(SELECTOR, TEXT)
715+
if not object_dict:
716+
data = re.match(
717+
r'''^(\s*)self\.write'''
718+
r'''\((r?['"][\S\s]+['"]),\s?([\S\s]+)\)([\S\s]*)'''
719+
r'''$''', line)
720+
else:
721+
data = re.match(
722+
r'''^(\s*)self\.write'''
723+
r'''\(([\S\s]+),\s?([\S\s]+)\)([\S\s]*)'''
724+
r'''$''', line)
725+
if data:
726+
whitespace = data.group(1)
727+
selector = '%s' % data.group(2)
728+
selector = remove_extra_slashes(selector)
729+
page_selectors.append(selector)
730+
text = data.group(3)
731+
comments = data.group(4)
732+
command = '''%sself.write(%s, %s)%s''' % (
733+
whitespace, selector, text, comments)
734+
if selector_dict:
735+
if add_comments:
736+
comments = " # %s" % selector
737+
selector = optimize_selector(selector)
738+
if selector in selector_dict.keys():
739+
selector_object = selector_dict[selector]
740+
changed.append(selector_object.split('.')[0])
741+
command = '''%sself.write(%s, %s)%s''' % (
742+
whitespace, selector_object, text, comments)
743+
if object_dict:
744+
if not add_comments:
745+
comments = ""
746+
object_name = selector
747+
if object_name in object_dict.keys():
748+
selector_object = object_dict[object_name]
749+
changed.append(object_name.split('.')[0])
750+
command = '''%sself.write(%s, %s)%s''' % (
751+
whitespace, selector_object, text, comments)
752+
seleniumbase_lines.append(command)
753+
continue
754+
755+
# Handle self.add_text(SELECTOR, TEXT)
756+
if not object_dict:
757+
data = re.match(
758+
r'''^(\s*)self\.add_text'''
759+
r'''\((r?['"][\S\s]+['"]),\s?([\S\s]+)\)([\S\s]*)'''
760+
r'''$''', line)
761+
else:
762+
data = re.match(
763+
r'''^(\s*)self\.add_text'''
764+
r'''\(([\S\s]+),\s?([\S\s]+)\)([\S\s]*)'''
765+
r'''$''', line)
766+
if data:
767+
whitespace = data.group(1)
768+
selector = '%s' % data.group(2)
769+
selector = remove_extra_slashes(selector)
770+
page_selectors.append(selector)
771+
text = data.group(3)
772+
comments = data.group(4)
773+
command = '''%sself.add_text(%s, %s)%s''' % (
774+
whitespace, selector, text, comments)
775+
if selector_dict:
776+
if add_comments:
777+
comments = " # %s" % selector
778+
selector = optimize_selector(selector)
779+
if selector in selector_dict.keys():
780+
selector_object = selector_dict[selector]
781+
changed.append(selector_object.split('.')[0])
782+
command = '''%sself.add_text(%s, %s)%s''' % (
783+
whitespace, selector_object, text, comments)
784+
if object_dict:
785+
if not add_comments:
786+
comments = ""
787+
object_name = selector
788+
if object_name in object_dict.keys():
789+
selector_object = object_dict[object_name]
790+
changed.append(object_name.split('.')[0])
791+
command = '''%sself.add_text(%s, %s)%s''' % (
792+
whitespace, selector_object, text, comments)
793+
seleniumbase_lines.append(command)
794+
continue
795+
673796
# Handle self.send_keys(SELECTOR, TEXT)
674797
if not object_dict:
675798
data = re.match(

seleniumbase/console_scripts/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
from seleniumbase.common import obfuscate
2424
from seleniumbase.common import unobfuscate
2525
from seleniumbase.console_scripts import logo_helper
26+
from seleniumbase.console_scripts import objectify
2627
from seleniumbase.console_scripts import sb_mkdir
2728
from seleniumbase.console_scripts import sb_install
2829
from seleniumbase.utilities.selenium_grid import download_selenium_server
2930
from seleniumbase.utilities.selenium_grid import grid_hub
3031
from seleniumbase.utilities.selenium_grid import grid_node
3132
from seleniumbase.utilities.selenium_ide import convert_ide
32-
from seleniumbase.utilities.selenium_ide import objectify
3333

3434

3535
def show_usage():

seleniumbase/fixtures/base_case.py

Lines changed: 74 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,6 @@ def open(self, url):
105105
self.wait_for_ready_state_complete()
106106
self.__demo_mode_pause_if_active()
107107

108-
def open_url(self, url):
109-
""" Same as open() - Original saved for backwards compatibility. """
110-
self.open(url)
111-
112-
def get(self, url):
113-
""" Same as open() - WebDriver uses this method name. """
114-
self.open(url)
115-
116-
def visit(self, url):
117-
""" Same as open() - Some JS frameworks use this method name. """
118-
self.open(url)
119-
120108
def click(self, selector, by=By.CSS_SELECTOR, timeout=None, delay=0):
121109
if not timeout:
122110
timeout = settings.SMALL_TIMEOUT
@@ -257,30 +245,6 @@ def click_chain(self, selectors_list, by=By.CSS_SELECTOR,
257245
if spacing > 0:
258246
time.sleep(spacing)
259247

260-
def type(self, selector, text, by=By.CSS_SELECTOR,
261-
timeout=None, retry=False):
262-
""" The short version of update_text(), which clears existing text
263-
and adds new text into the text field.
264-
We want to keep the other version for backward compatibility. """
265-
if not timeout:
266-
timeout = settings.LARGE_TIMEOUT
267-
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
268-
timeout = self.__get_new_timeout(timeout)
269-
if page_utils.is_xpath_selector(selector):
270-
by = By.XPATH
271-
self.update_text(selector, text, by=by, timeout=timeout, retry=retry)
272-
273-
def input(self, selector, text, by=By.CSS_SELECTOR,
274-
timeout=None, retry=False):
275-
""" Same as update_text(). """
276-
if not timeout:
277-
timeout = settings.LARGE_TIMEOUT
278-
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
279-
timeout = self.__get_new_timeout(timeout)
280-
if page_utils.is_xpath_selector(selector):
281-
by = By.XPATH
282-
self.update_text(selector, text, by=by, timeout=timeout, retry=retry)
283-
284248
def update_text(self, selector, new_value, by=By.CSS_SELECTOR,
285249
timeout=None, retry=False):
286250
""" This method updates an element's text field with new text.
@@ -413,16 +377,6 @@ def add_text(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
413377
elif self.slow_mode:
414378
self.__slow_mode_pause_if_active()
415379

416-
def send_keys(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
417-
""" Same as add_text() """
418-
if not timeout:
419-
timeout = settings.LARGE_TIMEOUT
420-
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
421-
timeout = self.__get_new_timeout(timeout)
422-
if page_utils.is_xpath_selector(selector):
423-
by = By.XPATH
424-
self.add_text(selector, text, by=by, timeout=timeout)
425-
426380
def submit(self, selector, by=By.CSS_SELECTOR):
427381
""" Alternative to self.driver.find_element_by_*(SELECTOR).submit() """
428382
if page_utils.is_xpath_selector(selector):
@@ -2858,6 +2812,76 @@ def skip(self, reason=""):
28582812

28592813
############
28602814

2815+
# Duplicates (Avoids name confusion when migrating from other frameworks.)
2816+
2817+
def open_url(self, url):
2818+
""" Same as open() - Original saved for backwards compatibility. """
2819+
self.open(url)
2820+
2821+
def get(self, url):
2822+
""" Same as open() - WebDriver uses this method name. """
2823+
self.open(url)
2824+
2825+
def visit(self, url):
2826+
""" Same as open() - Some JS frameworks use this method name. """
2827+
self.open(url)
2828+
2829+
def goto(self, url):
2830+
""" Same as open() - Some JS frameworks use this method name. """
2831+
self.open(url)
2832+
2833+
def go_to(self, url):
2834+
""" Same as open() - Some test frameworks use this method name. """
2835+
self.open(url)
2836+
2837+
def type(self, selector, text, by=By.CSS_SELECTOR,
2838+
timeout=None, retry=False):
2839+
""" Same as update_text(). """
2840+
if not timeout:
2841+
timeout = settings.LARGE_TIMEOUT
2842+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
2843+
timeout = self.__get_new_timeout(timeout)
2844+
if page_utils.is_xpath_selector(selector):
2845+
by = By.XPATH
2846+
self.update_text(selector, text, by=by, timeout=timeout, retry=retry)
2847+
2848+
def input(self, selector, text, by=By.CSS_SELECTOR,
2849+
timeout=None, retry=False):
2850+
""" Same as update_text(). """
2851+
if not timeout:
2852+
timeout = settings.LARGE_TIMEOUT
2853+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
2854+
timeout = self.__get_new_timeout(timeout)
2855+
if page_utils.is_xpath_selector(selector):
2856+
by = By.XPATH
2857+
self.update_text(selector, text, by=by, timeout=timeout, retry=retry)
2858+
2859+
def write(self, selector, text, by=By.CSS_SELECTOR,
2860+
timeout=None, retry=False):
2861+
""" Same as update_text(). """
2862+
if not timeout:
2863+
timeout = settings.LARGE_TIMEOUT
2864+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
2865+
timeout = self.__get_new_timeout(timeout)
2866+
if page_utils.is_xpath_selector(selector):
2867+
by = By.XPATH
2868+
self.update_text(selector, text, by=by, timeout=timeout, retry=retry)
2869+
2870+
def send_keys(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
2871+
""" Same as add_text() """
2872+
if not timeout:
2873+
timeout = settings.LARGE_TIMEOUT
2874+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
2875+
timeout = self.__get_new_timeout(timeout)
2876+
if page_utils.is_xpath_selector(selector):
2877+
by = By.XPATH
2878+
self.add_text(selector, text, by=by, timeout=timeout)
2879+
2880+
def start_tour(self, name=None, interval=0):
2881+
self.play_tour(name=name, interval=interval)
2882+
2883+
############
2884+
28612885
def add_css_link(self, css_link):
28622886
js_utils.add_css_link(self.driver, css_link)
28632887

@@ -3288,15 +3312,17 @@ def play_tour(self, name=None, interval=0):
32883312
def export_tour(self, name=None, filename="my_tour.js", url=None):
32893313
""" Exports a tour as a JS file.
32903314
You can call self.export_tour() anywhere where you would
3291-
normally use self.play_tour() to play a tour.
3315+
normally use self.play_tour() to play a website tour.
32923316
It will include necessary resources as well, such as jQuery.
32933317
You'll be able to copy the tour directly into the Console of
32943318
any web browser to play the tour outside of SeleniumBase runs.
32953319
@Params
32963320
name - If creating multiple tours at the same time,
32973321
use this to select the tour you wish to add steps to.
32983322
filename - The name of the JavaScript file that you wish to
3299-
save the tour to. """
3323+
save the tour to.
3324+
url - The URL where the tour starts. If not specified, the URL
3325+
of the current page will be used. """
33003326
if not url:
33013327
url = self.get_current_url()
33023328
tour_helper.export_tour(

seleniumbase/translate/chinese.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,36 @@ def 按索引选择选项(self, *args, **kwargs):
235235
def 按值选择选项(self, *args, **kwargs):
236236
# select_option_by_value(dropdown_selector, option)
237237
return self.select_option_by_value(*args, **kwargs)
238+
239+
def 创建游览(self, *args, **kwargs):
240+
# create_tour(name=None, theme=None)
241+
return self.create_tour(*args, **kwargs)
242+
243+
def 创建SHEPHERD游览(self, *args, **kwargs):
244+
# create_shepherd_tour(name=None, theme=None)
245+
return self.create_shepherd_tour(*args, **kwargs)
246+
247+
def 创建BOOTSTRAP游览(self, *args, **kwargs):
248+
# create_bootstrap_tour(name=None, theme=None)
249+
return self.create_bootstrap_tour(*args, **kwargs)
250+
251+
def 创建HOPSCOTCH游览(self, *args, **kwargs):
252+
# create_hopscotch_tour(name=None, theme=None)
253+
return self.create_hopscotch_tour(*args, **kwargs)
254+
255+
def 创建INTROJS游览(self, *args, **kwargs):
256+
# create_introjs_tour(name=None, theme=None)
257+
return self.create_introjs_tour(*args, **kwargs)
258+
259+
def 添加游览步骤(self, *args, **kwargs):
260+
# add_tour_step(message, selector=None, name=None,
261+
# title=None, theme=None, alignment=None)
262+
return self.add_tour_step(*args, **kwargs)
263+
264+
def 播放游览(self, *args, **kwargs):
265+
# play_tour(name=None)
266+
return self.play_tour(*args, **kwargs)
267+
268+
def 导出游览(self, *args, **kwargs):
269+
# export_tour(name=None, filename="my_tour.js", url=None)
270+
return self.export_tour(*args, **kwargs)

0 commit comments

Comments
 (0)