Skip to content

New console scripts for manipulating page objects #286

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 4 commits into from
Feb 26, 2019
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
200 changes: 155 additions & 45 deletions seleniumbase/console_scripts/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from seleniumbase.utilities.selenium_grid import grid_hub
from seleniumbase.utilities.selenium_grid import grid_node
from seleniumbase.utilities.selenium_ide import convert_ide
from seleniumbase.utilities.selenium_ide import objectify


def show_usage():
Expand All @@ -39,6 +40,10 @@ def show_basic_usage():
print(" install [DRIVER_NAME]")
print(" mkdir [NEW_TEST_DIRECTORY_NAME]")
print(" convert [PYTHON_WEBDRIVER_UNITTEST_FILE]")
print(" extract-objects [SELENIUMBASE_PYTHON_FILE]")
print(" inject-objects [SELENIUMBASE_PYTHON_FILE] [OPTIONS]")
print(" objectify [SELENIUMBASE_PYTHON_FILE] [OPTIONS]")
print(" revert-objects [SELENIUMBASE_PYTHON_FILE]")
print(" download [ITEM]")
print(" grid-hub [start|stop|restart] [OPTIONS]")
print(" grid-node [start|stop|restart] --hub=[HUB_IP] [OPTIONS]")
Expand All @@ -50,96 +55,157 @@ def show_install_usage():
print(" ** install **")
print("")
print(" Usage:")
print(" seleniumbase install [DRIVER_NAME]")
print(" (Drivers: chromedriver, geckodriver, edgedriver")
print(" iedriver, operadriver)")
print(" seleniumbase install [DRIVER_NAME]")
print(" (Drivers: chromedriver, geckodriver, edgedriver")
print(" iedriver, operadriver)")
print(" Example:")
print(" seleniumbase install chromedriver")
print(" seleniumbase install chromedriver")
print(" Output:")
print(" Installs the specified webdriver.")
print(" (chromedriver is required for Chrome automation)")
print(" (geckodriver is required for Firefox automation)")
print(" (edgedriver is required for Microsoft Edge automation)")
print(" (iedriver is required for InternetExplorer automation)")
print(" (operadriver is required for Opera Browser automation)")
print(" Installs the specified webdriver.")
print(" (chromedriver is required for Chrome automation)")
print(" (geckodriver is required for Firefox automation)")
print(" (edgedriver is required for Microsoft Edge automation)")
print(" (iedriver is required for InternetExplorer automation)")
print(" (operadriver is required for Opera Browser automation)")
print("")


def show_mkdir_usage():
print(" ** mkdir **")
print("")
print(" Usage:")
print(" seleniumbase mkdir [DIRECTORY_NAME]")
print(" seleniumbase mkdir [DIRECTORY_NAME]")
print(" Example:")
print(" seleniumbase mkdir browser_tests")
print(" seleniumbase mkdir browser_tests")
print(" Output:")
print(" Creates a new folder for running SeleniumBase scripts.")
print(" The new folder contains default config files,")
print(" sample tests for helping new users get started, and")
print(" Python boilerplates for setting up customized")
print(" test frameworks.")
print(" Creates a new folder for running SeleniumBase scripts.")
print(" The new folder contains default config files,")
print(" sample tests for helping new users get started, and")
print(" Python boilerplates for setting up customized")
print(" test frameworks.")
print("")


def show_convert_usage():
print(" ** convert **")
print("")
print(" Usage:")
print(" seleniumbase convert [PYTHON_WEBDRIVER_UNITTEST_FILE]")
print(" seleniumbase convert [PYTHON_WEBDRIVER_UNITTEST_FILE]")
print(" Output:")
print(" Converts a Selenium IDE exported WebDriver unittest")
print(" file into a SeleniumBase file. Adds _SB to the new")
print(" file name while keeping the original file intact.")
print(" Works with Katalon Recorder scripts.")
print(" See: http://www.katalon.com/automation-recorder")
print(" Converts a Selenium IDE exported WebDriver unittest")
print(" file into a SeleniumBase file. Adds _SB to the new")
print(" file name while keeping the original file intact.")
print(" Works with Katalon Recorder scripts.")
print(" See: http://www.katalon.com/automation-recorder")
print("")


def show_extract_objects_usage():
print(" ** extract-objects **")
print("")
print(" Usage:")
print(" seleniumbase extract-objects [SELENIUMBASE_PYTHON_FILE]")
print(" Output:")
print(" Creates page objects based on selectors found in a")
print(" seleniumbase Python file and saves those objects to the")
print(' "page_objects.py" file in the same folder as the tests.')
print("")


def show_inject_objects_usage():
print(" ** inject-objects **")
print("")
print(" Usage:")
print(" seleniumbase inject-objects [SELENIUMBASE_PYTHON_FILE]")
print(" Options:")
print(" -c, --comments (Add object selectors to the comments.)")
print(" (Default: No added comments.)")
print(" Output:")
print(' Takes the page objects found in the "page_objects.py"')
print(' file and uses those to replace matching selectors in')
print(' the selected seleniumbase Python file.')
print("")


def show_objectify_usage():
print(" ** objectify **")
print("")
print(" Usage:")
print(" seleniumbase objectify [SELENIUMBASE_PYTHON_FILE]")
print(" Options:")
print(" -c, --comments (Add object selectors to the comments.)")
print(" (Default: No added comments.)")
print(" Output:")
print(' A modified version of the file where the selectors')
print(' have been replaced with variable names defined in')
print(' "page_objects.py", supporting the Page Object Pattern.')
print("")
print(' (seleniumbase "objectify" has the same outcome as')
print(' combining "extract-objects" with "inject-objects")')
print("")


def show_revert_objects_usage():
print(" ** revert-objects **")
print("")
print(" Usage:")
print(" seleniumbase revert-objects [SELENIUMBASE_PYTHON_FILE]")
print(" Options:")
print(" -c, --comments (Keep existing comments for the lines.)")
print(" (Default: No comments are kept.)")
print(" Output:")
print(' Reverts the changes made by "seleniumbase objectify" or')
print(' "seleniumbase inject-objects" when run against a')
print(' seleniumbase Python file. Objects will get replaced by')
print(' selectors stored in the "page_objects.py" file.')
print("")


def show_download_usage():
print(" ** download **")
print("")
print(" Usage:")
print(" seleniumbase download [ITEM]")
print(" seleniumbase download [ITEM]")
print(" (Choices: server)")
print(" Example:")
print(" seleniumbase download server")
print(" seleniumbase download server")
print(" Output:")
print(" Downloads the specified item.")
print(" (server is required for using your own Selenium Grid)")
print(" Downloads the specified item.")
print(" (server is required for using your own Selenium Grid)")
print("")


def show_grid_hub_usage():
print(" ** grid-hub **")
print("")
print(" Usage:")
print(" seleniumbase grid-hub {start|stop|restart}")
print(" seleniumbase grid-hub {start|stop|restart}")
print(" Options:")
print(" -v, --verbose (Increase verbosity of logging output.)")
print(" (Default: Quiet logging / not verbose.)")
print(" -v, --verbose (Increase verbosity of logging output.)")
print(" (Default: Quiet logging / not verbose.)")
print(" Output:")
print(" Controls the Selenium Grid Hub Server, which allows")
print(" for running tests on multiple machines in parallel")
print(" to speed up test runs and reduce the total time")
print(" of test suite execution.")
print(" You can start, restart, or stop the Grid Hub server.")
print(" Controls the Selenium Grid Hub Server, which allows")
print(" for running tests on multiple machines in parallel")
print(" to speed up test runs and reduce the total time")
print(" of test suite execution.")
print(" You can start, restart, or stop the Grid Hub server.")
print("")


def show_grid_node_usage():
print(" ** grid-node **")
print("")
print(" Usage:")
print(" seleniumbase grid-node {start|stop|restart} [OPTIONS]")
print(" seleniumbase grid-node {start|stop|restart} [OPTIONS]")
print(" Options:")
print(" --hub=HUB_IP (The Grid Hub IP Address to connect to.)")
print(" (Default: 127.0.0.1 if not set)")
print(" -v, --verbose (Increase verbosity of logging output.)")
print(" (Default: Quiet logging / not verbose.)")
print(" --hub=HUB_IP (The Grid Hub IP Address to connect to.)")
print(" (Default: 127.0.0.1 if not set)")
print(" -v, --verbose (Increase verbosity of logging output.)")
print(" (Default: Quiet logging / not verbose.)")
print(" Output:")
print(" Controls the Selenium Grid node, which serves as a")
print(" worker machine for your Selenium Grid Hub server.")
print(" You can start, restart, or stop the Grid node.")
print(" Controls the Selenium Grid node, which serves as a")
print(" worker machine for your Selenium Grid Hub server.")
print(" You can start, restart, or stop the Grid node.")
print("")


Expand All @@ -150,6 +216,10 @@ def show_detailed_help():
show_install_usage()
show_mkdir_usage()
show_convert_usage()
show_extract_objects_usage()
show_inject_objects_usage()
show_objectify_usage()
show_revert_objects_usage()
show_download_usage()
show_grid_hub_usage()
show_grid_node_usage()
Expand Down Expand Up @@ -182,6 +252,30 @@ def main():
else:
show_basic_usage()
show_convert_usage()
elif command == "extract-objects" or command == "extract_objects":
if len(command_args) >= 1:
objectify.extract_objects()
else:
show_basic_usage()
show_extract_objects_usage()
elif command == "inject-objects" or command == "inject_objects":
if len(command_args) >= 1:
objectify.inject_objects()
else:
show_basic_usage()
show_inject_objects_usage()
elif command == "objectify":
if len(command_args) >= 1:
objectify.objectify()
else:
show_basic_usage()
show_objectify_usage()
elif command == "revert-objects" or command == "revert_objects":
if len(command_args) >= 1:
objectify.revert_objects()
else:
show_basic_usage()
show_revert_objects_usage()
elif command == "mkdir":
if len(command_args) >= 1:
sb_mkdir.main()
Expand All @@ -194,13 +288,13 @@ def main():
else:
show_basic_usage()
show_download_usage()
elif command == "grid-hub":
elif command == "grid-hub" or command == "grid_hub":
if len(command_args) >= 1:
grid_hub.main()
else:
show_basic_usage()
show_grid_hub_usage()
elif command == "grid-node":
elif command == "grid-node" or command == "grid_node":
if len(command_args) >= 1:
grid_node.main()
else:
Expand All @@ -220,6 +314,22 @@ def main():
print("")
show_convert_usage()
return
elif command_args[0] == "extract-objects":
print("")
show_extract_objects_usage()
return
elif command_args[0] == "inject-objects":
print("")
show_inject_objects_usage()
return
elif command_args[0] == "objectify":
print("")
show_objectify_usage()
return
elif command_args[0] == "revert-objects":
print("")
show_revert_objects_usage()
return
elif command_args[0] == "download":
print("")
show_download_usage()
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/console_scripts/sb_mkdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def main():

data = []
data.append("class Page(object):")
data.append(" html = 'html'")
data.append(' html = "html"')
data.append("")
file_path = "%s/%s" % (dir_name_2, "page_objects.py")
file = codecs.open(file_path, "w+", "utf-8")
Expand Down
Loading