browser Module (stx.browser)
- scitex.browser.is_playwright_cli_available()[source]
Check if playwright-cli (npm) is installed.
- Return type:
- async scitex.browser.highlight_element_async(element, duration_ms=1000, func_name='highlight_element_async')[source]
Highlight element with red overlay rectangle.
- scitex.browser.inject_visual_effects(page)[source]
Inject CSS and elements for visual effects (sync version).
- Return type:
- scitex.browser.show_cursor_at(page, x, y, state='normal')[source]
Move visual cursor to position (sync version).
- scitex.browser.show_click_effect(page, x, y)[source]
Show click ripple effect at position (sync version).
- Return type:
- scitex.browser.show_step(page, step, total, message, level='info')[source]
Show numbered step message in browser (sync version).
- scitex.browser.show_test_result(page, success, message='', delay_ms=3000)[source]
Show test result banner (PASS/FAIL) and wait (sync version).
- async scitex.browser.inject_visual_effects_async(page)[source]
Inject CSS and elements for visual effects (async version).
- Return type:
- async scitex.browser.show_cursor_at_async(page, x, y, state='normal')[source]
Move visual cursor to position (async version).
- Return type:
- async scitex.browser.show_click_effect_async(page, x, y)[source]
Show click ripple effect at position (async version).
- Return type:
- async scitex.browser.show_step_async(page, step, total, message, level='info')[source]
Show numbered step message in browser (async version).
- Return type:
- async scitex.browser.show_test_result_async(page, success, message='', delay_ms=3000)[source]
Show test result banner (PASS/FAIL) and wait (async version).
- Return type:
- scitex.browser.setup_console_interceptor(page)[source]
Set up console log interceptor with source tracking and error capture.
Features (mirroring console-interceptor.ts): - Intercepts console.log, info, warn, error, debug - Captures source file and line number - Captures unhandled JS errors - Captures unhandled promise rejections - Captures resource loading failures
Call this at the start of each test to begin capturing logs.
- Return type:
- scitex.browser.collect_console_logs(page)[source]
Collect all captured console logs from the browser.
- Return type:
- Returns:
List of log strings in format “[LEVEL] source message”
- scitex.browser.collect_console_logs_detailed(page)[source]
Collect all captured console logs with full details.
- Returns:
level, message, source, timestamp, url
- Return type:
List of dicts with keys
- scitex.browser.save_failure_artifacts(page, test_name, artifacts_dir, console_logs=None)[source]
Save screenshot, console logs, and page HTML on test failure.
- Parameters:
- Return type:
- Returns:
Dict with paths to saved artifacts
- scitex.browser.create_failure_capture_fixture(artifacts_dir)[source]
Create a pytest fixture for automatic failure capture.
- Usage in conftest.py:
from scitex_browser.debugging import create_failure_capture_fixture
- capture_on_failure = create_failure_capture_fixture(
Path(__file__).parent / “artifacts”
)
- class scitex.browser.TestMonitor(output_dir=None, interval=2.0, quality=70, verbose=False, test_name=None)[source]
Bases:
objectMonitor E2E tests with periodic screenshots using scitex.capture.
Captures screenshots at regular intervals during test execution, allowing visual inspection of test progress and debugging.
- __init__(output_dir=None, interval=2.0, quality=70, verbose=False, test_name=None)[source]
Initialize test monitor.
- Parameters:
output_dir (
str|Path) – Directory for screenshots (default: $SCITEX_DIR/browser/runtime/test_monitor)interval (
float) – Seconds between screenshots (default: 2.0)quality (
int) – JPEG quality 1-100 (default: 70)verbose (
bool) – Print capture messagestest_name (
str) – Optional test name for session identification
- scitex.browser.create_test_monitor_fixture(output_dir=None, interval=2.0, auto_gif=False)[source]
Create a pytest fixture for test monitoring.
- Usage in conftest.py:
from scitex_browser.debugging import create_test_monitor_fixture
test_monitor = create_test_monitor_fixture(interval=2.0, auto_gif=True)
- scitex.browser.monitor_test(test_func=None, interval=2.0, auto_gif=False)[source]
Decorator for monitoring tests with periodic screenshots.
- Usage:
@monitor_test(interval=1.0, auto_gif=True) def test_my_feature(page):
# test code…
- class scitex.browser.SyncBrowserSession(page, timeout=60, on_enter=None, on_exit=None)[source]
Bases:
objectSync context manager for playwright browser sessions.
Ensures zombie process cleanup on test failures, timeouts, or crashes. Tracks browser PIDs and kills orphaned processes on exit.
- __init__(page, timeout=60, on_enter=None, on_exit=None)[source]
Initialize sync browser session.
- Parameters:
page (
Page) – Playwright page instance from pytest-playwrighttimeout (
int) – Default timeout for operations in secondson_enter (
Optional[Callable[[Page],None]]) – Callback when entering contexton_exit (
Optional[Callable[[Page,bool],None]]) – Callback when exiting context (receives page and success flag)
- scitex.browser.sync_browser_session(page, timeout=60, on_enter=None, on_exit=None)[source]
Context manager for sync playwright sessions.
- Usage:
- with sync_browser_session(page) as session:
session.page.goto(url) # … test code
# Cleanup happens automatically
- scitex.browser.create_browser_session_fixture(timeout=60, setup=None, teardown=None, kill_zombies_on_start=True)[source]
Create a pytest fixture for browser session with cleanup.
- Usage in conftest.py:
from scitex_browser import create_browser_session_fixture
- browser_session = create_browser_session_fixture(
timeout=60, setup=lambda page: print(f”Starting test”), teardown=lambda page, success: print(f”Test {‘passed’ if success else ‘failed’}”), kill_zombies_on_start=True,
)
- Parameters:
- Returns:
A pytest fixture function
- scitex.browser.save_as_pdf(url, output_path, **kwargs)[source]
Sync wrapper for save_as_pdf_async.
- Return type:
- async scitex.browser.save_as_pdf_async(url, output_path, *, wait_seconds=3, print_background=True, format='A4', margin_top='10mm', margin_bottom='10mm', margin_left='10mm', margin_right='10mm')[source]
Navigate to URL and save page as PDF.
- Parameters:
url (str) – URL to save as PDF.
output_path (str) – Path to save the PDF file.
wait_seconds (float) – Extra seconds to wait after page load for JS rendering.
print_background (bool) – Whether to print background graphics.
format (str) – Paper format (A4, Letter, etc.).
margin_top (str) – Page margins (e.g., “10mm”, “1in”).
margin_bottom (str) – Page margins (e.g., “10mm”, “1in”).
margin_left (str) – Page margins (e.g., “10mm”, “1in”).
margin_right (str) – Page margins (e.g., “10mm”, “1in”).
- Returns:
Absolute path of the saved PDF.
- Return type:
- async scitex.browser.detect_chrome_pdf_viewer_async(page, verbose=False, func_name='detect_chrome_pdf_viewer_async')[source]
Detect if Chrome PDF viewer is present on the page.
Universal utility for detecting PDF viewer across any browser automation workflow.
NOTE: Caller should wait for networkidle BEFORE calling this function. This function does NOT wait for networkidle to avoid redundant waits.
- async scitex.browser.click_download_for_chrome_pdf_viewer_async(page, output_path, verbose=False, func_name='click_download_for_chrome_pdf_viewer_async')[source]
Click download button in Chrome PDF viewer and save the PDF file.
This function locates the download button in Chrome’s built-in PDF viewer (typically at top-right corner) and triggers the download, then saves the file to the specified path.
- Parameters:
- Returns:
True if download succeeded and file is valid (>1KB), False otherwise
- Return type:
Example
>>> await click_download_for_chrome_pdf_viewer_async( ... page, "paper.pdf", verbose=True ... ) True
Note
Expects Chrome PDF viewer to be already loaded on the page
Download button position is at approximately (95%, 3%) of viewport
Waits up to 120 seconds for download to start
Waits 10 seconds for download to complete after starting
- async scitex.browser.click_center_async(page, verbose=False, func_name='click_center_async')[source]
Click the center of the viewport.
- Parameters:
page – Playwright page object
verbose (
bool) – Enable visual feedback (default False)
- Returns:
Click result
- async scitex.browser.click_with_fallbacks_async(page, selector, method='auto', verbose=False, capture_debug=True)[source]
Click element using multiple fallback methods.
- Parameters:
page (
Page) – Playwright page objectselector (
str) – CSS selector for the elementmethod (
str) – Click method (“auto”, “playwright”, “force”, “js”)verbose (
bool) – Enable visual feedback via popup system (default False)capture_debug (
bool) – Save screenshot+HTML before/after the click (default True). Disabled in tight loops or hot paths where artifact volume hurts.
- Returns:
True if click successful, False otherwise
- Return type:
- async scitex.browser.fill_with_fallbacks_async(page, selector, value, method='auto', verbose=False, capture_debug=True)[source]
Fill element using multiple fallback methods.
- Parameters:
page (
Page) – Playwright page objectselector (
str) – CSS selector for the elementvalue (
str) – Value to fillmethod (
str) – Fill method (“auto”, “playwright”, “type”, “js”)verbose (
bool) – Enable visual feedback via popup system (default False)capture_debug (
bool) – Save screenshot+HTML before/after the fill (default True). Disabled in tight loops or hot paths.
- Returns:
True if fill successful, False otherwise
- Return type:
- class scitex.browser.PopupHandler(page)[source]
Bases:
objectHandle various types of popups on web pages.
- COOKIE_SELECTORS = ['button#onetrust-accept-btn-handler', 'button#onetrust-pc-btn-handler', 'button[id*="accept-cookie"]', 'button[id*="accept-all"]', 'button[aria-label*="accept cookie"]', 'button[aria-label*="Accept cookie"]', 'button:has-text("Accept all")', 'button:has-text("Accept All")', 'button:has-text("I agree")', 'button:has-text("I Agree")', 'button:has-text("Accept")', '.cookie-notice button.accept', '[class*="cookie"] button[class*="accept"]']
- CLOSE_SELECTORS = ['button[aria-label="Close"]', 'button[aria-label="close"]', 'button[aria-label*="Close"]', 'button[aria-label*="close"]', 'button[aria-label*="dismiss"]', 'button[aria-label*="Dismiss"]', 'button.close', 'button.close-button', 'button.modal-close', 'button.popup-close', 'button.dialog-close', 'a.close', 'a.close-button', 'span.close', '[class*="close-button"]', '[class*="close-icon"]', 'svg[class*="close"]', 'button:has-text("No thanks")', 'button:has-text("No Thanks")', 'button:has-text("Maybe later")', 'button:has-text("Maybe Later")', 'button:has-text("Skip")', 'button:has-text("Dismiss")', 'button:has-text("Not now")', 'button:has-text("Not Now")']
- MODAL_SELECTORS = ['.modal', '.overlay', '[role="dialog"]', '.popup', '#onetrust-banner-sdk', '.onetrust-pc-dark-filter', '[class*="modal"]', '[class*="popup"]', '[class*="overlay"]', '[class*="dialog"]', '[class*="banner"]', 'div[aria-modal="true"]']
- async handle_cookie_popup()[source]
Handle cookie consent popups.
- Return type:
- Returns:
True if handled, False otherwise
- async scitex.browser.close_popups_async(page, handle_cookies=True, close_others=True, max_attempts=3, wait_first=True, wait_ms=2000)[source]
Convenience function to handle all popups on a page.
- Parameters:
page (
Page) – Playwright page objecthandle_cookies (
bool) – Whether to accept cookie popupsclose_others (
bool) – Whether to close other popupsmax_attempts (
int) – Maximum attempts to clear popupswait_first (
bool) – Whether to wait for popups to appear firstwait_ms (
int) – Time to wait for popups to appear
- Return type:
- Returns:
Tuple of (number handled, list of handled popups)