Skip to content

UC Mode upgrades #3079

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ pathspec==0.12.1
Babel==2.16.0
paginate==0.5.7
lxml==5.3.0
pyquery==2.0.0
pyquery==2.0.1
readtime==3.0.0
mkdocs==1.6.0
mkdocs==1.6.1
mkdocs-material==9.5.33
mkdocs-exclude-search==0.6.6
mkdocs-simple-hooks==0.1.5
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ setuptools>=70.2.0;python_version>="3.10"
wheel>=0.42.0;python_version<"3.8"
wheel>=0.44.0;python_version>="3.8"
attrs>=24.2.0
certifi>=2024.7.4
certifi>=2024.8.30
exceptiongroup>=1.2.2
filelock>=3.12.2;python_version<"3.8"
filelock>=3.15.4;python_version>="3.8"
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.30.0"
__version__ = "4.30.1"
6 changes: 4 additions & 2 deletions seleniumbase/console_scripts/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,10 @@ sbase mkfile new_test.py

* Options:

``--uc`` (UC Mode boilerplate using SB context manager)
`-b` / `--basic` (Basic boilerplate / single-line test)
`-r` / `--rec` (adds Pdb+ breakpoint for Recorder Mode)
``--url=URL`` (makes the test start on a specific page)
`-r` / `--rec` (Adds Pdb+ breakpoint for Recorder Mode)
``--url=URL`` (Makes the test start on a specific page)

* Language Options:

Expand Down Expand Up @@ -381,6 +382,7 @@ methods: "open", "type", "click", "assert_element",
and "assert_text". If using the basic boilerplate
option, only the "open" method is included. Only the
BaseCase format supports Languages or Recorder Mode.
UC Mode automatically uses English with SB() format.

<h3>mkrec / record / codegen</h3>

Expand Down
6 changes: 4 additions & 2 deletions seleniumbase/console_scripts/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,10 @@ def show_mkfile_usage():
print(" Example:")
print(" sbase mkfile new_test.py")
print(" Options:")
print(" --uc (UC Mode boilerplate using SB context manager)")
print(" -b / --basic (Basic boilerplate / single-line test)")
print(" -r / --rec (adds Pdb+ breakpoint for Recorder Mode)")
print(" --url=URL (makes the test start on a specific page)")
print(" -r / --rec (Adds Pdb+ breakpoint for Recorder Mode)")
print(" --url=URL (Makes the test start on a specific page)")
print(" Language Options:")
print(" --en / --English | --zh / --Chinese")
print(" --nl / --Dutch | --fr / --French")
Expand All @@ -289,6 +290,7 @@ def show_mkfile_usage():
print(' and "assert_text". If using the basic boilerplate')
print(' option, only the "open" method is included. Only the')
print(" BaseCase format supports Languages or Recorder Mode.")
print(" UC Mode automatically uses English with SB() format.")
print("")


Expand Down
59 changes: 46 additions & 13 deletions seleniumbase/console_scripts/sb_mkfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
sbase mkfile new_test.py

Options:
--uc (UC Mode boilerplate using SB context manager)
-b / --basic (Basic boilerplate / single-line test)
-r / --rec (adds Pdb+ breakpoint for Recorder Mode)
--url=URL (makes the test start on a specific page)
-r / --rec (Adds Pdb+ breakpoint for Recorder Mode)
--url=URL (Makes the test start on a specific page)

Language Options:
--en / --English | --zh / --Chinese
Expand All @@ -37,6 +38,7 @@
and "assert_text". If using the basic boilerplate
option, only the "open" method is included. Only the
BaseCase format supports Languages or Recorder Mode.
UC Mode automatically uses English with SB() format.
"""
import codecs
import colorama
Expand All @@ -52,9 +54,10 @@ def invalid_run_command(msg=None):
exp += " Example:\n"
exp += " sbase mkfile new_test.py\n"
exp += " Options:\n"
exp += " --uc (UC Mode boilerplate using SB context manager)\n"
exp += " -b / --basic (Basic boilerplate / single-line test)\n"
exp += " -r / --rec (adds Pdb+ breakpoint for Recorder Mode)\n"
exp += " --url=URL (makes the test start on a specific page)\n"
exp += " -r / --rec (Adds Pdb+ breakpoint for Recorder Mode)\n"
exp += " --url=URL (Makes the test start on a specific page)\n"
exp += " Language Options:\n"
exp += " --en / --English | --zh / --Chinese\n"
exp += " --nl / --Dutch | --fr / --French\n"
Expand All @@ -77,6 +80,7 @@ def invalid_run_command(msg=None):
exp += ' and "assert_text". If using the basic boilerplate\n'
exp += ' option, only the "open" method is included. Only the\n'
exp += " BaseCase format supports Languages or Recorder Mode.\n"
exp += " UC Mode automatically uses English with SB() format.\n"
if not msg:
raise Exception("INVALID RUN COMMAND!\n\n%s" % exp)
elif msg == "help":
Expand Down Expand Up @@ -105,6 +109,7 @@ def main():
cr = colorama.Style.RESET_ALL

basic = False
use_uc = False
help_me = False
recorder = False
error_msg = None
Expand Down Expand Up @@ -152,6 +157,9 @@ def main():
recorder = True
elif option == "--record" or option == "--recorder":
recorder = True
elif use_uc:
# UC must use English & ContextManager formats
continue
elif option == "--en" or option == "--english":
language = "English"
elif option == "--zh" or option == "--chinese":
Expand Down Expand Up @@ -184,6 +192,11 @@ def main():
syntax = "DriverContext"
elif option == "--dm" or option == "--driver-manager":
syntax = "DriverManager"
elif option == "--uc":
basic = True
language = "English"
syntax = "ContextManager"
use_uc = True
else:
invalid_cmd = "\n===> INVALID OPTION: >> %s <<\n" % option
invalid_cmd = invalid_cmd.replace(">> ", ">>" + c5 + " ")
Expand Down Expand Up @@ -319,16 +332,22 @@ def main():
data = []
data.append("from seleniumbase import SB")
data.append("")
data.append('with SB(browser="chrome") as sb:')
data.append(
' sb.open("data:text/html,<div>Hello<br><input></div>")'
)
if use_uc:
data.append('with SB(uc=True) as sb:')
else:
data.append('with SB(browser="chrome") as sb:')
if use_uc:
data.append(' url = "%s"' % url)
data.append(" sb.uc_open_with_reconnect(url, 4)")
data.append(" sb.uc_gui_click_captcha()")
else:
data.append(' sb.open("%s")' % url)
if not basic:
data.append(' sb.type("input", "Goodbye") # selector, text')
data.append(' sb.click("html body > div") # selector')
data.append(' sb.click("html body > p") # selector')
data.append(' sb.assert_element("input") # selector')
data.append(' sb.assert_text("Hello", "div") # text, selector')
data.append(' sb.highlight("div") # selector')
data.append(' sb.assert_text("Hello", "p") # text, selector')
data.append(' sb.highlight("p") # selector')
data.append(" sb.sleep(0.5) # seconds")
data.append("")
new_data = data
Expand All @@ -337,7 +356,14 @@ def main():
data.append("from seleniumbase import DriverContext")
data.append("")
data.append('with DriverContext(browser="chrome") as driver:')
data.append(' driver.get("data:text/html,<p>Hello<br><input>")')
data.append(' driver.get("%s")' % url)
if not basic:
data.append(' driver.type("input", "Goodbye") # sel, text')
data.append(' driver.click("html body > p") # selector')
data.append(' driver.assert_element("input") # selector')
data.append(' driver.assert_text("Hello", "p") # text, sel')
data.append(' driver.highlight("p") # selector')
data.append(" driver.sleep(0.5) # seconds")
data.append("")
new_data = data
elif language == "English" and syntax == "DriverManager":
Expand All @@ -346,7 +372,14 @@ def main():
data.append("")
data.append('driver = Driver(browser="chrome")')
data.append("try:")
data.append(' driver.get("data:text/html,<p>Hello<br><input>")')
data.append(' driver.get("%s")' % url)
if not basic:
data.append(' driver.type("input", "Goodbye") # sel, text')
data.append(' driver.click("html body > p") # selector')
data.append(' driver.assert_element("input") # selector')
data.append(' driver.assert_text("Hello", "p") # text, sel')
data.append(' driver.highlight("p") # selector')
data.append(" driver.sleep(0.5) # seconds")
data.append("finally:")
data.append(" driver.quit()")
data.append("")
Expand Down
8 changes: 4 additions & 4 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,9 @@ def _uc_gui_click_captcha(
frame = "%s div[style]" % frame
elif (
driver.is_element_present('[name*="cf-turnstile-"]')
and driver.is_element_present("div.spacer div[style]")
and driver.is_element_present("div.spacer div")
):
frame = "div.spacer div[style]"
frame = "div.spacer div"
elif (
(
driver.is_element_present('[name*="cf-turnstile-"]')
Expand Down Expand Up @@ -1099,9 +1099,9 @@ def _uc_gui_handle_captcha(
frame = '[data-callback="onCaptchaSuccess"]'
elif (
driver.is_element_present('[name*="cf-turnstile-"]')
and driver.is_element_present("div.spacer div[style]")
and driver.is_element_present("div.spacer div")
):
frame = "div.spacer div[style]"
frame = "div.spacer div"
elif (
(
driver.is_element_present('[name*="cf-turnstile-"]')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
'wheel>=0.42.0;python_version<"3.8"',
'wheel>=0.44.0;python_version>="3.8"',
'attrs>=24.2.0',
"certifi>=2024.7.4",
"certifi>=2024.8.30",
"exceptiongroup>=1.2.2",
'filelock>=3.12.2;python_version<"3.8"',
'filelock>=3.15.4;python_version>="3.8"',
Expand Down