Skip to content

Commit 0abcaf1

Browse files
authored
Merge pull request #594 from seleniumbase/sb-print
Add the "seleniumbase print [FILE]" command with syntax-highlighting
2 parents bbfc354 + d955cee commit 0abcaf1

File tree

9 files changed

+429
-23
lines changed

9 files changed

+429
-23
lines changed

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
livereload==2.6.2;python_version>="3.6"
12
mkdocs==1.1.2
23
mkdocs-material==5.2.3
34
mkdocs-simple-hooks==0.1.1

examples/my_first_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_basic(self):
5757
# * Types in the new text
5858
# * Hits Enter/Submit (if the text ends in "\n")
5959
#
60-
# self.update_text(S, T) can also be written as self.type(S, T)
60+
# self.update_text(S, T) can also be written as self.input(S, T)
6161
#
6262
# 4. There's usually more than one way to do the same thing. Ex:
6363
# [
@@ -95,6 +95,10 @@ def test_basic(self):
9595
# the element does not appear on the page within the timeout limit.
9696
# And self.assert_element() does this too (without returning it).
9797
#
98-
# 7. For the full method list, see one of the following:
98+
# 7. If a URL starts with "://", then "https://" is automatically used.
99+
# Example: [self.open("://URL")] becomes [self.open("https://URL")]
100+
# This helps by reducing the line length by 5 characters.
101+
#
102+
# 8. For the full method list, see one of the following:
99103
# * SeleniumBase/seleniumbase/fixtures/base_case.py
100104
# * SeleniumBase/help_docs/method_summary.md

examples/translations/ReadMe.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ seleniumbase translate [SB_FILE].py [LANGUAGE] [ACTION]
5151
``-o`` / ``--overwrite`` (Overwrite the file being translated)
5252
``-c`` / ``--copy`` (Copy the translation to a new ``.py`` file)
5353
54+
* Options:
55+
``-n`` (include line Numbers when using the Print action)
56+
5457
* Examples:
5558
Translate test_1.py into Chinese and only print the output:
5659
>>> seleniumbase translate test_1.py --zh -p

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ requests==2.23.0
1414
selenium==3.141.0
1515
pluggy==0.13.1
1616
attrs>=19.3.0
17-
pytest==4.6.10;python_version<"3.5"
17+
pytest==4.6.11;python_version<"3.5"
1818
pytest==5.4.3;python_version>="3.5"
1919
pytest-cov==2.9.0
2020
pytest-forked==1.1.3
@@ -41,11 +41,11 @@ coverage==5.1
4141
pyotp==2.3.0
4242
boto==2.49.0
4343
cffi==1.14.0
44-
rich==1.3.1;python_version>="3.6" and python_version<"4.0"
44+
rich==2.0.0;python_version>="3.6" and python_version<"4.0"
4545
flake8==3.7.9;python_version<"3.5"
4646
flake8==3.8.2;python_version>="3.5"
4747
pyflakes==2.1.1;python_version<"3.5"
4848
pyflakes==2.2.0;python_version>="3.5"
49-
certifi>=2020.4.5.1
49+
certifi>=2020.4.5.2
5050
pdfminer.six==20191110;python_version<"3.5"
5151
pdfminer.six==20200517;python_version>="3.5"

seleniumbase/console_scripts/ReadMe.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ See: http://www.katalon.com/automation-recorder
7171
``-o`` / ``--overwrite`` (Overwrite the file being translated)
7272
``-c`` / ``--copy`` (Copy the translation to a new ``.py`` file)
7373

74+
* Options:
75+
``-n`` (include line Numbers when using the Print action)
76+
7477
* Output:
7578
Translates a SeleniumBase Python file into the language
7679
specified. Method calls and "import" lines get swapped.

seleniumbase/console_scripts/run.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
sbase install chromedriver
1010
sbase mkdir browser_tests
1111
sbase convert my_old_webdriver_unittest.py
12+
sbase print my_first_test.py -n
1213
sbase translate my_first_test.py --zh -p
1314
sbase extract-objects my_first_test.py
1415
sbase inject-objects my_first_test.py
@@ -67,6 +68,7 @@ def show_basic_usage():
6768
sc += (" install [DRIVER_NAME] [OPTIONS]\n")
6869
sc += (" mkdir [NEW_TEST_DIRECTORY_NAME]\n")
6970
sc += (" convert [PYTHON_WEBDRIVER_UNITTEST_FILE]\n")
71+
sc += (" print [FILE] [OPTIONS]\n")
7072
sc += (" translate [SB_PYTHON_FILE] [LANGUAGE] [ACTION]\n")
7173
sc += (" extract-objects [SB_PYTHON_FILE]\n")
7274
sc += (" inject-objects [SB_PYTHON_FILE] [OPTIONS]\n")
@@ -149,6 +151,20 @@ def show_convert_usage():
149151
print("")
150152

151153

154+
def show_print_usage():
155+
print(" ** print **")
156+
print(" Usage:")
157+
print(" seleniumbase print [FILE] [OPTIONS]")
158+
print(" OR: sbase print [FILE] [OPTIONS]")
159+
print(" Options:")
160+
print(" -n (Add line Numbers to the rows)")
161+
print(" -w (Use word-Wrap for long lines)")
162+
print(" Output:")
163+
print(" Prints the code/text of any file")
164+
print(" with syntax-highlighting.")
165+
print("")
166+
167+
152168
def show_translate_usage():
153169
print(" ** translate **")
154170
print(" Usage:")
@@ -164,6 +180,8 @@ def show_translate_usage():
164180
print(" -p / --print (Print translation output to the screen)")
165181
print(" -o / --overwrite (Overwrite the file being translated)")
166182
print(" -c / --copy (Copy the translation to a new .py file)")
183+
print(" Options:")
184+
print(" -n (include line Numbers when using the Print action)")
167185
print(" Output:")
168186
print(" Translates a SeleniumBase Python file into the language")
169187
print(' specified. Method calls and "import" lines get swapped.')
@@ -342,6 +360,7 @@ def show_detailed_help():
342360
show_install_usage()
343361
show_mkdir_usage()
344362
show_convert_usage()
363+
show_print_usage()
345364
show_translate_usage()
346365
show_extract_objects_usage()
347366
show_inject_objects_usage()
@@ -390,6 +409,22 @@ def main():
390409
else:
391410
show_basic_usage()
392411
show_convert_usage()
412+
elif command == "print":
413+
if len(command_args) >= 1:
414+
if sys.version_info[0] == 2:
415+
colorama.init(autoreset=True)
416+
c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
417+
cr = colorama.Style.RESET_ALL
418+
msg = '"sbase print" does NOT support Python 2! '
419+
msg += 'Try using the Unix "cat" command instead!'
420+
message = "\n" + c5 + msg + cr + "\n"
421+
print("")
422+
raise Exception(message)
423+
from seleniumbase.console_scripts import sb_print
424+
sb_print.main()
425+
else:
426+
show_basic_usage()
427+
show_print_usage()
393428
elif command == "translate":
394429
if len(command_args) >= 1:
395430
if sys.version_info[0] == 2:
@@ -478,6 +513,10 @@ def main():
478513
print("")
479514
show_convert_usage()
480515
return
516+
elif command_args[0] == "print":
517+
print("")
518+
show_print_usage()
519+
return
481520
elif command_args[0] == "translate":
482521
print("")
483522
show_translate_usage()

0 commit comments

Comments
 (0)