Refactor the code
This commit is contained in:
parent
614af4836e
commit
ea3788704c
|
@ -6,6 +6,7 @@ from seleniumbase import DriverContext # noqa
|
|||
from seleniumbase import encryption # noqa
|
||||
from seleniumbase import get_driver # noqa
|
||||
from seleniumbase import js_utils # noqa
|
||||
from seleniumbase import shared_utils # noqa
|
||||
from seleniumbase import MasterQA # noqa
|
||||
from seleniumbase import page_actions # noqa
|
||||
from seleniumbase import page_utils # noqa
|
||||
|
|
|
@ -14,6 +14,7 @@ from seleniumbase.core.browser_launcher import get_driver # noqa
|
|||
from seleniumbase.fixtures import js_utils # noqa
|
||||
from seleniumbase.fixtures import page_actions # noqa
|
||||
from seleniumbase.fixtures import page_utils # noqa
|
||||
from seleniumbase.fixtures import shared_utils # noqa
|
||||
from seleniumbase.fixtures.base_case import BaseCase # noqa
|
||||
from seleniumbase.masterqa.master_qa import MasterQA # noqa
|
||||
from seleniumbase.plugins.sb_manager import SB # noqa
|
||||
|
|
|
@ -82,8 +82,8 @@ behave -D agent="User Agent String" -D demo
|
|||
-D incognito (Enable Chrome's Incognito mode.)
|
||||
-D guest (Enable Chrome's Guest mode.)
|
||||
-D devtools (Open Chrome's DevTools when the browser opens.)
|
||||
-D reuse-session | -D rs (Reuse browser session for all tests.)
|
||||
-D reuse-class-session | -D rcs (Reuse session for tests in class/feature)
|
||||
-D rs | -D reuse-session (Reuse browser session for all tests.)
|
||||
-D rcs | -D reuse-class-session (Reuse session for tests in class/feature)
|
||||
-D crumbs (Delete all cookies between tests reusing a session.)
|
||||
-D disable-beforeunload (Disable the "beforeunload" event on Chrome.)
|
||||
-D window-size=WIDTH,HEIGHT (Set the browser's starting window size.)
|
||||
|
@ -95,24 +95,21 @@ behave -D agent="User Agent String" -D demo
|
|||
-D external-pdf (Set Chromium "plugins.always_open_pdf_externally":True.)
|
||||
-D timeout-multiplier=MULTIPLIER (Multiplies the default timeout values.)
|
||||
"""
|
||||
|
||||
import ast
|
||||
import colorama
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from seleniumbase import config as sb_config
|
||||
from seleniumbase.config import settings
|
||||
from seleniumbase.core import log_helper
|
||||
from seleniumbase.core import download_helper
|
||||
from seleniumbase.core import log_helper
|
||||
from seleniumbase.core import proxy_helper
|
||||
from seleniumbase.core import session_helper
|
||||
from seleniumbase.fixtures import constants
|
||||
from seleniumbase import config as sb_config
|
||||
from seleniumbase.fixtures import shared_utils
|
||||
|
||||
sb_config.__base_class = None
|
||||
is_windows = False
|
||||
if sys.platform in ["win32", "win64", "x64"]:
|
||||
is_windows = True
|
||||
|
||||
|
||||
def set_base_class(base_class):
|
||||
|
@ -817,10 +814,10 @@ def get_configured_sb(context):
|
|||
'\n (Your browser choice was: "%s")\n' % sb.browser
|
||||
)
|
||||
# The Xvfb virtual display server is for Linux OS Only.
|
||||
if sb.xvfb and "linux" not in sys.platform:
|
||||
if sb.xvfb and not shared_utils.is_linux():
|
||||
sb.xvfb = False
|
||||
if (
|
||||
"linux" in sys.platform
|
||||
shared_utils.is_linux()
|
||||
and not sb.headed
|
||||
and not sb.headless
|
||||
and not sb.headless2
|
||||
|
@ -931,7 +928,6 @@ def get_configured_sb(context):
|
|||
log_helper.log_folder_setup(sb.log_path, sb.archive_logs)
|
||||
download_helper.reset_downloads_folder()
|
||||
proxy_helper.remove_proxy_zip_if_present()
|
||||
|
||||
return sb
|
||||
|
||||
|
||||
|
@ -1007,7 +1003,7 @@ def dashboard_pre_processing():
|
|||
filename = None
|
||||
feature_name = None
|
||||
scenario_name = None
|
||||
if is_windows:
|
||||
if shared_utils.is_windows():
|
||||
output = output.decode("latin1")
|
||||
else:
|
||||
output = output.decode("utf-8")
|
||||
|
@ -1116,7 +1112,7 @@ def behave_dashboard_prepare():
|
|||
stars = "*" * star_len
|
||||
c1 = ""
|
||||
cr = ""
|
||||
if "linux" not in sys.platform:
|
||||
if not shared_utils.is_linux():
|
||||
colorama.init(autoreset=True)
|
||||
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
|
||||
cr = colorama.Style.RESET_ALL
|
||||
|
@ -1124,9 +1120,6 @@ def behave_dashboard_prepare():
|
|||
|
||||
|
||||
def _perform_behave_unconfigure_():
|
||||
from seleniumbase.core import log_helper
|
||||
from seleniumbase.core import proxy_helper
|
||||
|
||||
if hasattr(sb_config, "multi_proxy") and not sb_config.multi_proxy:
|
||||
proxy_helper.remove_proxy_zip_if_present()
|
||||
if hasattr(sb_config, "reuse_session") and sb_config.reuse_session:
|
||||
|
@ -1134,7 +1127,7 @@ def _perform_behave_unconfigure_():
|
|||
if sb_config.shared_driver:
|
||||
try:
|
||||
if (
|
||||
not is_windows
|
||||
not shared_utils.is_windows()
|
||||
or sb_config.browser == "ie"
|
||||
or sb_config.shared_driver.service.process
|
||||
):
|
||||
|
@ -1210,7 +1203,7 @@ def do_final_driver_cleanup_as_needed():
|
|||
try:
|
||||
if hasattr(sb_config, "last_driver") and sb_config.last_driver:
|
||||
if (
|
||||
not is_windows
|
||||
not shared_utils.is_windows()
|
||||
or sb_config.browser == "ie"
|
||||
or sb_config.last_driver.service.process
|
||||
):
|
||||
|
@ -1232,7 +1225,7 @@ def _perform_behave_terminal_summary_():
|
|||
equals = "=" * (equals_len + 2)
|
||||
c2 = ""
|
||||
cr = ""
|
||||
if "linux" not in sys.platform:
|
||||
if not shared_utils.is_linux():
|
||||
colorama.init(autoreset=True)
|
||||
c2 = colorama.Fore.MAGENTA + colorama.Back.LIGHTYELLOW_EX
|
||||
cr = colorama.Style.RESET_ALL
|
||||
|
|
|
@ -40,7 +40,6 @@ import colorama
|
|||
import sys
|
||||
import time
|
||||
from seleniumbase.fixtures import constants
|
||||
from seleniumbase.fixtures import shared_utils
|
||||
|
||||
colorama.init(autoreset=True)
|
||||
|
||||
|
@ -144,8 +143,8 @@ def show_install_usage():
|
|||
print(" sbase get chromedriver")
|
||||
print(" sbase get geckodriver")
|
||||
print(" sbase get edgedriver")
|
||||
print(" sbase get chromedriver 112")
|
||||
print(" sbase get chromedriver 112.0.5615.49")
|
||||
print(" sbase get chromedriver 114")
|
||||
print(" sbase get chromedriver 114.0.5735.90")
|
||||
print(" sbase get chromedriver latest")
|
||||
print(" sbase get chromedriver latest-1")
|
||||
print(" sbase get chromedriver -p")
|
||||
|
@ -976,12 +975,14 @@ def main():
|
|||
retry_msg_1 = "* Unable to download driver! Retrying in 3s..."
|
||||
retry_msg_2 = "** Unable to download driver! Retrying in 5s..."
|
||||
if " --proxy=" in " ".join(sys.argv):
|
||||
from seleniumbase.core import proxy_helper
|
||||
|
||||
for arg in sys.argv:
|
||||
if arg.startswith("--proxy="):
|
||||
proxy_string = arg.split("--proxy=")[1]
|
||||
if "@" in proxy_string:
|
||||
proxy_string = proxy_string.split("@")[1]
|
||||
shared_utils.validate_proxy_string(proxy_string)
|
||||
proxy_helper.validate_proxy_string(proxy_string)
|
||||
break
|
||||
try:
|
||||
sb_install.main()
|
||||
|
|
|
@ -23,13 +23,10 @@ if sys.version_info <= (3, 7):
|
|||
"\n* SBase Commander requires Python 3.7 or newer!"
|
||||
"\n** You are currently using Python %s" % current_version
|
||||
)
|
||||
from seleniumbase.fixtures import shared_utils
|
||||
import tkinter as tk # noqa: E402
|
||||
from tkinter.scrolledtext import ScrolledText # noqa: E402
|
||||
|
||||
is_windows = False
|
||||
if sys.platform in ["win32", "win64", "x64"]:
|
||||
is_windows = True
|
||||
|
||||
|
||||
def set_colors(use_colors):
|
||||
c0 = ""
|
||||
|
@ -127,7 +124,7 @@ def do_behave_run(
|
|||
|
||||
if headless:
|
||||
full_run_command += " -D headless"
|
||||
elif "linux" in sys.platform:
|
||||
elif shared_utils.is_linux():
|
||||
full_run_command += " -D gui"
|
||||
|
||||
if save_screenshots:
|
||||
|
@ -188,7 +185,7 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
|
|||
"Use Edge Browser (-D edge)",
|
||||
"Use Firefox Browser (-D firefox)",
|
||||
]
|
||||
if "darwin" in sys.platform:
|
||||
if shared_utils.is_mac():
|
||||
options_list.append("Use Safari Browser (-D safari)")
|
||||
brx = tk.StringVar(root)
|
||||
brx.set(options_list[0])
|
||||
|
@ -267,7 +264,7 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
|
|||
row += " " * 200
|
||||
ara[count] = tk.IntVar()
|
||||
cb = None
|
||||
if not is_windows:
|
||||
if not shared_utils.is_windows():
|
||||
cb = tk.Checkbutton(
|
||||
text_area,
|
||||
text=(row),
|
||||
|
@ -362,7 +359,7 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
|
|||
|
||||
def main():
|
||||
use_colors = True
|
||||
if "linux" in sys.platform:
|
||||
if shared_utils.is_linux():
|
||||
use_colors = False
|
||||
c0, c1, c2, c3, c4, c5, c6, cr = set_colors(use_colors)
|
||||
command_args = sys.argv[2:]
|
||||
|
@ -414,7 +411,7 @@ def main():
|
|||
f_count = 0
|
||||
s_count = 0
|
||||
t_count = 0
|
||||
if is_windows:
|
||||
if shared_utils.is_windows():
|
||||
output = output.decode("latin1")
|
||||
else:
|
||||
output = output.decode("utf-8")
|
||||
|
|
|
@ -27,14 +27,11 @@ if sys.version_info <= (3, 7):
|
|||
"\n* SBase Case Plans Generator requires Python 3.7 or newer!"
|
||||
"\n** You are currently using Python %s" % current_version
|
||||
)
|
||||
from seleniumbase.fixtures import shared_utils
|
||||
import tkinter as tk # noqa: E402
|
||||
from tkinter import messagebox # noqa: E402
|
||||
from tkinter.scrolledtext import ScrolledText # noqa: E402
|
||||
|
||||
is_windows = False
|
||||
if sys.platform in ["win32", "win64", "x64"]:
|
||||
is_windows = True
|
||||
|
||||
|
||||
def set_colors(use_colors):
|
||||
c0 = ""
|
||||
|
@ -404,7 +401,7 @@ def create_tkinter_gui(tests, command_string):
|
|||
row += " " * 200
|
||||
ara[count] = tk.IntVar()
|
||||
cb = None
|
||||
if not is_windows:
|
||||
if not shared_utils.is_windows():
|
||||
cb = tk.Checkbutton(
|
||||
text_area,
|
||||
text=(row),
|
||||
|
|
|
@ -28,13 +28,10 @@ if sys.version_info <= (3, 7):
|
|||
"\n* SBase Commander requires Python 3.7 or newer!"
|
||||
"\n** You are currently using Python %s" % current_version
|
||||
)
|
||||
from seleniumbase.fixtures import shared_utils
|
||||
import tkinter as tk # noqa: E402
|
||||
from tkinter.scrolledtext import ScrolledText # noqa: E402
|
||||
|
||||
is_windows = False
|
||||
if sys.platform in ["win32", "win64", "x64"]:
|
||||
is_windows = True
|
||||
|
||||
|
||||
def set_colors(use_colors):
|
||||
c0 = ""
|
||||
|
@ -154,7 +151,7 @@ def do_pytest_run(
|
|||
|
||||
if headless:
|
||||
full_run_command += " --headless"
|
||||
elif "linux" in sys.platform:
|
||||
elif shared_utils.is_linux():
|
||||
full_run_command += " --gui"
|
||||
|
||||
if save_screenshots:
|
||||
|
@ -191,7 +188,7 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
|
|||
"Use Edge Browser (--edge)",
|
||||
"Use Firefox Browser (--firefox)",
|
||||
]
|
||||
if "darwin" in sys.platform:
|
||||
if shared_utils.is_mac():
|
||||
options_list.append("Use Safari Browser (--safari)")
|
||||
brx = tk.StringVar(root)
|
||||
brx.set(options_list[0])
|
||||
|
@ -302,7 +299,7 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
|
|||
row += " " * 200
|
||||
ara[count] = tk.IntVar()
|
||||
cb = None
|
||||
if not is_windows:
|
||||
if not shared_utils.is_windows():
|
||||
cb = tk.Checkbutton(
|
||||
text_area,
|
||||
text=(row),
|
||||
|
@ -401,7 +398,7 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
|
|||
|
||||
def main():
|
||||
use_colors = True
|
||||
if "linux" in sys.platform:
|
||||
if shared_utils.is_linux():
|
||||
use_colors = False
|
||||
c0, c1, c2, c3, c4, c5, cr = set_colors(use_colors)
|
||||
command_args = sys.argv[2:]
|
||||
|
|
|
@ -14,8 +14,8 @@ Examples:
|
|||
sbase get chromedriver
|
||||
sbase get geckodriver
|
||||
sbase get edgedriver
|
||||
sbase get chromedriver 112
|
||||
sbase get chromedriver 112.0.5615.49
|
||||
sbase get chromedriver 114
|
||||
sbase get chromedriver 114.0.5735.90
|
||||
sbase get chromedriver latest
|
||||
sbase get chromedriver latest-1 # (Latest minus one)
|
||||
sbase get chromedriver -p
|
||||
|
@ -32,6 +32,7 @@ import platform
|
|||
import requests
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
import tarfile
|
||||
import urllib3
|
||||
import zipfile
|
||||
|
@ -42,26 +43,18 @@ from seleniumbase import drivers # webdriver storage folder for SeleniumBase
|
|||
|
||||
urllib3.disable_warnings()
|
||||
selenium4_or_newer = False
|
||||
if sys.version_info[0] == 3 and sys.version_info[1] >= 7:
|
||||
if sys.version_info >= (3, 7):
|
||||
selenium4_or_newer = True
|
||||
IS_ARM_MAC = False
|
||||
if (
|
||||
sys.platform.endswith("darwin")
|
||||
and (
|
||||
"arm" in platform.processor().lower()
|
||||
or "arm64" in platform.version().lower()
|
||||
)
|
||||
):
|
||||
IS_ARM_MAC = True
|
||||
PLAT = sys.platform
|
||||
IS_WINDOWS = False
|
||||
if "win32" in PLAT or "win64" in PLAT or "x64" in PLAT or "x86" in PLAT:
|
||||
IS_WINDOWS = True
|
||||
ARCH = platform.architecture()[0]
|
||||
IS_ARM_MAC = shared_utils.is_arm_mac()
|
||||
IS_MAC = shared_utils.is_mac()
|
||||
IS_LINUX = shared_utils.is_linux()
|
||||
IS_WINDOWS = shared_utils.is_windows()
|
||||
DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
|
||||
LOCAL_PATH = "/usr/local/bin/" # On Mac and Linux systems
|
||||
DEFAULT_CHROMEDRIVER_VERSION = "72.0.3626.69" # (If can't find LATEST_STABLE)
|
||||
DEFAULT_GECKODRIVER_VERSION = "v0.33.0"
|
||||
DEFAULT_EDGEDRIVER_VERSION = "112.0.1722.58" # (If can't find LATEST_STABLE)
|
||||
DEFAULT_EDGEDRIVER_VERSION = "114.0.1823.82" # (If can't find LATEST_STABLE)
|
||||
DEFAULT_OPERADRIVER_VERSION = "v.96.0.4664.45"
|
||||
|
||||
|
||||
|
@ -86,8 +79,8 @@ def invalid_run_command():
|
|||
exp += " sbase get chromedriver\n"
|
||||
exp += " sbase get geckodriver\n"
|
||||
exp += " sbase get edgedriver\n"
|
||||
exp += " sbase get chromedriver 112\n"
|
||||
exp += " sbase get chromedriver 112.0.5615.49\n"
|
||||
exp += " sbase get chromedriver 114\n"
|
||||
exp += " sbase get chromedriver 114.0.5735.90\n"
|
||||
exp += " sbase get chromedriver latest\n"
|
||||
exp += " sbase get chromedriver latest-1\n"
|
||||
exp += " sbase get chromedriver -p\n"
|
||||
|
@ -124,6 +117,8 @@ def requests_get_with_retry(url):
|
|||
protocol = "http"
|
||||
user_and_pass = None
|
||||
if " --proxy=" in " ".join(sys.argv):
|
||||
from seleniumbase.core import proxy_helper
|
||||
|
||||
for arg in sys.argv:
|
||||
if arg.startswith("--proxy="):
|
||||
proxy_string = arg.split("--proxy=")[1]
|
||||
|
@ -144,7 +139,7 @@ def requests_get_with_retry(url):
|
|||
protocol = "socks4"
|
||||
elif "socks5" in proxy_string:
|
||||
protocol = "socks5"
|
||||
proxy_string = shared_utils.validate_proxy_string(proxy_string)
|
||||
proxy_string = proxy_helper.validate_proxy_string(proxy_string)
|
||||
if user_and_pass:
|
||||
proxy_string = "%s@%s" % (user_and_pass, proxy_string)
|
||||
use_proxy = True
|
||||
|
@ -155,8 +150,6 @@ def requests_get_with_retry(url):
|
|||
try:
|
||||
response = requests.get(url, proxies=proxies)
|
||||
except Exception:
|
||||
import time
|
||||
|
||||
time.sleep(0.75)
|
||||
response = requests.get(url, proxies=proxies)
|
||||
return response
|
||||
|
@ -164,8 +157,6 @@ def requests_get_with_retry(url):
|
|||
try:
|
||||
response = requests.get(url)
|
||||
except Exception:
|
||||
import time
|
||||
|
||||
time.sleep(0.75)
|
||||
response = requests.get(url)
|
||||
return response
|
||||
|
@ -220,7 +211,6 @@ def main(override=None, intel_for_uc=None):
|
|||
headless_ie_exists = False
|
||||
headless_ie_file_name = None
|
||||
downloads_folder = DRIVER_DIR
|
||||
sys_plat = sys.platform
|
||||
expected_contents = None
|
||||
platform_code = None
|
||||
inner_folder = None
|
||||
|
@ -236,7 +226,7 @@ def main(override=None, intel_for_uc=None):
|
|||
c4 = colorama.Fore.LIGHTRED_EX + colorama.Back.LIGHTWHITE_EX
|
||||
c5 = colorama.Fore.RED + colorama.Back.LIGHTWHITE_EX
|
||||
cr = colorama.Style.RESET_ALL
|
||||
if "linux" in sys_plat:
|
||||
if IS_LINUX:
|
||||
c1 = ""
|
||||
c2 = ""
|
||||
c3 = ""
|
||||
|
@ -292,7 +282,7 @@ def main(override=None, intel_for_uc=None):
|
|||
copy_to_path = True
|
||||
else:
|
||||
invalid_run_command()
|
||||
if "darwin" in sys_plat:
|
||||
if IS_MAC:
|
||||
if IS_ARM_MAC and not intel_for_uc:
|
||||
if use_version == "latest" or use_version == "latest-1":
|
||||
use_version = requests_get(last).text
|
||||
|
@ -306,7 +296,7 @@ def main(override=None, intel_for_uc=None):
|
|||
file_name = "chromedriver_mac_arm64.zip"
|
||||
else:
|
||||
file_name = "chromedriver_mac64.zip"
|
||||
elif "linux" in sys_plat:
|
||||
elif IS_LINUX:
|
||||
file_name = "chromedriver_linux64.zip"
|
||||
elif IS_WINDOWS:
|
||||
file_name = "chromedriver_win32.zip" # Works for win32 / win_x64
|
||||
|
@ -394,11 +384,10 @@ def main(override=None, intel_for_uc=None):
|
|||
copy_to_path = True
|
||||
else:
|
||||
invalid_run_command()
|
||||
if "darwin" in sys_plat:
|
||||
if IS_MAC:
|
||||
file_name = "geckodriver-%s-macos.tar.gz" % use_version
|
||||
elif "linux" in sys_plat:
|
||||
arch = platform.architecture()[0]
|
||||
if "64" in arch:
|
||||
elif IS_LINUX:
|
||||
if "64" in ARCH:
|
||||
file_name = "geckodriver-%s-linux64.tar.gz" % use_version
|
||||
else:
|
||||
file_name = "geckodriver-%s-linux32.tar.gz" % use_version
|
||||
|
@ -484,19 +473,19 @@ def main(override=None, intel_for_uc=None):
|
|||
else:
|
||||
use_version = DEFAULT_EDGEDRIVER_VERSION
|
||||
suffix = None
|
||||
if "win64" in sys_plat or "x64" in sys_plat:
|
||||
if IS_WINDOWS and "64" in ARCH:
|
||||
file_name = "edgedriver_win64.zip"
|
||||
suffix = "WINDOWS"
|
||||
elif "win32" in sys_plat or "x86" in sys_plat:
|
||||
elif IS_WINDOWS:
|
||||
file_name = "edgedriver_win32.zip"
|
||||
suffix = "WINDOWS"
|
||||
elif "darwin" in sys_plat:
|
||||
elif IS_MAC:
|
||||
if IS_ARM_MAC and int(use_version.split(".")[0]) > 104:
|
||||
file_name = "edgedriver_mac64_m1.zip"
|
||||
else:
|
||||
file_name = "edgedriver_mac64.zip"
|
||||
suffix = "MACOS"
|
||||
elif "linux" in sys_plat:
|
||||
elif IS_LINUX:
|
||||
file_name = "edgedriver_linux64.zip"
|
||||
suffix = "LINUX"
|
||||
else:
|
||||
|
@ -526,10 +515,10 @@ def main(override=None, intel_for_uc=None):
|
|||
major_version = "3.14"
|
||||
full_version = "3.14.0"
|
||||
use_version = full_version
|
||||
if "win32" in sys_plat:
|
||||
file_name = "IEDriverServer_Win32_%s.zip" % full_version
|
||||
elif "win64" in sys_plat or "x64" in sys_plat:
|
||||
if IS_WINDOWS and "64" in ARCH:
|
||||
file_name = "IEDriverServer_x64_%s.zip" % full_version
|
||||
elif IS_WINDOWS:
|
||||
file_name = "IEDriverServer_Win32_%s.zip" % full_version
|
||||
else:
|
||||
raise Exception(
|
||||
"Sorry! IEDriver is only for "
|
||||
|
@ -568,7 +557,7 @@ def main(override=None, intel_for_uc=None):
|
|||
copy_to_path = True
|
||||
else:
|
||||
invalid_run_command()
|
||||
if "darwin" in sys_plat:
|
||||
if IS_MAC:
|
||||
file_name = "operadriver_mac64.zip"
|
||||
platform_code = "mac64"
|
||||
inner_folder = "operadriver_%s/" % platform_code
|
||||
|
@ -577,7 +566,7 @@ def main(override=None, intel_for_uc=None):
|
|||
"operadriver_mac64/operadriver",
|
||||
"operadriver_mac64/sha512_sum",
|
||||
]
|
||||
elif "linux" in sys_plat:
|
||||
elif IS_LINUX:
|
||||
file_name = "operadriver_linux64.zip"
|
||||
platform_code = "linux64"
|
||||
inner_folder = "operadriver_%s/" % platform_code
|
||||
|
@ -586,16 +575,7 @@ def main(override=None, intel_for_uc=None):
|
|||
"operadriver_linux64/operadriver",
|
||||
"operadriver_linux64/sha512_sum",
|
||||
]
|
||||
elif "win32" in sys_plat:
|
||||
file_name = "operadriver_win32.zip"
|
||||
platform_code = "win32"
|
||||
inner_folder = "operadriver_%s/" % platform_code
|
||||
expected_contents = [
|
||||
"operadriver_win32/",
|
||||
"operadriver_win32/operadriver.exe",
|
||||
"operadriver_win32/sha512_sum",
|
||||
]
|
||||
elif "win64" in sys_plat or "x64" in sys_plat:
|
||||
elif IS_WINDOWS and "64" in ARCH:
|
||||
file_name = "operadriver_win64.zip"
|
||||
platform_code = "win64"
|
||||
inner_folder = "operadriver_%s/" % platform_code
|
||||
|
@ -604,6 +584,15 @@ def main(override=None, intel_for_uc=None):
|
|||
"operadriver_win64/operadriver.exe",
|
||||
"operadriver_win64/sha512_sum",
|
||||
]
|
||||
elif IS_WINDOWS:
|
||||
file_name = "operadriver_win32.zip"
|
||||
platform_code = "win32"
|
||||
inner_folder = "operadriver_%s/" % platform_code
|
||||
expected_contents = [
|
||||
"operadriver_win32/",
|
||||
"operadriver_win32/operadriver.exe",
|
||||
"operadriver_win32/sha512_sum",
|
||||
]
|
||||
else:
|
||||
raise Exception(
|
||||
"Cannot determine which version of Operadriver to download!"
|
||||
|
@ -743,7 +732,7 @@ def main(override=None, intel_for_uc=None):
|
|||
new_file = os.path.join(downloads_folder, str(f_name))
|
||||
if (
|
||||
intel_for_uc
|
||||
and "darwin" in sys_plat
|
||||
and IS_MAC
|
||||
and new_file.endswith("drivers/chromedriver")
|
||||
):
|
||||
new_file = new_file.replace(
|
||||
|
@ -806,7 +795,7 @@ def main(override=None, intel_for_uc=None):
|
|||
print("Also copied to: %s%s%s" % (c3, path_file, cr))
|
||||
print("")
|
||||
elif name == "edgedriver" or name == "msedgedriver":
|
||||
if "darwin" in sys_plat or "linux" in sys_plat:
|
||||
if IS_MAC or IS_LINUX:
|
||||
# Mac / Linux
|
||||
expected_contents = [
|
||||
"Driver_Notes/",
|
||||
|
@ -840,7 +829,7 @@ def main(override=None, intel_for_uc=None):
|
|||
# Remove existing version if exists
|
||||
str_name = str(f_name)
|
||||
new_file = os.path.join(downloads_folder, str_name)
|
||||
if "darwin" in sys_plat or "linux" in sys_plat:
|
||||
if IS_MAC or IS_LINUX:
|
||||
# Mac / Linux
|
||||
if str_name == "msedgedriver":
|
||||
driver_file = str_name
|
||||
|
|
|
@ -154,6 +154,8 @@ def main():
|
|||
w = 6
|
||||
if num_lines >= 1000:
|
||||
w = 7
|
||||
if num_lines >= 10000:
|
||||
w = 8
|
||||
|
||||
if is_python_file:
|
||||
new_sb_lines = []
|
||||
|
|
|
@ -20,6 +20,7 @@ import subprocess
|
|||
import sys
|
||||
from seleniumbase import config as sb_config
|
||||
from seleniumbase.fixtures import page_utils
|
||||
from seleniumbase.fixtures import shared_utils
|
||||
|
||||
sb_config.rec_subprocess_p = None
|
||||
sb_config.rec_subprocess_used = False
|
||||
|
@ -179,7 +180,7 @@ def do_playback(file_name, use_chrome, window, demo_mode=False):
|
|||
)
|
||||
return
|
||||
command = "%s -m pytest %s -q -s" % (sys.executable, file_name)
|
||||
if "linux" in sys.platform:
|
||||
if shared_utils.is_linux():
|
||||
command += " --gui"
|
||||
if not use_chrome:
|
||||
command += " --edge"
|
||||
|
@ -319,7 +320,7 @@ def end_program():
|
|||
|
||||
def main():
|
||||
use_colors = True
|
||||
if "linux" in sys.platform:
|
||||
if shared_utils.is_linux():
|
||||
use_colors = False
|
||||
c0, c1, c2, c3, c4, cr = set_colors(use_colors)
|
||||
message = ""
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import fasteners
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
|
@ -16,17 +15,17 @@ from selenium.webdriver.common.service import utils as service_utils
|
|||
from selenium.webdriver.edge.service import Service as EdgeService
|
||||
from selenium.webdriver.firefox.service import Service as FirefoxService
|
||||
from selenium.webdriver.safari.service import Service as SafariService
|
||||
from seleniumbase import drivers # webdriver storage folder for SeleniumBase
|
||||
from seleniumbase import extensions # browser extensions storage folder
|
||||
from seleniumbase.config import settings
|
||||
from seleniumbase.core import download_helper
|
||||
from seleniumbase.core import proxy_helper
|
||||
from seleniumbase.fixtures import constants
|
||||
from seleniumbase.fixtures import shared_utils
|
||||
from seleniumbase import drivers # webdriver storage folder for SeleniumBase
|
||||
from seleniumbase import extensions # browser extensions storage folder
|
||||
|
||||
urllib3.disable_warnings()
|
||||
selenium4_or_newer = False
|
||||
if sys.version_info[0] == 3 and sys.version_info[1] >= 7:
|
||||
if sys.version_info >= (3, 7):
|
||||
selenium4_or_newer = True
|
||||
from selenium.webdriver.common.options import ArgOptions
|
||||
|
||||
|
@ -52,16 +51,6 @@ PROXY_ZIP_PATH = proxy_helper.PROXY_ZIP_PATH
|
|||
PROXY_ZIP_LOCK = proxy_helper.PROXY_ZIP_LOCK
|
||||
PROXY_DIR_PATH = proxy_helper.PROXY_DIR_PATH
|
||||
PROXY_DIR_LOCK = proxy_helper.PROXY_DIR_LOCK
|
||||
PLATFORM = sys.platform
|
||||
IS_ARM_MAC = False
|
||||
if (
|
||||
"darwin" in PLATFORM
|
||||
and (
|
||||
"arm" in platform.processor().lower()
|
||||
or "arm64" in platform.version().lower()
|
||||
)
|
||||
):
|
||||
IS_ARM_MAC = True
|
||||
LOCAL_CHROMEDRIVER = None
|
||||
LOCAL_GECKODRIVER = None
|
||||
LOCAL_EDGEDRIVER = None
|
||||
|
@ -69,21 +58,17 @@ LOCAL_IEDRIVER = None
|
|||
LOCAL_HEADLESS_IEDRIVER = None
|
||||
LOCAL_OPERADRIVER = None
|
||||
LOCAL_UC_DRIVER = None
|
||||
IS_WINDOWS = False
|
||||
IS_LINUX = False
|
||||
IS_MAC = False
|
||||
if "darwin" in PLATFORM or "linux" in PLATFORM:
|
||||
IS_ARM_MAC = shared_utils.is_arm_mac()
|
||||
IS_MAC = shared_utils.is_mac()
|
||||
IS_LINUX = shared_utils.is_linux()
|
||||
IS_WINDOWS = shared_utils.is_windows()
|
||||
if IS_MAC or IS_LINUX:
|
||||
LOCAL_CHROMEDRIVER = DRIVER_DIR + "/chromedriver"
|
||||
LOCAL_GECKODRIVER = DRIVER_DIR + "/geckodriver"
|
||||
LOCAL_EDGEDRIVER = DRIVER_DIR + "/msedgedriver"
|
||||
LOCAL_OPERADRIVER = DRIVER_DIR + "/operadriver"
|
||||
LOCAL_UC_DRIVER = DRIVER_DIR + "/uc_driver"
|
||||
if "darwin" in PLATFORM:
|
||||
IS_MAC = True
|
||||
elif "linux" in PLATFORM:
|
||||
IS_LINUX = True
|
||||
elif "win32" in PLATFORM or "win64" in PLATFORM or "x64" in PLATFORM:
|
||||
IS_WINDOWS = True
|
||||
elif IS_WINDOWS:
|
||||
LOCAL_EDGEDRIVER = DRIVER_DIR + "/msedgedriver.exe"
|
||||
LOCAL_IEDRIVER = DRIVER_DIR + "/IEDriverServer.exe"
|
||||
LOCAL_HEADLESS_IEDRIVER = DRIVER_DIR + "/headless_ie_selenium.exe"
|
||||
|
@ -1128,7 +1113,7 @@ def get_driver(
|
|||
"that has authentication! (If using a proxy server "
|
||||
"without auth, Chrome, Edge, or Firefox may be used.)"
|
||||
)
|
||||
proxy_string = shared_utils.validate_proxy_string(proxy_string)
|
||||
proxy_string = proxy_helper.validate_proxy_string(proxy_string)
|
||||
if proxy_string and proxy_user and proxy_pass:
|
||||
proxy_auth = True
|
||||
elif proxy_pac_url:
|
||||
|
|
|
@ -9,16 +9,15 @@ def _analyze_ast(contents):
|
|||
except SyntaxError:
|
||||
pass
|
||||
try:
|
||||
# remove all comments
|
||||
# Remove all comments
|
||||
contents = re.sub(re.compile(r"/\*.*?\*/", re.DOTALL), "", contents)
|
||||
contents = re.sub(re.compile(r"#.*?\n"), "", contents)
|
||||
|
||||
# remove anything before dict declaration like: "caps = { ..."
|
||||
# Remove anything before dict declaration like: "caps = { ..."
|
||||
match = re.match(r"^([^{]+)", contents)
|
||||
if match:
|
||||
contents = contents.replace(match.group(1), "")
|
||||
|
||||
# and try again
|
||||
return ast.literal_eval(contents)
|
||||
except SyntaxError:
|
||||
pass
|
||||
|
|
|
@ -49,12 +49,11 @@ PATTERN = {
|
|||
|
||||
|
||||
def os_name():
|
||||
pl = sys.platform
|
||||
if pl == "linux" or pl == "linux2":
|
||||
if "linux" in sys.platform:
|
||||
return OSType.LINUX
|
||||
elif pl == "darwin":
|
||||
elif "darwin" in sys.platform:
|
||||
return OSType.MAC
|
||||
elif pl == "win32":
|
||||
elif "win32" in sys.platform:
|
||||
return OSType.WIN
|
||||
else:
|
||||
raise Exception("Could not determine the OS type!")
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
"""
|
||||
This module contains methods for opening jquery-confirm boxes.
|
||||
These helper methods SHOULD NOT be called directly from tests.
|
||||
"""
|
||||
"""This module contains methods for opening jquery-confirm boxes.
|
||||
These helper methods SHOULD NOT be called directly from tests."""
|
||||
from seleniumbase.fixtures import constants
|
||||
from seleniumbase.fixtures import js_utils
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""Wrapper for MySQL DB functions."""
|
||||
"""Wrapper for MySQL DB functions"""
|
||||
|
||||
|
||||
class DatabaseManager:
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import os
|
||||
import re
|
||||
import warnings
|
||||
import zipfile
|
||||
from seleniumbase.config import proxy_list
|
||||
from seleniumbase.config import settings
|
||||
from seleniumbase.fixtures import constants
|
||||
from seleniumbase.fixtures import page_utils
|
||||
|
||||
DOWNLOADS_DIR = constants.Files.DOWNLOADS_FOLDER
|
||||
PROXY_ZIP_PATH = os.path.join(DOWNLOADS_DIR, "proxy.zip")
|
||||
|
@ -131,3 +136,63 @@ def remove_proxy_zip_if_present():
|
|||
os.remove(PROXY_ZIP_LOCK)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def validate_proxy_string(proxy_string):
|
||||
if proxy_string in proxy_list.PROXY_LIST.keys():
|
||||
proxy_string = proxy_list.PROXY_LIST[proxy_string]
|
||||
if not proxy_string:
|
||||
return None
|
||||
valid = False
|
||||
val_ip = re.match(
|
||||
r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$", proxy_string
|
||||
)
|
||||
if not val_ip:
|
||||
if proxy_string.startswith("http://"):
|
||||
proxy_string = proxy_string.split("http://")[1]
|
||||
elif proxy_string.startswith("https://"):
|
||||
proxy_string = proxy_string.split("https://")[1]
|
||||
elif "://" in proxy_string:
|
||||
if not proxy_string.startswith("socks4://") and not (
|
||||
proxy_string.startswith("socks5://")
|
||||
):
|
||||
proxy_string = proxy_string.split("://")[1]
|
||||
chunks = proxy_string.split(":")
|
||||
if len(chunks) == 2:
|
||||
if re.match(r"^\d+$", chunks[1]):
|
||||
if page_utils.is_valid_url("http://" + proxy_string):
|
||||
valid = True
|
||||
elif len(chunks) == 3:
|
||||
if re.match(r"^\d+$", chunks[2]):
|
||||
if page_utils.is_valid_url("http:" + ":".join(chunks[1:])):
|
||||
if chunks[0] == "http":
|
||||
valid = True
|
||||
elif chunks[0] == "https":
|
||||
valid = True
|
||||
elif chunks[0] == "socks4":
|
||||
valid = True
|
||||
elif chunks[0] == "socks5":
|
||||
valid = True
|
||||
else:
|
||||
proxy_string = val_ip.group()
|
||||
valid = True
|
||||
if not valid:
|
||||
__display_proxy_warning(proxy_string)
|
||||
proxy_string = None
|
||||
return proxy_string
|
||||
|
||||
|
||||
def __display_proxy_warning(proxy_string):
|
||||
message = (
|
||||
'\nWARNING: Proxy String ["%s"] is NOT in the expected '
|
||||
'"ip_address:port" or "server:port" format, '
|
||||
"(OR the key does not exist in "
|
||||
"seleniumbase.config.proxy_list.PROXY_LIST)." % proxy_string
|
||||
)
|
||||
if settings.RAISE_INVALID_PROXY_STRING_EXCEPTION:
|
||||
raise Exception(message)
|
||||
else:
|
||||
message += " *** DEFAULTING to NOT USING a Proxy Server! ***"
|
||||
warnings.simplefilter("always", Warning) # See Warnings
|
||||
warnings.warn(message, category=Warning, stacklevel=2)
|
||||
warnings.simplefilter("default", Warning) # Set Default
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""Generating SeleniumBase Python code from the Recorder."""
|
||||
"""Generating SeleniumBase Python code from the Recorder"""
|
||||
|
||||
|
||||
def generate_sbase_code(srt_actions):
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
import sys
|
||||
from seleniumbase import config as sb_config
|
||||
|
||||
is_windows = False
|
||||
if sys.platform in ["win32", "win64", "x64"]:
|
||||
is_windows = True
|
||||
from seleniumbase.fixtures import shared_utils
|
||||
|
||||
|
||||
def end_reused_class_session_as_needed():
|
||||
|
@ -14,7 +10,7 @@ def end_reused_class_session_as_needed():
|
|||
and sb_config.shared_driver
|
||||
):
|
||||
if (
|
||||
not is_windows
|
||||
not shared_utils.is_windows()
|
||||
or (
|
||||
hasattr(sb_config.shared_driver, "service")
|
||||
and sb_config.shared_driver.service.process
|
||||
|
|
|
@ -87,9 +87,7 @@ logging.getLogger("requests").setLevel(logging.ERROR)
|
|||
logging.getLogger("urllib3").setLevel(logging.ERROR)
|
||||
urllib3.disable_warnings()
|
||||
LOGGER.setLevel(logging.WARNING)
|
||||
is_windows = False
|
||||
if sys.platform in ["win32", "win64", "x64"]:
|
||||
is_windows = True
|
||||
is_windows = shared_utils.is_windows()
|
||||
python3_11_or_newer = False
|
||||
if sys.version_info >= (3, 11):
|
||||
python3_11_or_newer = True
|
||||
|
@ -13676,11 +13674,9 @@ class BaseCase(unittest.TestCase):
|
|||
)
|
||||
from seleniumbase.core.testcase_manager import (
|
||||
ExecutionQueryPayload,
|
||||
)
|
||||
from seleniumbase.core.testcase_manager import (
|
||||
TestcaseDataPayload,
|
||||
TestcaseManager,
|
||||
)
|
||||
from seleniumbase.core.testcase_manager import TestcaseManager
|
||||
|
||||
self.execution_guid = str(uuid.uuid4())
|
||||
self.testcase_guid = None
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""SeleniumBase constants are stored in this file."""
|
||||
"""SeleniumBase constants"""
|
||||
from seleniumbase.core import encoded_images
|
||||
|
||||
|
||||
|
|
|
@ -6,8 +6,7 @@ class ConvertibleToCssTranslator(GenericTranslator):
|
|||
"""An implementation of :py:class:`cssselect.GenericTranslator` with
|
||||
XPath output that more readily converts back to CSS selectors.
|
||||
The simplified examples in https://devhints.io/xpath were used as a
|
||||
reference here.
|
||||
"""
|
||||
reference here."""
|
||||
|
||||
def css_to_xpath(self, css, prefix="//"):
|
||||
return super().css_to_xpath(css, prefix)
|
||||
|
|
|
@ -1,28 +1,23 @@
|
|||
"""
|
||||
SeleniumBase MySQL-related exceptions.
|
||||
"""SeleniumBase MySQL-related exceptions.
|
||||
|
||||
This feature is DEPRECATED!
|
||||
Use self.skip() for skipping tests!
|
||||
|
||||
Raising one of these in a test will cause the
|
||||
test-state to be logged appropriately in the DB
|
||||
for tests that use the SeleniumBase MySQL option.
|
||||
"""
|
||||
for tests that use the SeleniumBase MySQL option."""
|
||||
|
||||
|
||||
class BlockedTest(Exception):
|
||||
"""Raise this to mark a test as Blocked in the DB."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class SkipTest(Exception):
|
||||
"""Raise this to mark a test as Skipped in the DB."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class DeprecatedTest(Exception):
|
||||
"""Raise this to mark a test as Deprecated in the DB."""
|
||||
|
||||
pass
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
"""
|
||||
This module contains useful Javascript utility methods for base_case.py
|
||||
These helper methods SHOULD NOT be called directly from tests.
|
||||
"""
|
||||
"""This module contains useful Javascript utility methods for BaseCase."""
|
||||
import re
|
||||
import requests
|
||||
import time
|
||||
|
@ -13,16 +10,14 @@ from seleniumbase.fixtures import constants
|
|||
|
||||
|
||||
def wait_for_ready_state_complete(driver, timeout=settings.LARGE_TIMEOUT):
|
||||
"""
|
||||
The DOM (Document Object Model) has a property called "readyState".
|
||||
"""The DOM (Document Object Model) has a property called "readyState".
|
||||
When the value of this becomes "complete", page resources are considered
|
||||
fully loaded (although AJAX and other loads might still be happening).
|
||||
This method will wait until document.readyState == "complete".
|
||||
This may be redundant, as methods already wait for page elements to load.
|
||||
If the timeout is exceeded, the test will still continue
|
||||
because readyState == "interactive" may be good enough.
|
||||
(Previously, tests would fail immediately if exceeding the timeout.)
|
||||
"""
|
||||
(Previously, tests would fail immediately if exceeding the timeout.)"""
|
||||
if hasattr(settings, "SKIP_JS_WAITS") and settings.SKIP_JS_WAITS:
|
||||
return
|
||||
if sb_config.time_limit and not sb_config.recorder_mode:
|
||||
|
@ -157,8 +152,8 @@ def raise_unable_to_load_jquery_exception(driver):
|
|||
|
||||
|
||||
def activate_jquery(driver):
|
||||
"""If "jQuery is not defined" on a website, use this method to activate it.
|
||||
This method is needed because jQuery is not always defined on web sites."""
|
||||
# If "jQuery is not defined" on a website, use this method to activate it.
|
||||
# This method is needed because jQuery is not always defined on web sites.
|
||||
try:
|
||||
# Let's first find out if jQuery is already defined.
|
||||
driver.execute_script("jQuery('html');")
|
||||
|
@ -191,8 +186,7 @@ def are_quotes_escaped(string):
|
|||
|
||||
|
||||
def escape_quotes_if_needed(string):
|
||||
"""
|
||||
re.escape() works differently in Python 3.7.0 than earlier versions:
|
||||
"""re.escape() works differently in Python 3.7.0 than earlier versions:
|
||||
|
||||
Python 3.6.5:
|
||||
>>> import re
|
||||
|
@ -215,10 +209,8 @@ def escape_quotes_if_needed(string):
|
|||
|
||||
|
||||
def is_in_frame(driver):
|
||||
"""
|
||||
Returns True if the driver has switched to a frame.
|
||||
Returns False if the driver was on default content.
|
||||
"""
|
||||
# Returns True if the driver has switched to a frame.
|
||||
# Returns False if the driver was on default content.
|
||||
in_basic_frame = driver.execute_script(
|
||||
"""
|
||||
var frame = window.frameElement;
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
"""
|
||||
This module contains a set of methods that can be used for page loads and
|
||||
for waiting for elements to appear on a page.
|
||||
"""This module contains useful methods for waiting on elements to load.
|
||||
|
||||
These methods improve on and expand existing WebDriver commands.
|
||||
These methods improve and expand on existing WebDriver commands.
|
||||
Improvements include making WebDriver commands more robust and more reliable
|
||||
by giving page elements enough time to load before taking action on them.
|
||||
|
||||
The default option for searching for elements is by CSS Selector.
|
||||
The default option for searching for elements is by "css selector".
|
||||
This can be changed by overriding the "By" parameter from this import:
|
||||
> from selenium.webdriver.common.by import By
|
||||
Options are:
|
||||
|
@ -19,7 +17,6 @@ By.XPATH # "xpath"
|
|||
By.TAG_NAME # "tag name"
|
||||
By.PARTIAL_LINK_TEXT # "partial link text"
|
||||
"""
|
||||
|
||||
import codecs
|
||||
import os
|
||||
import time
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""This module contains useful utility methods."""
|
||||
"""This module contains useful utility methods"""
|
||||
import codecs
|
||||
import fasteners
|
||||
import os
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
"""Shared utility methods."""
|
||||
import subprocess
|
||||
"""Shared utility methods"""
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
from seleniumbase.config import settings
|
||||
from seleniumbase.fixtures import constants
|
||||
import time
|
||||
from seleniumbase import config as sb_config
|
||||
from seleniumbase.fixtures import constants
|
||||
|
||||
|
||||
def pip_install(package, version=None):
|
||||
import fasteners
|
||||
import subprocess
|
||||
|
||||
pip_install_lock = fasteners.InterProcessLock(
|
||||
constants.PipInstall.LOCKFILE
|
||||
|
@ -24,17 +26,30 @@ def pip_install(package, version=None):
|
|||
)
|
||||
|
||||
|
||||
def is_arm_mac():
|
||||
"""(M1 / M2 Macs use the ARM processor)"""
|
||||
return (
|
||||
"darwin" in sys.platform
|
||||
and (
|
||||
"arm" in platform.processor().lower()
|
||||
or "arm64" in platform.version().lower()
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def is_mac():
|
||||
return "darwin" in sys.platform
|
||||
|
||||
|
||||
def is_linux():
|
||||
return "linux" in sys.platform
|
||||
|
||||
|
||||
def is_windows():
|
||||
platform = sys.platform
|
||||
if "win32" in platform or "win64" in platform or "x64" in platform:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
return "win32" in sys.platform
|
||||
|
||||
|
||||
def get_terminal_width():
|
||||
import os
|
||||
|
||||
width = 80 # default
|
||||
try:
|
||||
width = os.get_terminal_size().columns
|
||||
|
@ -48,72 +63,6 @@ def get_terminal_width():
|
|||
return width
|
||||
|
||||
|
||||
def display_proxy_warning(proxy_string):
|
||||
import warnings
|
||||
|
||||
message = (
|
||||
'\nWARNING: Proxy String ["%s"] is NOT in the expected '
|
||||
'"ip_address:port" or "server:port" format, '
|
||||
"(OR the key does not exist in "
|
||||
"seleniumbase.config.proxy_list.PROXY_LIST)." % proxy_string
|
||||
)
|
||||
if settings.RAISE_INVALID_PROXY_STRING_EXCEPTION:
|
||||
raise Exception(message)
|
||||
else:
|
||||
message += " *** DEFAULTING to NOT USING a Proxy Server! ***"
|
||||
warnings.simplefilter("always", Warning) # See Warnings
|
||||
warnings.warn(message, category=Warning, stacklevel=2)
|
||||
warnings.simplefilter("default", Warning) # Set Default
|
||||
|
||||
|
||||
def validate_proxy_string(proxy_string):
|
||||
import re
|
||||
from seleniumbase.config import proxy_list
|
||||
from seleniumbase.fixtures import page_utils
|
||||
|
||||
if proxy_string in proxy_list.PROXY_LIST.keys():
|
||||
proxy_string = proxy_list.PROXY_LIST[proxy_string]
|
||||
if not proxy_string:
|
||||
return None
|
||||
valid = False
|
||||
val_ip = re.match(
|
||||
r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$", proxy_string
|
||||
)
|
||||
if not val_ip:
|
||||
if proxy_string.startswith("http://"):
|
||||
proxy_string = proxy_string.split("http://")[1]
|
||||
elif proxy_string.startswith("https://"):
|
||||
proxy_string = proxy_string.split("https://")[1]
|
||||
elif "://" in proxy_string:
|
||||
if not proxy_string.startswith("socks4://") and not (
|
||||
proxy_string.startswith("socks5://")
|
||||
):
|
||||
proxy_string = proxy_string.split("://")[1]
|
||||
chunks = proxy_string.split(":")
|
||||
if len(chunks) == 2:
|
||||
if re.match(r"^\d+$", chunks[1]):
|
||||
if page_utils.is_valid_url("http://" + proxy_string):
|
||||
valid = True
|
||||
elif len(chunks) == 3:
|
||||
if re.match(r"^\d+$", chunks[2]):
|
||||
if page_utils.is_valid_url("http:" + ":".join(chunks[1:])):
|
||||
if chunks[0] == "http":
|
||||
valid = True
|
||||
elif chunks[0] == "https":
|
||||
valid = True
|
||||
elif chunks[0] == "socks4":
|
||||
valid = True
|
||||
elif chunks[0] == "socks5":
|
||||
valid = True
|
||||
else:
|
||||
proxy_string = val_ip.group()
|
||||
valid = True
|
||||
if not valid:
|
||||
display_proxy_warning(proxy_string)
|
||||
proxy_string = None
|
||||
return proxy_string
|
||||
|
||||
|
||||
def format_exc(exception, message):
|
||||
"""Formats an exception message to make the output cleaner."""
|
||||
from selenium.common.exceptions import ElementNotVisibleException
|
||||
|
@ -198,8 +147,6 @@ def check_if_time_limit_exceeded():
|
|||
and sb_config.time_limit
|
||||
and not sb_config.recorder_mode
|
||||
):
|
||||
import time
|
||||
|
||||
time_limit = sb_config.time_limit
|
||||
now_ms = int(time.time() * 1000)
|
||||
if now_ms > sb_config.start_time_ms + sb_config.time_limit_ms:
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
Convert XPath selectors into CSS selectors
|
||||
"""
|
||||
"""Convert XPath selectors into CSS selectors"""
|
||||
import re
|
||||
|
||||
_sub_regexes = {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""The Nosetest plugin for setting base configuration and logging."""
|
||||
"""Base Plugin for SeleniumBase tests that run with pynose / nosetests"""
|
||||
import ast
|
||||
import sys
|
||||
import time
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""The plugin for saving basic test info for Selenium tests."""
|
||||
"""Test Info Plugin for SeleniumBase tests that run with pynose / nosetests"""
|
||||
import os
|
||||
import codecs
|
||||
import time
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""The plugin for recording test results in the Testcase Database."""
|
||||
"""DB Reporting Plugin for SeleniumBase tests that use pynose / nosetests"""
|
||||
import time
|
||||
import uuid
|
||||
from nose.plugins import Plugin
|
||||
|
@ -76,7 +76,7 @@ class DBReporting(Plugin):
|
|||
self.testcase_manager.insert_execution_data(exec_payload)
|
||||
|
||||
def startTest(self, test):
|
||||
"""At the start of the test, set the testcase details."""
|
||||
"""At the start of the test, set testcase details."""
|
||||
from seleniumbase.core.application_manager import ApplicationManager
|
||||
from seleniumbase.core.testcase_manager import TestcaseDataPayload
|
||||
|
||||
|
|
|
@ -111,6 +111,7 @@ def Driver(
|
|||
pls=None, # Shortcut / Duplicate of "page_load_strategy".
|
||||
):
|
||||
from seleniumbase.fixtures import constants
|
||||
from seleniumbase.fixtures import shared_utils
|
||||
|
||||
sys_argv = sys.argv
|
||||
browser_changes = 0
|
||||
|
@ -251,7 +252,7 @@ def Driver(
|
|||
recorder_mode = True
|
||||
recorder_ext = True
|
||||
if (
|
||||
"linux" in sys.platform
|
||||
shared_utils.is_linux()
|
||||
and not headed
|
||||
and not headless
|
||||
and not headless2
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""The plugin for capturing & storing the page source on errors & failures."""
|
||||
"""PageSource Plugin for SeleniumBase tests that run with pynose / nosetests"""
|
||||
import os
|
||||
import codecs
|
||||
from nose.plugins import Plugin
|
||||
|
@ -7,7 +7,7 @@ from seleniumbase.core import log_helper
|
|||
|
||||
|
||||
class PageSource(Plugin):
|
||||
"""Capture the page source when a test fails or raises an error."""
|
||||
"""Capture the page source after a test fails."""
|
||||
name = "page_source" # Usage: --with-page_source
|
||||
logfile_name = settings.PAGE_SOURCE_NAME
|
||||
|
||||
|
@ -24,7 +24,6 @@ class PageSource(Plugin):
|
|||
try:
|
||||
page_source = test.driver.page_source
|
||||
except Exception:
|
||||
# Since we can't get the page source from here, skip saving it
|
||||
return
|
||||
test_logpath = self.options.log_path + "/" + test.id()
|
||||
if not os.path.exists(test_logpath):
|
||||
|
@ -41,7 +40,6 @@ class PageSource(Plugin):
|
|||
try:
|
||||
page_source = test.driver.page_source
|
||||
except Exception:
|
||||
# Since we can't get the page source from here, don't save it.
|
||||
return
|
||||
test_logpath = self.options.log_path + "/" + test.id()
|
||||
if not os.path.exists(test_logpath):
|
||||
|
|
|
@ -8,10 +8,8 @@ from seleniumbase import config as sb_config
|
|||
from seleniumbase.config import settings
|
||||
from seleniumbase.core import log_helper
|
||||
from seleniumbase.fixtures import constants
|
||||
from seleniumbase.fixtures import shared_utils
|
||||
|
||||
is_windows = False
|
||||
if sys.platform in ["win32", "win64", "x64"]:
|
||||
is_windows = True
|
||||
python3_11_or_newer = False
|
||||
if sys.version_info >= (3, 11):
|
||||
python3_11_or_newer = True
|
||||
|
@ -99,8 +97,8 @@ def pytest_addoption(parser):
|
|||
--incognito (Enable Chrome's Incognito mode.)
|
||||
--guest (Enable Chrome's Guest mode.)
|
||||
--devtools (Open Chrome's DevTools when the browser opens.)
|
||||
--reuse-session | --rs (Reuse browser session for all tests.)
|
||||
--reuse-class-session | --rcs (Reuse session for tests in class.)
|
||||
--rs | --reuse-session (Reuse browser session for all tests.)
|
||||
--rcs | --reuse-class-session (Reuse session for tests in class.)
|
||||
--crumbs (Delete all cookies between tests reusing a session.)
|
||||
--disable-beforeunload (Disable the "beforeunload" event on Chrome.)
|
||||
--window-size=WIDTH,HEIGHT (Set the browser's starting window size.)
|
||||
|
@ -1854,7 +1852,10 @@ def pytest_runtest_teardown(item):
|
|||
and self.driver
|
||||
and "--pdb" not in sys_argv
|
||||
):
|
||||
if not is_windows or self.driver.service.process:
|
||||
if not (
|
||||
shared_utils.is_windows()
|
||||
or self.driver.service.process
|
||||
):
|
||||
self.driver.quit()
|
||||
except Exception:
|
||||
pass
|
||||
|
@ -1864,7 +1865,7 @@ def pytest_runtest_teardown(item):
|
|||
):
|
||||
try:
|
||||
if (
|
||||
not is_windows
|
||||
not shared_utils.is_windows()
|
||||
or sb_config._sb_pdb_driver.service.process
|
||||
):
|
||||
sb_config._sb_pdb_driver.quit()
|
||||
|
@ -1982,7 +1983,7 @@ def _perform_pytest_unconfigure_():
|
|||
if sb_config.shared_driver:
|
||||
try:
|
||||
if (
|
||||
not is_windows
|
||||
not shared_utils.is_windows()
|
||||
or sb_config.browser == "ie"
|
||||
or sb_config.shared_driver.service.process
|
||||
):
|
||||
|
|
|
@ -329,11 +329,11 @@ def SB(
|
|||
record_sleep = True
|
||||
else:
|
||||
record_sleep = False
|
||||
if "linux" not in sys.platform:
|
||||
if not shared_utils.is_linux():
|
||||
# The Xvfb virtual display server is for Linux OS Only!
|
||||
xvfb = False
|
||||
if (
|
||||
"linux" in sys.platform
|
||||
shared_utils.is_linux()
|
||||
and not headed
|
||||
and not headless
|
||||
and not headless2
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
"""The screenshot plugin for selenium tests that run with nosetests."""
|
||||
"""Screenshot Plugin for SeleniumBase tests that run with pynose / nosetests"""
|
||||
import os
|
||||
from nose.plugins import Plugin
|
||||
from seleniumbase.config import settings
|
||||
|
||||
|
||||
class ScreenShots(Plugin):
|
||||
"""This plugin takes a screenshot when a test fails or raises an error."""
|
||||
"""This plugin takes a screenshot when a test fails."""
|
||||
name = "screen_shots"
|
||||
logfile_name = settings.SCREENSHOT_NAME
|
||||
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
"""The Nosetest plugin for setting Selenium test configuration."""
|
||||
"""Selenium Plugin for SeleniumBase tests that run with pynose / nosetests"""
|
||||
import sys
|
||||
from nose.plugins import Plugin
|
||||
from seleniumbase import config as sb_config
|
||||
from seleniumbase.config import settings
|
||||
from seleniumbase.core import proxy_helper
|
||||
from seleniumbase.fixtures import constants
|
||||
|
||||
is_windows = False
|
||||
if sys.platform in ["win32", "win64", "x64"]:
|
||||
is_windows = True
|
||||
from seleniumbase.fixtures import shared_utils
|
||||
|
||||
|
||||
class SeleniumBrowser(Plugin):
|
||||
|
@ -1150,7 +1147,7 @@ class SeleniumBrowser(Plugin):
|
|||
if str(self.options.port) == "443":
|
||||
test.test.protocol = "https"
|
||||
if (
|
||||
"linux" in sys.platform
|
||||
shared_utils.is_linux()
|
||||
and not self.options.headed
|
||||
and not self.options.headless
|
||||
and not self.options.headless2
|
||||
|
@ -1198,7 +1195,7 @@ class SeleniumBrowser(Plugin):
|
|||
sb_config.headless_active = False
|
||||
self.headless_active = False
|
||||
if (
|
||||
"linux" in sys.platform
|
||||
shared_utils.is_linux()
|
||||
and (not self.options.headed or self.options.xvfb)
|
||||
):
|
||||
width = settings.HEADLESS_START_WIDTH
|
||||
|
@ -1235,7 +1232,7 @@ class SeleniumBrowser(Plugin):
|
|||
try:
|
||||
# If the browser window is still open, close it now.
|
||||
if (
|
||||
not is_windows
|
||||
not shared_utils.is_windows()
|
||||
or test.test.browser == "ie"
|
||||
or self.driver.service.process
|
||||
):
|
||||
|
|
|
@ -27,7 +27,6 @@ Output:
|
|||
(Example: Translating "test_1.py" into Japanese with
|
||||
"-c" will create a new file called "test_1_ja.py".)
|
||||
"""
|
||||
|
||||
import codecs
|
||||
import colorama
|
||||
import os
|
||||
|
@ -551,6 +550,9 @@ def main():
|
|||
save_line = save_line.replace("]]]", cr + "")
|
||||
|
||||
if print_only:
|
||||
from rich.console import Console
|
||||
from rich.syntax import Syntax
|
||||
|
||||
console_width = None # width of console output when running script
|
||||
used_width = None # code_width and few spaces on right for padding
|
||||
magic_console = None
|
||||
|
@ -562,438 +564,437 @@ def main():
|
|||
except Exception:
|
||||
console_width = None
|
||||
|
||||
if sys.version_info[0] == 3 and sys.version_info[1] >= 6:
|
||||
from rich.console import Console
|
||||
from rich.syntax import Syntax
|
||||
python_code = "\n".join(seleniumbase_lines)
|
||||
code_width = 1
|
||||
|
||||
python_code = "\n".join(seleniumbase_lines)
|
||||
code_width = 1
|
||||
w = 0 # line number whitespace
|
||||
if line_numbers:
|
||||
w = 4
|
||||
num_lines = len(code_lines)
|
||||
if num_lines >= 10:
|
||||
w = 5
|
||||
if num_lines >= 100:
|
||||
w = 6
|
||||
if num_lines >= 1000:
|
||||
w = 7
|
||||
if num_lines >= 10000:
|
||||
w = 8
|
||||
|
||||
w = 0 # line number whitespace
|
||||
if line_numbers:
|
||||
w = 4
|
||||
num_lines = len(code_lines)
|
||||
if num_lines >= 10:
|
||||
w = 5
|
||||
if num_lines >= 100:
|
||||
w = 6
|
||||
if num_lines >= 1000:
|
||||
w = 7
|
||||
new_sb_lines = []
|
||||
for line in seleniumbase_lines:
|
||||
if line.endswith(" # noqa") and line.count(" # noqa") == 1:
|
||||
line = line.replace(" # noqa", "")
|
||||
line_length2 = len(line) # Normal Python string length used
|
||||
line_length = get_width(line) # Special characters count 2X
|
||||
if line_length > code_width:
|
||||
code_width = line_length
|
||||
|
||||
new_sb_lines = []
|
||||
for line in seleniumbase_lines:
|
||||
if line.endswith(" # noqa") and line.count(" # noqa") == 1:
|
||||
line = line.replace(" # noqa", "")
|
||||
line_length2 = len(line) # Normal Python string length used
|
||||
line_length = get_width(line) # Special characters count 2X
|
||||
if line_length > code_width:
|
||||
code_width = line_length
|
||||
|
||||
if console_width:
|
||||
# If line is larger than console_width, try to optimize it.
|
||||
# Smart Python word wrap to be used with valid indentation.
|
||||
if line_length + w > console_width: # 5 is line number ws
|
||||
if line.strip().startswith("#"):
|
||||
new_sb_lines.append(line)
|
||||
continue
|
||||
elif (
|
||||
line.count(" # ") == 1
|
||||
and get_width(line.split(" # ")[0]) + w
|
||||
<= console_width
|
||||
):
|
||||
# Line is short enough once comment is removed
|
||||
line = line.split(" # ")[0]
|
||||
new_sb_lines.append(line)
|
||||
continue
|
||||
elif (
|
||||
line.count(" # ") == 1
|
||||
and get_width(line.split(" # ")[0]) + w
|
||||
<= console_width
|
||||
):
|
||||
# L-Length good if removing bad flake8 comment
|
||||
line = line.split(" # ")[0]
|
||||
new_sb_lines.append(line)
|
||||
continue
|
||||
if line.startswith("from") and " import " in line:
|
||||
line1 = line.split(" import ")[0] + " \\"
|
||||
line2 = " import " + line.split(" import ")[1]
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if line.count("(") == 1 and line.count(")") == 1:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split("(")[0] + "("
|
||||
line2 = new_ws + line.split("(")[1]
|
||||
if not ("):") in line2:
|
||||
new_sb_lines.append(line1)
|
||||
if get_width(line2) + w > console_width:
|
||||
if line2.count('", "') == 1:
|
||||
line2a = line2.split('", "')[0] + '",'
|
||||
line2b = (
|
||||
new_ws
|
||||
+ '"'
|
||||
+ (line2.split('", "')[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
elif line2.count("', '") == 1:
|
||||
line2a = line2.split("', '")[0] + "',"
|
||||
line2b = (
|
||||
new_ws
|
||||
+ "'"
|
||||
+ (line2.split("', '")[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
elif line2.count("://") == 1 and (
|
||||
line2.count('")') == 1
|
||||
):
|
||||
line2a = line2.split("://")[0] + '://"'
|
||||
line2b = (
|
||||
new_ws
|
||||
+ '"'
|
||||
+ (line2.split("://")[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
if get_width(line2b) + w > (
|
||||
console_width
|
||||
):
|
||||
if line2b.count("/") > 0:
|
||||
slash_one = line2b.find("/")
|
||||
slash_one_p1 = slash_one + 1
|
||||
line2b1 = (
|
||||
line2b[:slash_one_p1] + '"'
|
||||
)
|
||||
line2b2 = (
|
||||
new_ws
|
||||
+ '"'
|
||||
+ (line2b[slash_one_p1:])
|
||||
)
|
||||
new_sb_lines.append(line2b1)
|
||||
if line2b2.count(") # ") == 1:
|
||||
line2b2 = (
|
||||
line2b2.split(") # ")[
|
||||
0
|
||||
]
|
||||
+ ")"
|
||||
)
|
||||
new_sb_lines.append(line2b2)
|
||||
continue
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
elif line2.count("://") == 1 and (
|
||||
line2.count("')") == 1
|
||||
):
|
||||
line2a = line2.split("://")[0] + "://'"
|
||||
line2b = (
|
||||
new_ws
|
||||
+ "'"
|
||||
+ (line2.split("://")[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
if get_width(line2b) + w > (
|
||||
console_width
|
||||
):
|
||||
if line2b.count("/") > 0:
|
||||
slash_one = line2b.find("/")
|
||||
slash_one_p1 = slash_one + 1
|
||||
line2b1 = (
|
||||
line2b[:slash_one_p1] + "'"
|
||||
)
|
||||
line2b2 = (
|
||||
new_ws
|
||||
+ "'"
|
||||
+ (line2b[slash_one_p1:])
|
||||
)
|
||||
new_sb_lines.append(line2b1)
|
||||
if line2b2.count(") # ") == 1:
|
||||
line2b2 = (
|
||||
line2b2.split(") # ")[
|
||||
0
|
||||
]
|
||||
+ ")"
|
||||
)
|
||||
new_sb_lines.append(line2b2)
|
||||
continue
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
elif line2.count(", ") == 1:
|
||||
line2a = line2.split(", ")[0] + ","
|
||||
line2b = new_ws + (
|
||||
line2.split(", ")[1]
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
elif line2.count('="') == 1 and (
|
||||
line2.lstrip().startswith("'")
|
||||
):
|
||||
line2a = line2.split('="')[0] + "='"
|
||||
line2b = (
|
||||
new_ws
|
||||
+ "'\""
|
||||
+ (line2.split('="')[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
elif line2.count("='") == 1 and (
|
||||
line2.lstrip().startswith('"')
|
||||
):
|
||||
line2a = line2.split("='")[0] + '="'
|
||||
line2b = (
|
||||
new_ws
|
||||
+ "\"'"
|
||||
+ (line2.split("='")[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
new_sb_lines.append(line2)
|
||||
elif get_width(line2) + 4 + w <= console_width:
|
||||
line2 = " " + line2
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
else:
|
||||
new_sb_lines.append(line)
|
||||
continue
|
||||
if line.count('("') == 1:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split('("')[0] + "("
|
||||
line2 = new_ws + '"' + line.split('("')[1]
|
||||
if not ("):") in line2:
|
||||
new_sb_lines.append(line1)
|
||||
if get_width(line2) + w > console_width:
|
||||
if line2.count('" in self.') == 1:
|
||||
line2a = (
|
||||
line2.split('" in self.')[0]
|
||||
+ '" in'
|
||||
)
|
||||
line2b = (
|
||||
new_ws
|
||||
+ "self."
|
||||
+ (line2.split('" in self.')[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
new_sb_lines.append(line2)
|
||||
elif get_width(line2) + 4 + w <= console_width:
|
||||
line2 = " " + line2
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
else:
|
||||
new_sb_lines.append(line)
|
||||
continue
|
||||
if line.count("('") == 1:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split("('")[0] + "("
|
||||
line2 = new_ws + "'" + line.split("('")[1]
|
||||
if not ("):") in line2:
|
||||
new_sb_lines.append(line1)
|
||||
if get_width(line2) + w > console_width:
|
||||
if line2.count("' in self.") == 1:
|
||||
line2a = (
|
||||
line2.split("' in self.")[0]
|
||||
+ "' in"
|
||||
)
|
||||
line2b = (
|
||||
new_ws
|
||||
+ "self."
|
||||
+ (line2.split("' in self.")[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
new_sb_lines.append(line2)
|
||||
elif get_width(line2) + 4 + w <= console_width:
|
||||
line2 = " " + line2
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
else:
|
||||
new_sb_lines.append(line)
|
||||
continue
|
||||
if line.count('= "') == 1 and line.count("://") == 1:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split("://")[0] + '://" \\'
|
||||
line2 = new_ws + '"' + line.split("://")[1]
|
||||
if console_width:
|
||||
# If line is larger than console_width, try to optimize it.
|
||||
# Smart Python word wrap to be used with valid indentation.
|
||||
if line_length + w > console_width: # 5 is line number ws
|
||||
if line.strip().startswith("#"):
|
||||
new_sb_lines.append(line)
|
||||
continue
|
||||
elif (
|
||||
line.count(" # ") == 1
|
||||
and get_width(line.split(" # ")[0]) + w
|
||||
<= console_width
|
||||
):
|
||||
# Line is short enough once comment is removed
|
||||
line = line.split(" # ")[0]
|
||||
new_sb_lines.append(line)
|
||||
continue
|
||||
elif (
|
||||
line.count(" # ") == 1
|
||||
and get_width(line.split(" # ")[0]) + w
|
||||
<= console_width
|
||||
):
|
||||
# L-Length good if removing bad flake8 comment
|
||||
line = line.split(" # ")[0]
|
||||
new_sb_lines.append(line)
|
||||
continue
|
||||
if line.startswith("from") and " import " in line:
|
||||
line1 = line.split(" import ")[0] + " \\"
|
||||
line2 = " import " + line.split(" import ")[1]
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if line.count("(") == 1 and line.count(")") == 1:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split("(")[0] + "("
|
||||
line2 = new_ws + line.split("(")[1]
|
||||
if not ("):") in line2:
|
||||
new_sb_lines.append(line1)
|
||||
if get_width(line2) + w > console_width:
|
||||
if line2.count("/") > 0:
|
||||
slash_one = line2.find("/")
|
||||
slash_one_p1 = slash_one + 1
|
||||
line2a = line2[:slash_one_p1] + '" \\'
|
||||
if line2.count('", "') == 1:
|
||||
line2a = line2.split('", "')[0] + '",'
|
||||
line2b = (
|
||||
new_ws + '"' + line2[slash_one_p1:]
|
||||
new_ws
|
||||
+ '"'
|
||||
+ (line2.split('", "')[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if line.count("= '") == 1 and line.count("://") == 1:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split("://")[0] + "://' \\"
|
||||
line2 = new_ws + "'" + line.split("://")[1]
|
||||
new_sb_lines.append(line1)
|
||||
if get_width(line2) + w > console_width:
|
||||
if line2.count("/") > 0:
|
||||
slash_one = line2.find("/")
|
||||
slash_one_p1 = slash_one + 1
|
||||
line2a = line2[:slash_one_p1] + "' \\"
|
||||
elif line2.count("', '") == 1:
|
||||
line2a = line2.split("', '")[0] + "',"
|
||||
line2b = (
|
||||
new_ws + "'" + line2[slash_one_p1:]
|
||||
new_ws
|
||||
+ "'"
|
||||
+ (line2.split("', '")[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if line.count("(self.") == 1 and not ("):") in line:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split("(self.")[0] + "("
|
||||
line2 = new_ws + "self." + line.split("(self.")[1]
|
||||
if get_width(line1) + w <= console_width:
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if line.count(" == ") == 1 and not (
|
||||
line.endswith(":") or (": #") in line
|
||||
):
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split(" == ")[0] + " == ("
|
||||
line2 = new_ws + line.split(" == ")[1] + ")"
|
||||
if get_width(line1) + w <= console_width and (
|
||||
get_width(line2) + w <= console_width
|
||||
):
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if line.count(" == ") == 1 and line.endswith(":"):
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split(" == ")[0] + " == ("
|
||||
line2 = new_ws + line.split(" == ")[1][:-1] + "):"
|
||||
if get_width(line1) + w <= console_width and (
|
||||
get_width(line2) + w <= console_width
|
||||
):
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if (
|
||||
line.count(" == ") == 1
|
||||
and (line.count(": #") == 1)
|
||||
and (line.find(" == ") < line.find(": #"))
|
||||
):
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
comments = " #" + line.split(": #")[1]
|
||||
line0 = line.split(": #")[0] + ":"
|
||||
line1 = line0.split(" == ")[0] + " == ("
|
||||
line2 = new_ws + line0.split(" == ")[1][:-1] + "):"
|
||||
if get_width(line1) + w <= console_width and (
|
||||
get_width(line2) + w <= console_width
|
||||
):
|
||||
new_sb_lines.append(line1)
|
||||
if (
|
||||
get_width(line2 + comments) + w
|
||||
<= console_width
|
||||
elif line2.count("://") == 1 and (
|
||||
line2.count('")') == 1
|
||||
):
|
||||
new_sb_lines.append(line2 + comments)
|
||||
else:
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if line.count(" % ") == 1 and not ("):") in line:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split(" % ")[0] + " \\"
|
||||
line2 = new_ws + "% " + line.split(" % ")[1]
|
||||
if get_width(line1) + w <= console_width:
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if line.count(" = ") == 1 and not (" # ") in line:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split(" = ")[0] + " = ("
|
||||
line2 = new_ws + line.split(" = ")[1] + ")"
|
||||
if get_width(line1) + w <= console_width and (
|
||||
get_width(line2) + w <= console_width
|
||||
):
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
elif get_width(line1) + w <= console_width:
|
||||
if line2.count(" % ") == 1 and not (
|
||||
line2.endswith(":")
|
||||
):
|
||||
whitespace = line_length2 - len(
|
||||
line2.lstrip()
|
||||
)
|
||||
line2a = line2.split(" % ")[0] + " \\"
|
||||
line2a = line2.split("://")[0] + '://"'
|
||||
line2b = (
|
||||
new_ws + "% " + line2.split(" % ")[1]
|
||||
new_ws
|
||||
+ '"'
|
||||
+ (line2.split("://")[1])
|
||||
)
|
||||
if get_width(line2a) + w <= console_width:
|
||||
if (
|
||||
get_width(line2b) + w
|
||||
<= console_width
|
||||
):
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
new_sb_lines.append(line2a)
|
||||
if get_width(line2b) + w > (
|
||||
console_width
|
||||
):
|
||||
if line2b.count("/") > 0:
|
||||
slash_one = line2b.find("/")
|
||||
slash_one_p1 = slash_one + 1
|
||||
line2b1 = (
|
||||
line2b[:slash_one_p1] + '"'
|
||||
)
|
||||
line2b2 = (
|
||||
new_ws
|
||||
+ '"'
|
||||
+ (line2b[slash_one_p1:])
|
||||
)
|
||||
new_sb_lines.append(line2b1)
|
||||
if line2b2.count(") # ") == 1:
|
||||
line2b2 = (
|
||||
line2b2.split(") # ")[
|
||||
0
|
||||
]
|
||||
+ ")"
|
||||
)
|
||||
new_sb_lines.append(line2b2)
|
||||
continue
|
||||
if (
|
||||
line.count(" = ") == 1
|
||||
and (line.count(" # ") == 1)
|
||||
and (line.find(" = ") < line.find(" # "))
|
||||
):
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
comments = " # " + line.split(" # ")[1]
|
||||
line0 = line.split(" # ")[0]
|
||||
line1 = line0.split(" = ")[0] + " = ("
|
||||
line2 = new_ws + line0.split(" = ")[1] + ")"
|
||||
if get_width(line1) + w <= console_width and (
|
||||
get_width(line2) + w <= console_width
|
||||
):
|
||||
new_sb_lines.append(line1)
|
||||
if (
|
||||
get_width(line2 + comments) + w
|
||||
<= console_width
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
elif line2.count("://") == 1 and (
|
||||
line2.count("')") == 1
|
||||
):
|
||||
new_sb_lines.append(line2 + comments)
|
||||
else:
|
||||
new_sb_lines.append(line2)
|
||||
line2a = line2.split("://")[0] + "://'"
|
||||
line2b = (
|
||||
new_ws
|
||||
+ "'"
|
||||
+ (line2.split("://")[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
if get_width(line2b) + w > (
|
||||
console_width
|
||||
):
|
||||
if line2b.count("/") > 0:
|
||||
slash_one = line2b.find("/")
|
||||
slash_one_p1 = slash_one + 1
|
||||
line2b1 = (
|
||||
line2b[:slash_one_p1] + "'"
|
||||
)
|
||||
line2b2 = (
|
||||
new_ws
|
||||
+ "'"
|
||||
+ (line2b[slash_one_p1:])
|
||||
)
|
||||
new_sb_lines.append(line2b1)
|
||||
if line2b2.count(") # ") == 1:
|
||||
line2b2 = (
|
||||
line2b2.split(") # ")[
|
||||
0
|
||||
]
|
||||
+ ")"
|
||||
)
|
||||
new_sb_lines.append(line2b2)
|
||||
continue
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
elif line2.count(", ") == 1:
|
||||
line2a = line2.split(", ")[0] + ","
|
||||
line2b = new_ws + (
|
||||
line2.split(", ")[1]
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
elif line2.count('="') == 1 and (
|
||||
line2.lstrip().startswith("'")
|
||||
):
|
||||
line2a = line2.split('="')[0] + "='"
|
||||
line2b = (
|
||||
new_ws
|
||||
+ "'\""
|
||||
+ (line2.split('="')[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
elif line2.count("='") == 1 and (
|
||||
line2.lstrip().startswith('"')
|
||||
):
|
||||
line2a = line2.split("='")[0] + '="'
|
||||
line2b = (
|
||||
new_ws
|
||||
+ "\"'"
|
||||
+ (line2.split("='")[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
new_sb_lines.append(line2)
|
||||
elif get_width(line2) + 4 + w <= console_width:
|
||||
line2 = " " + line2
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
else:
|
||||
new_sb_lines.append(line)
|
||||
continue
|
||||
if line.count('("') == 1:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split('("')[0] + "("
|
||||
line2 = new_ws + '"' + line.split('("')[1]
|
||||
if not ("):") in line2:
|
||||
new_sb_lines.append(line1)
|
||||
if get_width(line2) + w > console_width:
|
||||
if line2.count('" in self.') == 1:
|
||||
line2a = (
|
||||
line2.split('" in self.')[0]
|
||||
+ '" in'
|
||||
)
|
||||
line2b = (
|
||||
new_ws
|
||||
+ "self."
|
||||
+ (line2.split('" in self.')[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
new_sb_lines.append(line2)
|
||||
elif get_width(line2) + 4 + w <= console_width:
|
||||
line2 = " " + line2
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
else:
|
||||
new_sb_lines.append(line)
|
||||
continue
|
||||
if line.count("('") == 1:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split("('")[0] + "("
|
||||
line2 = new_ws + "'" + line.split("('")[1]
|
||||
if not ("):") in line2:
|
||||
new_sb_lines.append(line1)
|
||||
if get_width(line2) + w > console_width:
|
||||
if line2.count("' in self.") == 1:
|
||||
line2a = (
|
||||
line2.split("' in self.")[0]
|
||||
+ "' in"
|
||||
)
|
||||
line2b = (
|
||||
new_ws
|
||||
+ "self."
|
||||
+ (line2.split("' in self.")[1])
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
new_sb_lines.append(line2)
|
||||
elif get_width(line2) + 4 + w <= console_width:
|
||||
line2 = " " + line2
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
else:
|
||||
new_sb_lines.append(line)
|
||||
continue
|
||||
if line.count('= "') == 1 and line.count("://") == 1:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split("://")[0] + '://" \\'
|
||||
line2 = new_ws + '"' + line.split("://")[1]
|
||||
new_sb_lines.append(line1)
|
||||
if get_width(line2) + w > console_width:
|
||||
if line2.count("/") > 0:
|
||||
slash_one = line2.find("/")
|
||||
slash_one_p1 = slash_one + 1
|
||||
line2a = line2[:slash_one_p1] + '" \\'
|
||||
line2b = (
|
||||
new_ws + '"' + line2[slash_one_p1:]
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
new_sb_lines.append(line)
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if line.count("= '") == 1 and line.count("://") == 1:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split("://")[0] + "://' \\"
|
||||
line2 = new_ws + "'" + line.split("://")[1]
|
||||
new_sb_lines.append(line1)
|
||||
if get_width(line2) + w > console_width:
|
||||
if line2.count("/") > 0:
|
||||
slash_one = line2.find("/")
|
||||
slash_one_p1 = slash_one + 1
|
||||
line2a = line2[:slash_one_p1] + "' \\"
|
||||
line2b = (
|
||||
new_ws + "'" + line2[slash_one_p1:]
|
||||
)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if line.count("(self.") == 1 and not ("):") in line:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split("(self.")[0] + "("
|
||||
line2 = new_ws + "self." + line.split("(self.")[1]
|
||||
if get_width(line1) + w <= console_width:
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if line.count(" == ") == 1 and not (
|
||||
line.endswith(":") or (": #") in line
|
||||
):
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split(" == ")[0] + " == ("
|
||||
line2 = new_ws + line.split(" == ")[1] + ")"
|
||||
if get_width(line1) + w <= console_width and (
|
||||
get_width(line2) + w <= console_width
|
||||
):
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if line.count(" == ") == 1 and line.endswith(":"):
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split(" == ")[0] + " == ("
|
||||
line2 = new_ws + line.split(" == ")[1][:-1] + "):"
|
||||
if get_width(line1) + w <= console_width and (
|
||||
get_width(line2) + w <= console_width
|
||||
):
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if (
|
||||
line.count(" == ") == 1
|
||||
and (line.count(": #") == 1)
|
||||
and (line.find(" == ") < line.find(": #"))
|
||||
):
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
comments = " #" + line.split(": #")[1]
|
||||
line0 = line.split(": #")[0] + ":"
|
||||
line1 = line0.split(" == ")[0] + " == ("
|
||||
line2 = new_ws + line0.split(" == ")[1][:-1] + "):"
|
||||
if get_width(line1) + w <= console_width and (
|
||||
get_width(line2) + w <= console_width
|
||||
):
|
||||
new_sb_lines.append(line1)
|
||||
if (
|
||||
get_width(line2 + comments) + w
|
||||
<= console_width
|
||||
):
|
||||
new_sb_lines.append(line2 + comments)
|
||||
else:
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if line.count(" % ") == 1 and not ("):") in line:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split(" % ")[0] + " \\"
|
||||
line2 = new_ws + "% " + line.split(" % ")[1]
|
||||
if get_width(line1) + w <= console_width:
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
if line.count(" = ") == 1 and not (" # ") in line:
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
line1 = line.split(" = ")[0] + " = ("
|
||||
line2 = new_ws + line.split(" = ")[1] + ")"
|
||||
if get_width(line1) + w <= console_width and (
|
||||
get_width(line2) + w <= console_width
|
||||
):
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
elif get_width(line1) + w <= console_width:
|
||||
if line2.count(" % ") == 1 and not (
|
||||
line2.endswith(":")
|
||||
):
|
||||
whitespace = line_length2 - len(
|
||||
line2.lstrip()
|
||||
)
|
||||
line2a = line2.split(" % ")[0] + " \\"
|
||||
line2b = (
|
||||
new_ws + "% " + line2.split(" % ")[1]
|
||||
)
|
||||
if get_width(line2a) + w <= console_width:
|
||||
if (
|
||||
get_width(line2b) + w
|
||||
<= console_width
|
||||
):
|
||||
new_sb_lines.append(line1)
|
||||
new_sb_lines.append(line2a)
|
||||
new_sb_lines.append(line2b)
|
||||
continue
|
||||
if (
|
||||
line.count(" = ") == 1
|
||||
and (line.count(" # ") == 1)
|
||||
and (line.find(" = ") < line.find(" # "))
|
||||
):
|
||||
whitespace = line_length2 - len(line.lstrip())
|
||||
new_ws = line[0:whitespace] + " "
|
||||
comments = " # " + line.split(" # ")[1]
|
||||
line0 = line.split(" # ")[0]
|
||||
line1 = line0.split(" = ")[0] + " = ("
|
||||
line2 = new_ws + line0.split(" = ")[1] + ")"
|
||||
if get_width(line1) + w <= console_width and (
|
||||
get_width(line2) + w <= console_width
|
||||
):
|
||||
new_sb_lines.append(line1)
|
||||
if (
|
||||
get_width(line2 + comments) + w
|
||||
<= console_width
|
||||
):
|
||||
new_sb_lines.append(line2 + comments)
|
||||
else:
|
||||
new_sb_lines.append(line2)
|
||||
continue
|
||||
new_sb_lines.append(line)
|
||||
|
||||
if new_sb_lines:
|
||||
seleniumbase_lines = new_sb_lines
|
||||
python_code = "\n".join(seleniumbase_lines)
|
||||
if new_sb_lines:
|
||||
seleniumbase_lines = new_sb_lines
|
||||
python_code = "\n".join(seleniumbase_lines)
|
||||
|
||||
extra_r_spaces = 2
|
||||
if console_width and (code_width + extra_r_spaces < console_width):
|
||||
used_width = code_width + extra_r_spaces
|
||||
extra_r_spaces = 2
|
||||
if console_width and (code_width + extra_r_spaces < console_width):
|
||||
used_width = code_width + extra_r_spaces
|
||||
|
||||
magic_syntax = Syntax(
|
||||
python_code,
|
||||
"python",
|
||||
theme="monokai",
|
||||
line_numbers=line_numbers,
|
||||
code_width=used_width,
|
||||
word_wrap=word_wrap,
|
||||
)
|
||||
magic_console = Console()
|
||||
|
||||
magic_syntax = Syntax(
|
||||
python_code,
|
||||
"python",
|
||||
theme="monokai",
|
||||
line_numbers=line_numbers,
|
||||
code_width=used_width,
|
||||
word_wrap=word_wrap,
|
||||
)
|
||||
magic_console = Console()
|
||||
print("")
|
||||
print(save_line)
|
||||
print(" " + c1 + " *** Here are the results: >>> " + cr)
|
||||
|
|
|
@ -26,7 +26,6 @@ __all__ = (
|
|||
"CDP",
|
||||
"find_chrome_executable",
|
||||
)
|
||||
|
||||
logger = logging.getLogger("uc")
|
||||
logger.setLevel(logging.getLogger().getEffectiveLevel())
|
||||
sys_plat = sys.platform
|
||||
|
@ -182,22 +181,14 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
|||
try:
|
||||
language = m[1]
|
||||
except IndexError:
|
||||
logger.debug("will set the language to en-US,en;q=0.9")
|
||||
language = "en-US,en;q=0.9"
|
||||
if "user-data-dir" in arg:
|
||||
m = re.search("(?:--)?user-data-dir(?:[ =])?(.*)", arg)
|
||||
try:
|
||||
user_data_dir = m[1]
|
||||
logger.debug(
|
||||
"user-data-dir found in user argument %s => %s"
|
||||
% (arg, m[1])
|
||||
)
|
||||
keep_user_data_dir = True
|
||||
except IndexError:
|
||||
logger.debug(
|
||||
"No user data dir extracted from supplied argument %s"
|
||||
% arg
|
||||
)
|
||||
pass
|
||||
if not user_data_dir:
|
||||
if hasattr(options, "user_data_dir") and getattr(
|
||||
options, "user_data_dir", None
|
||||
|
@ -206,21 +197,14 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
|||
"--user-data-dir=%s" % options.user_data_dir
|
||||
)
|
||||
keep_user_data_dir = True
|
||||
logger.debug(
|
||||
"user_data_dir property found in options object: %s"
|
||||
% user_data_dir
|
||||
)
|
||||
else:
|
||||
import tempfile
|
||||
|
||||
user_data_dir = os.path.normpath(tempfile.mkdtemp())
|
||||
keep_user_data_dir = False
|
||||
arg = "--user-data-dir=%s" % user_data_dir
|
||||
# Create a temporary folder for the user-data profile.
|
||||
options.add_argument(arg)
|
||||
logger.debug(
|
||||
"Created a temporary folder for the user-data profile.\n"
|
||||
"Also added it to the Chrome startup arguments: %s" % arg
|
||||
)
|
||||
if not language:
|
||||
try:
|
||||
import locale
|
||||
|
@ -279,9 +263,8 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
|||
fs.seek(0, 0)
|
||||
fs.truncate()
|
||||
json.dump(config, fs)
|
||||
logger.debug("Fixed exit_type flag.")
|
||||
except Exception:
|
||||
logger.debug("Did not find a bad exit_type flag.")
|
||||
pass
|
||||
creationflags = 0
|
||||
if "win32" in sys_plat or "win64" in sys_plat or "x64" in sys_plat:
|
||||
creationflags = subprocess.CREATE_NO_WINDOW
|
||||
|
@ -338,10 +321,6 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
|||
original = super().__getattribute__(item)
|
||||
if inspect.ismethod(original) and not inspect.isclass(original):
|
||||
def newfunc(*args, **kwargs):
|
||||
logger.debug(
|
||||
"calling %s with args %s and kwargs %s\n"
|
||||
% (original.__qualname__, args, kwargs)
|
||||
)
|
||||
return original(*args, **kwargs)
|
||||
return newfunc
|
||||
return original
|
||||
|
@ -412,7 +391,7 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
|||
return None
|
||||
|
||||
def tab_new(self, url):
|
||||
"""This opens a url in a new tab."""
|
||||
"""Open url in a new tab."""
|
||||
if not hasattr(self, "cdp"):
|
||||
self.cdp = CDP(self.options)
|
||||
self.cdp.tab_new(str(url))
|
||||
|
@ -428,20 +407,21 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
|||
"""This can be useful when sites use heavy detection methods:
|
||||
- Stops the chromedriver service that runs in the background.
|
||||
- Starts the chromedriver service that runs in the background.
|
||||
- Recreates the session. """
|
||||
try:
|
||||
self.service.stop()
|
||||
except Exception as e:
|
||||
logger.debug(e)
|
||||
time.sleep(timeout)
|
||||
try:
|
||||
self.service.start()
|
||||
except Exception as e:
|
||||
logger.debug(e)
|
||||
- Recreates the session."""
|
||||
if hasattr(self, "service"):
|
||||
try:
|
||||
self.service.stop()
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(timeout)
|
||||
try:
|
||||
self.service.start()
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
self.start_session()
|
||||
except Exception as e:
|
||||
logger.debug(e)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def start_session(self, capabilities=None):
|
||||
if not capabilities:
|
||||
|
|
|
@ -3,6 +3,7 @@ import os
|
|||
import subprocess
|
||||
import sys
|
||||
from seleniumbase import drivers # webdriver storage folder for SeleniumBase
|
||||
from seleniumbase.fixtures import shared_utils
|
||||
|
||||
DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
|
||||
# Make sure that the SeleniumBase DRIVER_DIR is at the top of the System PATH
|
||||
|
@ -85,7 +86,7 @@ def main():
|
|||
|
||||
download_selenium_server.main(force_download=False) # Only runs if needed
|
||||
|
||||
if "linux" in sys.platform or "darwin" in sys.platform:
|
||||
if shared_utils.is_linux() or shared_utils.is_mac():
|
||||
if grid_hub_command == "start":
|
||||
subprocess.check_call(
|
||||
dir_path + "/grid-hub start %s" % timeout, shell=True
|
||||
|
|
|
@ -3,6 +3,7 @@ import os
|
|||
import subprocess
|
||||
import sys
|
||||
from seleniumbase import drivers # webdriver storage folder for SeleniumBase
|
||||
from seleniumbase.fixtures import shared_utils
|
||||
|
||||
DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
|
||||
# Make sure that the SeleniumBase DRIVER_DIR is at the top of the System PATH
|
||||
|
@ -102,7 +103,7 @@ def main():
|
|||
|
||||
download_selenium_server.main(force_download=False) # Only runs if needed
|
||||
|
||||
if "linux" in sys.platform or "darwin" in sys.platform:
|
||||
if shared_utils.is_linux() or shared_utils.is_mac():
|
||||
if grid_hub_command == "start":
|
||||
subprocess.check_call(dir_path + "/grid-node start", shell=True)
|
||||
elif grid_hub_command == "restart":
|
||||
|
|
Loading…
Reference in New Issue