Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update options and UC Mode #2770

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
mdmintz merged 5 commits into master from update-options-and-uc-mode
May 13, 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
1 change: 1 addition & 0 deletions README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ pytest test_coffee_cart.py --trace
--block-images # (Block images from loading during tests.)
--do-not-track # (Indicate to websites that you don't want to be tracked.)
--verify-delay=SECONDS # (The delay before MasterQA verification checks.)
--ee | --esc-end # (Lets the user end the current test via the ESC key.)
--recorder # (Enables the Recorder for turning browser actions into code.)
--rec-behave # (Same as Recorder Mode, but also generates behave-gherkin.)
--rec-sleep # (If the Recorder is enabled, also records self.sleep calls.)
Expand Down
1 change: 1 addition & 0 deletions examples/raw_parameter_script.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
sb._reuse_session = False
sb._crumbs = False
sb._final_debug = False
sb.esc_end = False
sb.use_wire = False
sb.enable_3d_apis = False
sb.window_size = None
Expand Down
1 change: 1 addition & 0 deletions help_docs/customizing_test_runs.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ pytest my_first_test.py --settings-file=custom_settings.py
--block-images # (Block images from loading during tests.)
--do-not-track # (Indicate to websites that you don't want to be tracked.)
--verify-delay=SECONDS # (The delay before MasterQA verification checks.)
--ee | --esc-end # (Lets the user end the current test via the ESC key.)
--recorder # (Enables the Recorder for turning browser actions into code.)
--rec-behave # (Same as Recorder Mode, but also generates behave-gherkin.)
--rec-sleep # (If the Recorder is enabled, also records self.sleep calls.)
Expand Down
2 changes: 2 additions & 0 deletions help_docs/method_summary.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,8 @@ driver.uc_open_with_tab(url) # (New tab with default reconnect_time)

driver.uc_open_with_reconnect(url, reconnect_time=None) # (New tab)

driver.uc_open_with_disconnect(url) # Open in new tab + disconnect()

driver.reconnect(timeout) # disconnect() + sleep(timeout) + connect()

driver.disconnect() # Stops the webdriver service to prevent detection
Expand Down
2 changes: 2 additions & 0 deletions help_docs/recorder_mode.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ pytest TEST_NAME.py --trace --rec -s

⏺️ Inside recorded tests, you might find the <code>self.open_if_not_url(URL)</code> method, which opens the URL given if the browser is not currently on that page. SeleniumBase uses this method in recorded scripts when the Recorder detects that a browser action changed the current URL. This method prevents an unnecessary page load and shows what page the test visited after a browser action.

⏺️ By launching the Recorder App with <code>sbase recorder --ee</code>, you can end the recording by pressing {<code>SHIFT</code>+<code>ESC</code>} instead of the usual way of ending the recording by typing <code>c</code> from a <code>breakpoint()</code> and pressing <code>Enter</code>. Those buttons don't need to be pressed at the same time, but <code>SHIFT</code> must be pressed directly before <code>ESC</code>.

--------

<div>To learn more about SeleniumBase, check out the Docs Site:</div>
Expand Down
2 changes: 2 additions & 0 deletions help_docs/uc_mode.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ driver.uc_open_with_tab(url)

driver.uc_open_with_reconnect(url, reconnect_time=None)

driver.uc_open_with_disconnect(url)

driver.reconnect(timeout)

driver.disconnect()
Expand Down
10 changes: 5 additions & 5 deletions mkdocs_build/requirements.txt
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# mkdocs dependencies for generating the seleniumbase.io website
# Minimum Python version: 3.8 (for generating docs only)

regex>=2024.4.28
regex>=2024.5.10
pymdown-extensions>=10.8.1
pipdeptree>=2.19.1
pipdeptree>=2.20.0
python-dateutil>=2.8.2
Markdown==3.6
markdown2==2.4.13
MarkupSafe==2.1.5
Jinja2==3.1.3
Jinja2==3.1.4
click==8.1.7
ghp-import==2.1.0
watchdog==4.0.0
cairocffi==1.7.0
pathspec==0.12.1
Babel==2.14.0
Babel==2.15.0
paginate==0.5.6
lxml==5.2.1
pyquery==2.0.0
readtime==3.0.0
mkdocs==1.6.0
mkdocs-material==9.5.21
mkdocs-material==9.5.22
mkdocs-exclude-search==0.6.6
mkdocs-simple-hooks==0.1.5
mkdocs-material-extensions==1.3.1
5 changes: 3 additions & 2 deletions requirements.txt
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ behave==1.2.6
soupsieve==2.4.1;python_version<"3.8"
soupsieve==2.5;python_version>="3.8"
beautifulsoup4==4.12.3
pygments==2.17.2
pygments==2.17.2;python_version<"3.8"
pygments==2.18.0;python_version>="3.8"
pyreadline3==3.4.1;platform_system=="Windows"
tabcompleter==1.3.0
pdbp==1.5.0
Expand All @@ -72,7 +73,7 @@ rich==13.7.1
# ("pip install -r requirements.txt" also installs this, but "pip install -e ." won't.)

coverage==7.2.7;python_version<"3.8"
coverage>=7.5.0;python_version>="3.8"
coverage>=7.5.1;python_version>="3.8"
pytest-cov==4.1.0;python_version<"3.8"
pytest-cov>=5.0.0;python_version>="3.8"
flake8==5.0.4;python_version<"3.9"
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.26.3"
__version__ = "4.26.4"
1 change: 1 addition & 0 deletions seleniumbase/console_scripts/ReadMe.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ sbase codegen new_test.py --url=wikipedia.org
``--edge`` (Use Edge browser instead of Chrome.)
``--gui`` / ``--headed`` (Use headed mode on Linux.)
``--uc`` / ``--undetected`` (Use undetectable mode.)
``--ee`` (Use SHIFT + ESC to end the recording.)
``--overwrite`` (Overwrite file when it exists.)
``--behave`` (Also output Behave/Gherkin files.)

