* SeleniumBase as a Python Context Manager * Example: -------- .. code-block:: python from seleniumbase import SB with SB(uc=True, test=True) as sb: url = "https://google.com/ncr" sb.activate_cdp_mode(url) sb.click_if_visible('bu
(
test=None, # Test Mode: Output, Logging, Continue on failure unless "rtf".
rtf=None, # Shortcut / Duplicate of "raise_test_failure".
raise_test_failure=None, # If "test" mode, raise Exception on 1st failure.
browser=None, # Choose from "chrome", "edge", "firefox", or "safari".
headless=None, # Use the default headless mode for Chromium and Firefox.
headless1=None, # Use Chromium's old headless mode. (Fast, but limited)
headless2=None, # Use Chromium's new headless mode. (Has more features)
locale_code=None, # Set the Language Locale Code for the web browser.
protocol=None, # The Selenium Grid protocol: "http" or "https".
servername=None, # The Selenium Grid server/IP used for tests.
port=None, # The Selenium Grid port used by the test server.
proxy=None, # Use proxy. Format: "SERVER:PORT" or "USER:PASS@SERVER:PORT".
proxy_bypass_list=None, # Skip proxy when using the listed domains.
proxy_pac_url=None, # Use PAC file. (Format: URL or USERNAME:PASSWORD@URL)
multi_proxy=None, # Allow multiple proxies with auth when multi-threaded.
agent=None, # Modify the web browser's User-Agent string.
cap_file=None, # The desired capabilities to use with a Selenium Grid.
cap_string=None, # The desired capabilities to use with a Selenium Grid.
recorder_ext=None, # Enables the SeleniumBase Recorder Chromium extension.
disable_cookies=None, # Disable Cookies on websites. (Pages might break!)
disable_js=None, # Disable JavaScript on websites. (Pages might break!)
disable_csp=None, # Disable the Content Security Policy of websites.
enable_ws=None, # Enable Web Security on Chromium-based browsers.
enable_sync=None, # Enable "Chrome Sync" on websites.
use_auto_ext=None, # Use Chrome's automation extension.
undetectable=None, # Use undetected-chromedriver to evade bot-detection.
uc_cdp_events=None, # Capture CDP events in undetected-chromedriver mode.
uc_subprocess=None, # Use undetected-chromedriver as a subprocess.
log_cdp_events=None, # Capture {"performance": "ALL", "browser": "ALL"}
incognito=None, # Enable Chromium's Incognito mode.
guest_mode=None, # Enable Chromium's Guest mode.
dark_mode=None, # Enable Chromium's Dark mode.
devtools=None, # Open Chromium's DevTools when the browser opens.
remote_debug=None, # Enable Chrome's Debugger on "http://localhost:9222".
enable_3d_apis=None, # Enable WebGL and 3D APIs.
swiftshader=None, # Chrome: --use-gl=angle / --use-angle=swiftshader-webgl
ad_block_on=None, # Block some types of display ads from loading.
host_resolver_rules=None, # Set host-resolver-rules, comma-separated.
block_images=None, # Block images from loading during tests.
do_not_track=None, # Tell websites that you don't want to be tracked.
chromium_arg=None, # "ARG=N,ARG2" (Set Chromium args, ","-separated.)
firefox_arg=None, # "ARG=N,ARG2" (Set Firefox args, comma-separated.)
firefox_pref=None, # SET (Set Firefox PREFERENCE:VALUE set, ","-separated)
user_data_dir=None, # Set the Chrome user data directory to use.
extension_zip=None, # Load a Chrome Extension .zip|.crx, comma-separated.
extension_dir=None, # Load a Chrome Extension directory, comma-separated.
disable_features=None, # "F1,F2" (Disable Chrome features, ","-separated.)
binary_location=None, # Set path of the Chromium browser binary to use.
driver_version=None, # Set the chromedriver or uc_driver version to use.
skip_js_waits=None, # Skip JS Waits (readyState=="complete" and Angular).
wait_for_angularjs=None, # Wait for AngularJS to load after some actions.
external_pdf=None, # Set Chrome "plugins.always_open_pdf_externally":True.
window_position=None, # Set the browser's starting window position: "X,Y"
window_size=None, # Set the browser's starting window size: "Width,Height"
is_mobile=None, # Use the mobile device emulator while running tests.
mobile=None, # Shortcut / Duplicate of "is_mobile".
device_metrics=None, # Set mobile metrics: "CSSWidth,CSSHeight,PixelRatio"
xvfb=None, # Run tests using the Xvfb virtual display server on Linux OS.
xvfb_metrics=None, # Set Xvfb display size on Linux: "Width,Height".
start_page=None, # The starting URL for the web browser when tests begin.
rec_print=None, # If Recorder is enabled, prints output after tests end.
rec_sb_mgr=None, # Recorder Mode that generates SB() context manager code.
rec_sb_cdp=None, # Recorder Mode that generates Pure CDP Mode sb_cdp code.
rec_behave=None, # Like Recorder Mode, but also generates behave-gherkin.
record_sleep=None, # If Recorder enabled, also records self.sleep calls.
data=None, # Extra test data. Access with "self.data" in tests.
var1=None, # Extra test data. Access with "self.var1" in tests.
var2=None, # Extra test data. Access with "self.var2" in tests.
var3=None, # Extra test data. Access with "self.var3" in tests.
variables=None, # DICT (Extra test data. Access with "self.variables")
account=None, # Set account. Access with "self.account" in tests.
environment=None, # Set the test env. Access with "self.env" in tests.
headed=None, # Run tests in headed/GUI mode on Linux, where not default.
maximize=None, # Start tests with the browser window maximized.
disable_ws=None, # Reverse of "enable_ws". (None and False are different)
disable_beforeunload=None, # Disable the "beforeunload" event on Chromium.
settings_file=None, # A file for overriding default SeleniumBase settings.
position=None, # Shortcut / Duplicate of "window_position".
size=None, # Shortcut / Duplicate of "window_size".
uc=None, # Shortcut / Duplicate of "undetectable".
undetected=None, # Shortcut / Duplicate of "undetectable".
uc_cdp=None, # Shortcut / Duplicate of "uc_cdp_events".
uc_sub=None, # Shortcut / Duplicate of "uc_subprocess".
locale=None, # Shortcut / Duplicate of "locale_code".
log_cdp=None, # Shortcut / Duplicate of "log_cdp_events".
ad_block=None, # Shortcut / Duplicate of "ad_block_on".
server=None, # Shortcut / Duplicate of "servername".
guest=None, # Shortcut / Duplicate of "guest_mode".
pls=None, # Shortcut / Duplicate of "page_load_strategy".
sjw=None, # Shortcut / Duplicate of "skip_js_waits".
wfa=None, # Shortcut / Duplicate of "wait_for_angularjs".
cft=None, # Use "Chrome for Testing"
chs=None, # Use "Chrome-Headless-Shell"
use_chromium=None, # Use base "Chromium"
save_screenshot=None, # Save a screenshot at the end of each test.
no_screenshot=None, # No screenshots saved unless tests directly ask it.
page_load_strategy=None, # Set Chrome PLS to "normal", "eager", or "none".
timeout_multiplier=None, # Multiplies the default timeout values.
js_checking_on=None, # Check for JavaScript errors after page loads.
slow=None, # Slow down the automation. Faster than using Demo Mode.
demo=None, # Slow down and visually see test actions as they occur.
demo_sleep=None, # SECONDS (Set wait time after Slow & Demo Mode actions.)
message_duration=None, # SECONDS (The time length for Messenger alerts.)
highlights=None, # Number of highlight animations for Demo Mode actions.
interval=None, # SECONDS (Autoplay interval for SB Slides & Tour steps.)
time_limit=None, # SECONDS (Safely fail tests that exceed the time limit.)
)
| 31 | |
| 32 | @contextmanager # Usage: -> ``with SB() as sb:`` |
| 33 | def SB( |
| 34 | test=None, # Test Mode: Output, Logging, Continue on failure unless "rtf". |
| 35 | rtf=None, # Shortcut / Duplicate of "raise_test_failure". |
| 36 | raise_test_failure=None, # If "test" mode, raise Exception on 1st failure. |
| 37 | browser=None, # Choose from "chrome", "edge", "firefox", or "safari". |
| 38 | headless=None, # Use the default headless mode for Chromium and Firefox. |
| 39 | headless1=None, # Use Chromium's old headless mode. (Fast, but limited) |
| 40 | headless2=None, # Use Chromium's new headless mode. (Has more features) |
| 41 | locale_code=None, # Set the Language Locale Code for the web browser. |
| 42 | protocol=None, # The Selenium Grid protocol: "http" or "https". |
| 43 | servername=None, # The Selenium Grid server/IP used for tests. |
| 44 | port=None, # The Selenium Grid port used by the test server. |
| 45 | proxy=None, # Use proxy. Format: "SERVER:PORT" or "USER:PASS@SERVER:PORT". |
| 46 | proxy_bypass_list=None, # Skip proxy when using the listed domains. |
| 47 | proxy_pac_url=None, # Use PAC file. (Format: URL or USERNAME:PASSWORD@URL) |
| 48 | multi_proxy=None, # Allow multiple proxies with auth when multi-threaded. |
| 49 | agent=None, # Modify the web browser's User-Agent string. |
| 50 | cap_file=None, # The desired capabilities to use with a Selenium Grid. |
| 51 | cap_string=None, # The desired capabilities to use with a Selenium Grid. |
| 52 | recorder_ext=None, # Enables the SeleniumBase Recorder Chromium extension. |
| 53 | disable_cookies=None, # Disable Cookies on websites. (Pages might break!) |
| 54 | disable_js=None, # Disable JavaScript on websites. (Pages might break!) |
| 55 | disable_csp=None, # Disable the Content Security Policy of websites. |
| 56 | enable_ws=None, # Enable Web Security on Chromium-based browsers. |
| 57 | enable_sync=None, # Enable "Chrome Sync" on websites. |
| 58 | use_auto_ext=None, # Use Chrome's automation extension. |
| 59 | undetectable=None, # Use undetected-chromedriver to evade bot-detection. |
| 60 | uc_cdp_events=None, # Capture CDP events in undetected-chromedriver mode. |
| 61 | uc_subprocess=None, # Use undetected-chromedriver as a subprocess. |
| 62 | log_cdp_events=None, # Capture {"performance": "ALL", "browser": "ALL"} |
| 63 | incognito=None, # Enable Chromium's Incognito mode. |
| 64 | guest_mode=None, # Enable Chromium's Guest mode. |
| 65 | dark_mode=None, # Enable Chromium's Dark mode. |
| 66 | devtools=None, # Open Chromium's DevTools when the browser opens. |
| 67 | remote_debug=None, # Enable Chrome's Debugger on "http://localhost:9222". |
| 68 | enable_3d_apis=None, # Enable WebGL and 3D APIs. |
| 69 | swiftshader=None, # Chrome: --use-gl=angle / --use-angle=swiftshader-webgl |
| 70 | ad_block_on=None, # Block some types of display ads from loading. |
| 71 | host_resolver_rules=None, # Set host-resolver-rules, comma-separated. |
| 72 | block_images=None, # Block images from loading during tests. |
| 73 | do_not_track=None, # Tell websites that you don't want to be tracked. |
| 74 | chromium_arg=None, # "ARG=N,ARG2" (Set Chromium args, ","-separated.) |
| 75 | firefox_arg=None, # "ARG=N,ARG2" (Set Firefox args, comma-separated.) |
| 76 | firefox_pref=None, # SET (Set Firefox PREFERENCE:VALUE set, ","-separated) |
| 77 | user_data_dir=None, # Set the Chrome user data directory to use. |
| 78 | extension_zip=None, # Load a Chrome Extension .zip|.crx, comma-separated. |
| 79 | extension_dir=None, # Load a Chrome Extension directory, comma-separated. |
| 80 | disable_features=None, # "F1,F2" (Disable Chrome features, ","-separated.) |
| 81 | binary_location=None, # Set path of the Chromium browser binary to use. |
| 82 | driver_version=None, # Set the chromedriver or uc_driver version to use. |
| 83 | skip_js_waits=None, # Skip JS Waits (readyState=="complete" and Angular). |
| 84 | wait_for_angularjs=None, # Wait for AngularJS to load after some actions. |
| 85 | external_pdf=None, # Set Chrome "plugins.always_open_pdf_externally":True. |
| 86 | window_position=None, # Set the browser's starting window position: "X,Y" |
| 87 | window_size=None, # Set the browser's starting window size: "Width,Height" |
| 88 | is_mobile=None, # Use the mobile device emulator while running tests. |
| 89 | mobile=None, # Shortcut / Duplicate of "is_mobile". |
| 90 | device_metrics=None, # Set mobile metrics: "CSSWidth,CSSHeight,PixelRatio" |