def main(): dir_path = os.path.dirname(os.path.realpath(__file__)) num_args = len(sys.argv) if sys.argv[0].split('/')[-1] == "seleniumbase" or ( sys.argv[0].split('\\')[-1] == "seleniumbase") or ( sys.argv[0].split('/')[-1] == "sbase") or ( sys.argv[0].split('\\')[-1] == "sbase"): if num_args < 3: invalid_run_command() else: invalid_run_command() grid_hub_command = sys.argv[2] if grid_hub_command not in ["start", "stop", "restart"]: invalid_run_command() verbose = "False" if num_args >= 4: options = sys.argv[3:] for option in options: if option == '-v' or option == '--verbose': verbose = "True" else: invalid_run_command() data = [] data.append(verbose) file_path = "%s/%s" % (dir_path, "verbose_hub_server.dat") file = codecs.open(file_path, "w+", "utf-8") file.writelines("\r\n".join(data)) file.close() from seleniumbase.utilities.selenium_grid import download_selenium_server download_selenium_server.main(force_download=False) # Only runs if needed if "linux" in sys.platform or "darwin" in sys.platform: if grid_hub_command == "start": subprocess.check_call(dir_path + "/grid-hub start", shell=True) elif grid_hub_command == "restart": subprocess.check_call(dir_path + "/grid-hub restart", shell=True) elif grid_hub_command == "stop": subprocess.check_call(dir_path + "/grid-hub stop", shell=True) else: invalid_run_command() else: if grid_hub_command == "start" or grid_hub_command == "restart": shell_command = ( """java -jar %s/selenium-server-standalone.jar -role hub """ """-timeout 180 -browserTimeout 75 -port 4444""" % dir_path) print("\nStarting Selenium-WebDriver Grid Hub...\n") print(shell_command) print("") print("Grid Hub Console: http://127.0.0.1:4444/grid/console") print("") subprocess.check_call(shell_command, shell=True) elif grid_hub_command == "stop": print("") print("To stop the Grid Hub, use CTRL-C inside the server shell!") print("") else: invalid_run_command()
def main(): dir_path = os.path.dirname(os.path.realpath(__file__)) num_args = len(sys.argv) if sys.argv[0].split('/')[-1] == "seleniumbase" or ( sys.argv[0].split('\\')[-1] == "seleniumbase"): if num_args < 3: invalid_run_command() else: invalid_run_command() grid_hub_command = sys.argv[2] if grid_hub_command not in ["start", "stop", "restart"]: invalid_run_command() verbose = "False" if num_args >= 4: options = sys.argv[3:] for option in options: if option == '-v' or option == '--verbose': verbose = "True" else: invalid_run_command() data = [] data.append(verbose) file_path = "%s/%s" % (dir_path, "verbose_hub_server.dat") file = codecs.open(file_path, "w+", "utf-8") file.writelines("\r\n".join(data)) file.close() from seleniumbase.utilities.selenium_grid import download_selenium_server download_selenium_server.main(force_download=False) # Only runs if needed if "linux" in sys.platform or "darwin" in sys.platform: if grid_hub_command == "start": subprocess.check_call(dir_path + "/grid-hub start", shell=True) elif grid_hub_command == "restart": subprocess.check_call(dir_path + "/grid-hub restart", shell=True) elif grid_hub_command == "stop": subprocess.check_call(dir_path + "/grid-hub stop", shell=True) else: invalid_run_command() else: if grid_hub_command == "start" or grid_hub_command == "restart": shell_command = ( """java -jar %s/selenium-server-standalone.jar -role hub """ """-timeout 30 -browserTimeout 60 -port 4444""" % dir_path) print("\nStarting Selenium-WebDriver Grid Hub...\n") print(shell_command) print("") print("Grid Hub Console: http://127.0.0.1:4444/grid/console") print("") subprocess.check_call(shell_command, shell=True) elif grid_hub_command == "stop": print("") print("To stop the Grid Hub, use CTRL-C inside the server shell!") print("") else: invalid_run_command()
def main(): # Install chromedriver if not installed if not is_chromedriver_on_path(): from seleniumbase.console_scripts import sb_install sys_args = sys.argv # Save a copy of current sys args print("\nWarning: chromedriver not found. Installing now:") sb_install.main(override="chromedriver") sys.argv = sys_args # Put back the original sys args dir_path = os.path.dirname(os.path.realpath(__file__)) num_args = len(sys.argv) if (sys.argv[0].split("/")[-1] == "seleniumbase" or (sys.argv[0].split("\\")[-1] == "seleniumbase") or (sys.argv[0].split("/")[-1] == "sbase") or (sys.argv[0].split("\\")[-1] == "sbase")): if num_args < 3: invalid_run_command() else: invalid_run_command() grid_hub_command = sys.argv[2] if grid_hub_command not in ["start", "stop", "restart"]: invalid_run_command() server_ip = "127.0.0.1" verbose = "False" if num_args >= 4: options = sys.argv[3:] for option in options: if option.startswith("--hub=") and (len(option.split("--hub=")[1]) > 0): server_ip = option.split("--hub=")[1] elif option == "-v" or option == "--verbose": verbose = "True" else: invalid_run_command() data = [] data.append(server_ip) file_path = "%s/%s" % (dir_path, "ip_of_grid_hub.dat") file = codecs.open(file_path, "w+", "utf-8") file.writelines("\r\n".join(data)) file.close() data = [] data.append(verbose) file_path = "%s/%s" % (dir_path, "verbose_node_server.dat") file = codecs.open(file_path, "w+", "utf-8") file.writelines("\r\n".join(data)) file.close() from seleniumbase.utilities.selenium_grid import download_selenium_server download_selenium_server.main(force_download=False) # Only runs if needed if "linux" in sys.platform or "darwin" in sys.platform: if grid_hub_command == "start": subprocess.check_call(dir_path + "/grid-node start", shell=True) elif grid_hub_command == "restart": subprocess.check_call(dir_path + "/grid-node restart", shell=True) elif grid_hub_command == "stop": subprocess.check_call(dir_path + "/grid-node stop", shell=True) else: invalid_run_command() else: if grid_hub_command == "start" or grid_hub_command == "restart": shell_command = ( """java -jar %s/selenium-server-standalone.jar -role node """ """-hub http://%s:4444/grid/register -browser browser""" """Name=chrome,maxInstances=5,version=ANY,seleniumProtocol=""" """WebDriver -browser browserName=firefox,maxInstances=5,""" """version=ANY,seleniumProtocol=WebDriver -browser browser""" """Name=MicrosoftEdge,maxInstances=1,version=ANY,""" """platform=WIN10,seleniumProtocol=WebDriver""" % (dir_path, server_ip)) print("\nStarting Selenium-WebDriver Grid node...\n") print(shell_command) print("") print("""Browser Sessions: http://127.0.0.1:5555""" """/wd/hub/static/resource/hub.html""") print("") subprocess.check_call(shell_command, shell=True) elif grid_hub_command == "stop": print("") print("To stop the Grid node, use CTRL-C inside the server shell!") print("") else: invalid_run_command()
def main(): command = None command_args = None num_args = len(sys.argv) if num_args == 1: show_usage() return elif num_args == 2: command = sys.argv[1] command_args = [] elif num_args > 2: command = sys.argv[1] command_args = sys.argv[2:] command = command.lower() if command == "install": if len(command_args) >= 1: from seleniumbase.console_scripts import sb_install sb_install.main() else: show_basic_usage() show_install_usage() elif command == "mkdir": if len(command_args) >= 1: from seleniumbase.console_scripts import sb_mkdir sb_mkdir.main() else: show_basic_usage() show_mkdir_usage() elif command == "mkfile": if len(command_args) >= 1: from seleniumbase.console_scripts import sb_mkfile sb_mkfile.main() else: show_basic_usage() show_mkfile_usage() elif command == "mkpres": if len(command_args) >= 1: from seleniumbase.console_scripts import sb_mkpres sb_mkpres.main() else: show_basic_usage() show_mkpres_usage() elif command == "mkchart": if len(command_args) >= 1: from seleniumbase.console_scripts import sb_mkchart sb_mkchart.main() else: show_basic_usage() show_mkchart_usage() elif command == "convert": if len(command_args) == 1: from seleniumbase.utilities.selenium_ide import convert_ide convert_ide.main() else: show_basic_usage() show_convert_usage() elif command == "print": if len(command_args) >= 1: if sys.version_info[0] == 2: 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: c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX cr = colorama.Style.RESET_ALL msg = "The SeleniumBase Translator does NOT support Python 2!" message = "\n" + c5 + msg + cr + "\n" print("") raise Exception(message) from seleniumbase.translate import translator translator.main() else: show_basic_usage() show_translate_usage() elif command == "extract-objects" or command == "extract_objects": if len(command_args) >= 1: from seleniumbase.console_scripts import objectify objectify.extract_objects() else: show_basic_usage() show_extract_objects_usage() elif command == "inject-objects" or command == "inject_objects": if len(command_args) >= 1: from seleniumbase.console_scripts import objectify objectify.inject_objects() else: show_basic_usage() show_inject_objects_usage() elif command == "objectify": if len(command_args) >= 1: from seleniumbase.console_scripts import objectify objectify.objectify() else: show_basic_usage() show_objectify_usage() elif command == "revert-objects" or command == "revert_objects": if len(command_args) >= 1: from seleniumbase.console_scripts import objectify objectify.revert_objects() else: show_basic_usage() show_revert_objects_usage() elif command == "encrypt" or command == "obfuscate": if len(command_args) >= 0: from seleniumbase.common import obfuscate obfuscate.main() else: show_basic_usage() show_encrypt_usage() elif command == "decrypt" or command == "unobfuscate": if len(command_args) >= 0: from seleniumbase.common import unobfuscate unobfuscate.main() else: show_basic_usage() show_decrypt_usage() elif command == "download": if len(command_args) >= 1 and command_args[0].lower() == "server": from seleniumbase.utilities.selenium_grid import ( download_selenium_server) download_selenium_server.main(force_download=True) else: show_basic_usage() show_download_usage() elif command == "grid-hub" or command == "grid_hub": if len(command_args) >= 1: from seleniumbase.utilities.selenium_grid import grid_hub grid_hub.main() else: show_basic_usage() show_grid_hub_usage() elif command == "grid-node" or command == "grid_node": if len(command_args) >= 1: from seleniumbase.utilities.selenium_grid import grid_node grid_node.main() else: show_basic_usage() show_grid_node_usage() elif command == "version" or command == "--version": if len(command_args) == 0: from seleniumbase.console_scripts import logo_helper seleniumbase_logo = logo_helper.get_seleniumbase_logo() print(seleniumbase_logo) print("") show_package_location() show_version_info() print("") else: show_basic_usage() elif command == "methods" or command == "--methods": show_methods() elif command == "options" or command == "--options": show_options() elif command == "help" or command == "--help": if len(command_args) >= 1: if command_args[0] == "install": print("") show_install_usage() return elif command_args[0] == "mkdir": print("") show_mkdir_usage() return elif command_args[0] == "mkfile": print("") show_mkfile_usage() return elif command_args[0] == "mkpres": print("") show_mkpres_usage() return elif command_args[0] == "mkchart": print("") show_mkchart_usage() return elif command_args[0] == "convert": print("") show_convert_usage() return elif command_args[0] == "print": print("") show_print_usage() return elif command_args[0] == "translate": print("") show_translate_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] == "encrypt": print("") show_encrypt_usage() return elif command_args[0] == "obfuscate": print("") show_encrypt_usage() return elif command_args[0] == "decrypt": print("") show_decrypt_usage() return elif command_args[0] == "unobfuscate": print("") show_decrypt_usage() return elif command_args[0] == "download": print("") show_download_usage() return elif command_args[0] == "grid-hub": print("") show_grid_hub_usage() return elif command_args[0] == "grid-node": print("") show_grid_node_usage() return show_detailed_help() else: show_usage()
def main(): command = None command_args = None num_args = len(sys.argv) if num_args == 1: show_usage() return elif num_args == 2: command = sys.argv[1] command_args = [] elif num_args > 2: command = sys.argv[1] command_args = sys.argv[2:] command = command.lower() if command == "install": if len(command_args) >= 1: sb_install.main() else: show_basic_usage() show_install_usage() elif command == "convert": if len(command_args) == 1: convert_ide.main() else: show_basic_usage() show_convert_usage() elif command == "mkdir": if len(command_args) >= 1: sb_mkdir.main() else: show_basic_usage() show_mkdir_usage() elif command == "download": if len(command_args) >= 1: download_selenium_server.main(force_download=True) else: show_basic_usage() show_download_usage() elif command == "grid-hub": if len(command_args) >= 1: grid_hub.main() else: show_basic_usage() show_grid_hub_usage() elif command == "grid-node": if len(command_args) >= 1: grid_node.main() else: show_basic_usage() show_grid_node_usage() elif command == "help" or command == "--help": if len(command_args) >= 1: if command_args[0] == "install": print("") show_install_usage() return elif command_args[0] == "mkdir": print("") show_mkdir_usage() return elif command_args[0] == "convert": print("") show_convert_usage() return elif command_args[0] == "download": print("") show_download_usage() return elif command_args[0] == "grid-hub": print("") show_grid_hub_usage() return elif command_args[0] == "grid-node": print("") show_grid_node_usage() return show_detailed_help() else: show_usage()
def main(): command = None command_args = None num_args = len(sys.argv) if num_args == 1: show_usage() return elif num_args == 2: command = sys.argv[1] command_args = [] elif num_args > 2: command = sys.argv[1] command_args = sys.argv[2:] command = command.lower() if command == "install": if len(command_args) >= 1: sb_install.main() else: show_basic_usage() show_install_usage() elif command == "mkdir": if len(command_args) >= 1: sb_mkdir.main() else: show_basic_usage() show_mkdir_usage() elif command == "convert": if len(command_args) == 1: convert_ide.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 == "encrypt" or command == "obfuscate": if len(command_args) >= 0: obfuscate.main() else: show_basic_usage() show_encrypt_usage() elif command == "decrypt" or command == "unobfuscate": if len(command_args) >= 0: unobfuscate.main() else: show_basic_usage() show_decrypt_usage() elif command == "download": if len(command_args) >= 1 and command_args[0].lower() == "server": download_selenium_server.main(force_download=True) else: show_basic_usage() show_download_usage() 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" or command == "grid_node": if len(command_args) >= 1: grid_node.main() else: show_basic_usage() show_grid_node_usage() elif command == "version" or command == "--version": if len(command_args) == 0: show_version_info() else: show_basic_usage() elif command == "help" or command == "--help": if len(command_args) >= 1: if command_args[0] == "install": print("") show_install_usage() return elif command_args[0] == "mkdir": print("") show_mkdir_usage() return elif command_args[0] == "convert": 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] == "encrypt": print("") show_encrypt_usage() return elif command_args[0] == "obfuscate": print("") show_encrypt_usage() return elif command_args[0] == "decrypt": print("") show_decrypt_usage() return elif command_args[0] == "unobfuscate": print("") show_decrypt_usage() return elif command_args[0] == "download": print("") show_download_usage() return elif command_args[0] == "grid-hub": print("") show_grid_hub_usage() return elif command_args[0] == "grid-node": print("") show_grid_node_usage() return show_detailed_help() else: show_usage()
def main(): command = None command_args = None num_args = len(sys.argv) if num_args == 1: show_usage() return elif num_args == 2: command = sys.argv[1] command_args = [] elif num_args > 2: command = sys.argv[1] command_args = sys.argv[2:] command = command.lower() if command == "install": if len(command_args) >= 1: sb_install.main() else: show_basic_usage() show_install_usage() elif command == "convert": if len(command_args) == 1: convert_ide.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() else: show_basic_usage() show_mkdir_usage() elif command == "download": if len(command_args) >= 1 and command_args[0].lower() == "server": download_selenium_server.main(force_download=True) else: show_basic_usage() show_download_usage() 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" or command == "grid_node": if len(command_args) >= 1: grid_node.main() else: show_basic_usage() show_grid_node_usage() elif command == "help" or command == "--help": if len(command_args) >= 1: if command_args[0] == "install": print("") show_install_usage() return elif command_args[0] == "mkdir": print("") show_mkdir_usage() return elif command_args[0] == "convert": 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() return elif command_args[0] == "grid-hub": print("") show_grid_hub_usage() return elif command_args[0] == "grid-node": print("") show_grid_node_usage() return show_detailed_help() else: show_usage()
def main(): dir_path = os.path.dirname(os.path.realpath(__file__)) num_args = len(sys.argv) if sys.argv[0].split('/')[-1] == "seleniumbase" or ( sys.argv[0].split('\\')[-1] == "seleniumbase"): if num_args < 3: invalid_run_command() else: invalid_run_command() grid_hub_command = sys.argv[2] if grid_hub_command not in ["start", "stop", "restart"]: invalid_run_command() server_ip = "127.0.0.1" verbose = "False" if num_args >= 4: options = sys.argv[3:] for option in options: if option.startswith('--hub=') and (len(option.split('--hub=')[1]) > 0): server_ip = option.split('--hub=')[1] elif option == '-v' or option == '--verbose': verbose = "True" else: invalid_run_command() data = [] data.append(server_ip) file_path = "%s/%s" % (dir_path, "ip_of_grid_hub.dat") file = codecs.open(file_path, "w+", "utf-8") file.writelines("\r\n".join(data)) file.close() data = [] data.append(verbose) file_path = "%s/%s" % (dir_path, "verbose_node_server.dat") file = codecs.open(file_path, "w+", "utf-8") file.writelines("\r\n".join(data)) file.close() from seleniumbase.utilities.selenium_grid import download_selenium_server download_selenium_server.main() # Nothing happens if already exists if "linux" in sys.platform or "darwin" in sys.platform: if grid_hub_command == "start": subprocess.check_call(dir_path + "/grid-node start", shell=True) elif grid_hub_command == "restart": subprocess.check_call(dir_path + "/grid-node restart", shell=True) elif grid_hub_command == "stop": subprocess.check_call(dir_path + "/grid-node stop", shell=True) else: invalid_run_command() else: if grid_hub_command == "start" or grid_hub_command == "restart": shell_command = ( """java -jar %s/selenium-server-standalone.jar -role node """ """-hub http://%s:4444/grid/register -browser browser""" """Name=chrome,maxInstances=5,version=ANY,seleniumProtocol=""" """WebDriver -browser browserName=firefox,maxInstances=5,""" """version=ANY,seleniumProtocol=WebDriver -browser browser""" """Name=MicrosoftEdge,maxInstances=1,version=ANY,""" """platform=WIN10,seleniumProtocol=WebDriver""" % (dir_path, server_ip)) print("\nStarting Selenium-WebDriver Grid node...\n") print(shell_command) print("") print("""Browser Sessions: http://127.0.0.1:5555""" """/wd/hub/static/resource/hub.html""") print("") subprocess.check_call(shell_command, shell=True) elif grid_hub_command == "stop": print("") print("To stop the Grid node, use CTRL-C inside the server shell!") print("") else: invalid_run_command()
def main(): timeout = 230 # The default number of seconds that a test can be idle dir_path = os.path.dirname(os.path.realpath(__file__)) num_args = len(sys.argv) if sys.argv[0].split('/')[-1] == "seleniumbase" or ( sys.argv[0].split('\\')[-1] == "seleniumbase") or (sys.argv[0].split('/')[-1] == "sbase") or (sys.argv[0].split('\\')[-1] == "sbase"): if num_args < 3: invalid_run_command() else: invalid_run_command() grid_hub_command = sys.argv[2] if grid_hub_command not in ["start", "stop", "restart"]: invalid_run_command() verbose = "False" if num_args >= 4: options = sys.argv[3:] for option in options: if option == '-v' or option == '--verbose': verbose = "True" elif option.startswith("--timeout=") and len(option) > 10: timeout = option.split("--timeout=")[1] if not timeout.isdigit(): msg = '\n"timeout" must be a non-negative integer!\n' print(msg) invalid_run_command(msg) else: invalid_run_command() data = [] data.append(verbose) file_path = "%s/%s" % (dir_path, "verbose_hub_server.dat") file = codecs.open(file_path, "w+", "utf-8") file.writelines("\r\n".join(data)) file.close() from seleniumbase.utilities.selenium_grid import download_selenium_server download_selenium_server.main(force_download=False) # Only runs if needed if "linux" in sys.platform or "darwin" in sys.platform: if grid_hub_command == "start": subprocess.check_call(dir_path + "/grid-hub start %s" % timeout, shell=True) elif grid_hub_command == "restart": subprocess.check_call(dir_path + "/grid-hub stop .", shell=True) subprocess.check_call(dir_path + "/grid-hub start %s" % timeout, shell=True) elif grid_hub_command == "stop": subprocess.check_call(dir_path + "/grid-hub stop .", shell=True) else: invalid_run_command() else: if grid_hub_command == "start" or grid_hub_command == "restart": shell_command = ( """java -jar %s/selenium-server-standalone.jar -role hub """ """-timeout %s -browserTimeout 170 -port 4444""" "" % (dir_path, timeout)) print("\nStarting Selenium-WebDriver Grid Hub...\n") print(shell_command) print("") print("Grid Hub Console: http://127.0.0.1:4444/grid/console") print("") subprocess.check_call(shell_command, shell=True) elif grid_hub_command == "stop": print("") print("To stop the Grid Hub, use CTRL+C inside the server shell!") print("") else: invalid_run_command()
def main(): dir_path = os.path.dirname(os.path.realpath(__file__)) num_args = len(sys.argv) if sys.argv[0].split('/')[-1] == "seleniumbase" or ( sys.argv[0].split('\\')[-1] == "seleniumbase"): if num_args < 3: invalid_run_command() else: invalid_run_command() grid_hub_command = sys.argv[2] if grid_hub_command not in ["start", "stop", "restart"]: invalid_run_command() server_ip = "127.0.0.1" verbose = "False" if num_args >= 4: options = sys.argv[3:] for option in options: if option.startswith('--hub=') and ( len(option.split('--hub=')[1]) > 0): server_ip = option.split('--hub=')[1] elif option == '-v' or option == '--verbose': verbose = "True" else: invalid_run_command() data = [] data.append(server_ip) file_path = "%s/%s" % (dir_path, "ip_of_grid_hub.dat") file = codecs.open(file_path, "w+", "utf-8") file.writelines("\r\n".join(data)) file.close() data = [] data.append(verbose) file_path = "%s/%s" % (dir_path, "verbose_node_server.dat") file = codecs.open(file_path, "w+", "utf-8") file.writelines("\r\n".join(data)) file.close() from seleniumbase.utilities.selenium_grid import download_selenium_server download_selenium_server.main(force_download=False) # Only runs if needed if "linux" in sys.platform or "darwin" in sys.platform: if grid_hub_command == "start": subprocess.check_call(dir_path + "/grid-node start", shell=True) elif grid_hub_command == "restart": subprocess.check_call(dir_path + "/grid-node restart", shell=True) elif grid_hub_command == "stop": subprocess.check_call(dir_path + "/grid-node stop", shell=True) else: invalid_run_command() else: if grid_hub_command == "start" or grid_hub_command == "restart": shell_command = ( """java -jar %s/selenium-server-standalone.jar -role node """ """-hub http://%s:4444/grid/register -browser browser""" """Name=chrome,maxInstances=5,version=ANY,seleniumProtocol=""" """WebDriver -browser browserName=firefox,maxInstances=5,""" """version=ANY,seleniumProtocol=WebDriver -browser browser""" """Name=MicrosoftEdge,maxInstances=1,version=ANY,""" """platform=WIN10,seleniumProtocol=WebDriver""" % (dir_path, server_ip)) print("\nStarting Selenium-WebDriver Grid node...\n") print(shell_command) print("") print("""Browser Sessions: http://127.0.0.1:5555""" """/wd/hub/static/resource/hub.html""") print("") subprocess.check_call(shell_command, shell=True) elif grid_hub_command == "stop": print("") print("To stop the Grid node, use CTRL-C inside the server shell!") print("") else: invalid_run_command()
def main(): command = None command_args = None num_args = len(sys.argv) if num_args == 1: show_usage() return elif num_args == 2: command = sys.argv[1] command_args = [] elif num_args > 2: command = sys.argv[1] command_args = sys.argv[2:] command = command.lower() if command == "install": if len(command_args) >= 1: sb_install.main() else: show_basic_usage() show_install_usage() elif command == "mkdir": if len(command_args) >= 1: sb_mkdir.main() else: show_basic_usage() show_mkdir_usage() elif command == "convert": if len(command_args) == 1: convert_ide.main() else: show_basic_usage() show_convert_usage() elif command == "translate": 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 = "The SeleniumBase Translator does NOT support Python 2!" message = "\n" + c5 + msg + cr + "\n" print("") raise Exception(message) from seleniumbase.translate import translator translator.main() else: show_basic_usage() show_translate_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 == "encrypt" or command == "obfuscate": if len(command_args) >= 0: obfuscate.main() else: show_basic_usage() show_encrypt_usage() elif command == "decrypt" or command == "unobfuscate": if len(command_args) >= 0: unobfuscate.main() else: show_basic_usage() show_decrypt_usage() elif command == "download": if len(command_args) >= 1 and command_args[0].lower() == "server": download_selenium_server.main(force_download=True) else: show_basic_usage() show_download_usage() 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" or command == "grid_node": if len(command_args) >= 1: grid_node.main() else: show_basic_usage() show_grid_node_usage() elif command == "version" or command == "--version": if len(command_args) == 0: show_version_info() else: show_basic_usage() elif command == "help" or command == "--help": if len(command_args) >= 1: if command_args[0] == "install": print("") show_install_usage() return elif command_args[0] == "mkdir": print("") show_mkdir_usage() return elif command_args[0] == "convert": print("") show_convert_usage() return elif command_args[0] == "translate": print("") show_translate_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] == "encrypt": print("") show_encrypt_usage() return elif command_args[0] == "obfuscate": print("") show_encrypt_usage() return elif command_args[0] == "decrypt": print("") show_decrypt_usage() return elif command_args[0] == "unobfuscate": print("") show_decrypt_usage() return elif command_args[0] == "download": print("") show_download_usage() return elif command_args[0] == "grid-hub": print("") show_grid_hub_usage() return elif command_args[0] == "grid-node": print("") show_grid_node_usage() return show_detailed_help() else: show_usage()