Skip to content

Add the "seleniumbase print [FILE]" command with syntax-highlighting #594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
livereload==2.6.2;python_version>="3.6"
mkdocs==1.1.2
mkdocs-material==5.2.3
mkdocs-simple-hooks==0.1.1
Expand Down
8 changes: 6 additions & 2 deletions examples/my_first_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_basic(self):
# * Types in the new text
# * Hits Enter/Submit (if the text ends in "\n")
#
# self.update_text(S, T) can also be written as self.type(S, T)
# self.update_text(S, T) can also be written as self.input(S, T)
#
# 4. There's usually more than one way to do the same thing. Ex:
# [
Expand Down Expand Up @@ -95,6 +95,10 @@ def test_basic(self):
# the element does not appear on the page within the timeout limit.
# And self.assert_element() does this too (without returning it).
#
# 7. For the full method list, see one of the following:
# 7. If a URL starts with "://", then "https://" is automatically used.
# Example: [self.open("://URL")] becomes [self.open("https://URL")]
# This helps by reducing the line length by 5 characters.
#
# 8. For the full method list, see one of the following:
# * SeleniumBase/seleniumbase/fixtures/base_case.py
# * SeleniumBase/help_docs/method_summary.md
3 changes: 3 additions & 0 deletions examples/translations/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ seleniumbase translate [SB_FILE].py [LANGUAGE] [ACTION]
``-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
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ requests==2.23.0
selenium==3.141.0
pluggy==0.13.1
attrs>=19.3.0
pytest==4.6.10;python_version<"3.5"
pytest==4.6.11;python_version<"3.5"
pytest==5.4.3;python_version>="3.5"
pytest-cov==2.9.0
pytest-forked==1.1.3
Expand All @@ -41,11 +41,11 @@ coverage==5.1
pyotp==2.3.0
boto==2.49.0
cffi==1.14.0
rich==1.3.1;python_version>="3.6" and python_version<"4.0"
rich==2.0.0;python_version>="3.6" and python_version<"4.0"
flake8==3.7.9;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
certifi>=2020.4.5.2
pdfminer.six==20191110;python_version<"3.5"
pdfminer.six==20200517;python_version>="3.5"
3 changes: 3 additions & 0 deletions seleniumbase/console_scripts/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ See: http://www.katalon.com/automation-recorder
``-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)

* Output:
Translates a SeleniumBase Python file into the language
specified. Method calls and "import" lines get swapped.
Expand Down
39 changes: 39 additions & 0 deletions seleniumbase/console_scripts/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
sbase install chromedriver
sbase mkdir browser_tests
sbase convert my_old_webdriver_unittest.py
sbase print my_first_test.py -n
sbase translate my_first_test.py --zh -p
sbase extract-objects my_first_test.py
sbase inject-objects my_first_test.py
Expand Down Expand Up @@ -67,6 +68,7 @@ def show_basic_usage():
sc += (" install [DRIVER_NAME] [OPTIONS]\n")
sc += (" mkdir [NEW_TEST_DIRECTORY_NAME]\n")
sc += (" convert [PYTHON_WEBDRIVER_UNITTEST_FILE]\n")
sc += (" print [FILE] [OPTIONS]\n")
sc += (" translate [SB_PYTHON_FILE] [LANGUAGE] [ACTION]\n")
sc += (" extract-objects [SB_PYTHON_FILE]\n")
sc += (" inject-objects [SB_PYTHON_FILE] [OPTIONS]\n")
Expand Down Expand Up @@ -149,6 +151,20 @@ def show_convert_usage():
print("")


def show_print_usage():
print(" ** print **")
print(" Usage:")
print(" seleniumbase print [FILE] [OPTIONS]")
print(" OR: sbase print [FILE] [OPTIONS]")
print(" Options:")
print(" -n (Add line Numbers to the rows)")
print(" -w (Use word-Wrap for long lines)")
print(" Output:")
print(" Prints the code/text of any file")
print(" with syntax-highlighting.")
print("")


def show_translate_usage():
print(" ** translate **")
print(" Usage:")
Expand All @@ -164,6 +180,8 @@ def show_translate_usage():
print(" -p / --print (Print translation output to the screen)")
print(" -o / --overwrite (Overwrite the file being translated)")
print(" -c / --copy (Copy the translation to a new .py file)")
print(" Options:")
print(" -n (include line Numbers when using the Print action)")
print(" Output:")
print(" Translates a SeleniumBase Python file into the language")
print(' specified. Method calls and "import" lines get swapped.')
Expand Down Expand Up @@ -342,6 +360,7 @@ def show_detailed_help():
show_install_usage()
show_mkdir_usage()
show_convert_usage()
show_print_usage()
show_translate_usage()
show_extract_objects_usage()
show_inject_objects_usage()
Expand Down Expand Up @@ -390,6 +409,22 @@ def main():
else:
show_basic_usage()
show_convert_usage()
elif command == "print":
if len(command_args) >= 1:
if sys.version_info[0] == 2:
colorama.init(autoreset=True)
c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
cr = colorama.Style.RESET_ALL
msg = '"sbase print" does NOT support Python 2! '
msg += 'Try using the Unix "cat" command instead!'
message = "\n" + c5 + msg + cr + "\n"
print("")
raise Exception(message)
from seleniumbase.console_scripts import sb_print
sb_print.main()
else:
show_basic_usage()
show_print_usage()
elif command == "translate":
if len(command_args) >= 1:
if sys.version_info[0] == 2:
Expand Down Expand Up @@ -478,6 +513,10 @@ def main():
print("")
show_convert_usage()
return
elif command_args[0] == "print":
print("")
show_print_usage()
return
elif command_args[0] == "translate":
print("")
show_translate_usage()
Expand Down
Loading