Expand Down
2 changes: 2 additions & 0 deletions seleniumbase/console_scripts/run.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def show_mkrec_usage():
print(" --edge (Use Edge browser instead of Chrome.)")
print(" --gui / --headed (Use headed mode on Linux.)")
print(" --uc / --undetected (Use undetectable mode.)")
print(" --ee (Use SHIFT + ESC to end the recording.)")
print(" --overwrite (Overwrite file when it exists.)")
print(" --behave (Also output Behave/Gherkin files.)")
print(" Output:")
Expand All @@ -336,6 +337,7 @@ def show_codegen_usage():
print(" --edge (Use Edge browser instead of Chrome.)")
print(" --gui / --headed (Use headed mode on Linux.)")
print(" --uc / --undetected (Use undetectable mode.)")
print(" --ee (Use SHIFT + ESC to end the recording.)")
print(" --overwrite (Overwrite file when it exists.)")
print(" --behave (Also output Behave/Gherkin files.)")
print(" Output:")
Expand Down
39 changes: 39 additions & 0 deletions seleniumbase/console_scripts/sb_mkrec.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def main():
invalid_cmd = None
use_edge = False
use_uc = False
esc_end = False
start_page = None
next_is_url = False
use_colors = True
Expand Down Expand Up @@ -145,6 +146,8 @@ def main():
help_me = True
elif option.lower() == "--edge":
use_edge = True
elif option.lower() == "--ee":
esc_end = True
elif option.lower() in ("--gui", "--headed"):
if "linux" in sys.platform:
force_gui = True
Expand Down Expand Up @@ -183,6 +186,42 @@ def main():
data.append(' # type "c", and press [Enter].')
data.append(" import pdb; pdb.set_trace()")
data.append("")

if esc_end:
msg = ">>> Use [SHIFT + ESC] in the browser to end recording!"
d2 = []
d2.append("from seleniumbase import BaseCase")
d2.append("")
d2.append("")
d2.append("class RecorderTest(BaseCase):")
d2.append(" def test_recording(self):")
d2.append(" if self.recorder_ext:")
d2.append(" print(")
d2.append(' "\\n\\n%s\\n"' % msg)
d2.append(" )")
d2.append(' script = self._get_rec_shift_esc_script()')
d2.append(' esc = "return document.sb_esc_end;"')
d2.append(" start_time = self.time()")
d2.append(" last_handles_num = self._get_num_handles()")
d2.append(" for i in range(1200):")
d2.append(" try:")
d2.append(" self.execute_script(script)")
d2.append(" handles_num = self._get_num_handles()")
d2.append(" if handles_num < 1:")
d2.append(" return")
d2.append(" elif handles_num != last_handles_num:")
d2.append(" self.switch_to_window(-1)")
d2.append(" last_handles_num = handles_num")
d2.append(' if self.execute_script(esc) == "yes":')
d2.append(" return")
d2.append(" elif self.time() - start_time > 600:")
d2.append(" return")
d2.append(" self.sleep(0.5)")
d2.append(" except Exception:")
d2.append(" return")
d2.append("")
data = d2

file = codecs.open(file_path, "w+", "utf-8")
file.writelines("\r\n".join(data))
file.close()
Expand Down
2 changes: 2 additions & 0 deletions seleniumbase/console_scripts/sb_recorder.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ def do_recording(file_name, url, overwrite_enabled, use_chrome, window):
or "--undetectable" in command_args
):
command += " --uc"
if "--ee" in command_args:
command += " --ee"
command += add_on
poll = None
if sb_config.rec_subprocess_used:
Expand Down
33 changes: 31 additions & 2 deletions seleniumbase/core/browser_launcher.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,32 @@ def uc_open_with_reconnect(driver, url, reconnect_time=None):
js_utils.call_me_later(driver, script, 3)
time.sleep(0.007)
driver.close()
driver.reconnect(reconnect_time)
driver.switch_to.window(driver.window_handles[-1])
if reconnect_time == "disconnect":
driver.disconnect()
time.sleep(0.007)
else:
driver.reconnect(reconnect_time)
driver.switch_to.window(driver.window_handles[-1])
else:
driver.default_get(url) # The original one
return None


def uc_open_with_disconnect(driver, url):
"""Open a url and disconnect chromedriver.
Note: You can't perform Selenium actions again
until after you've called driver.connect()."""
if url.startswith("//"):
url = "https:" + url
elif ":" not in url:
url = "https://" + url
if (url.startswith("http:") or url.startswith("https:")):
script = 'window.open("%s","_blank");' % url
js_utils.call_me_later(driver, script, 3)
time.sleep(0.007)
driver.close()
driver.disconnect()
time.sleep(0.007)
else:
driver.default_get(url) # The original one
return None
Expand Down Expand Up @@ -3754,6 +3778,11 @@ def get_local_driver(
driver, *args, **kwargs
)
)
driver.uc_open_with_disconnect = (
lambda *args, **kwargs: uc_open_with_disconnect(
driver, *args, **kwargs
)
)
driver.uc_click = lambda *args, **kwargs: uc_click(
driver, *args, **kwargs
)
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /