Understanding Sahi Pro Architecture
Proxy-Based Injection
Sahi Pro uses a proxy server to inject JavaScript into the AUT (Application Under Test). This allows it to control and monitor the DOM without requiring direct access to source code. Improper proxy settings or HTTPS interception can cause script injection failures.
Identifier Strategy and Smart Accessors
Sahi scripts rely on accessors like _textbox("username")
or _button("Login")
. Smart accessor logic uses heuristics and DOM inspection, which can be brittle on dynamic pages or after UI redesigns.
Common Symptoms
- Tests fail to identify elements reliably across environments
_button(...)
or_textbox(...)
returns null during execution- HTTPS sites load without instrumentation or fail with certificate errors
- Batch runs slow down significantly or hang mid-execution
- CI tools (Jenkins, Bamboo) fail to detect test pass/fail status from Sahi Pro
Root Causes
1. Dynamic DOM Changes and Non-Unique Identifiers
Modern SPAs often modify the DOM post-load or reuse element IDs, breaking Sahi’s locator logic. Accessors relying on positional indices or partial text fail frequently under these conditions.
2. Browser or Proxy Misconfiguration
If the browser is not launched via Sahi's launcher or the proxy is not properly set (e.g., corporate firewalls), script injection fails, leading to silent test failures or element mismatches.
3. Incomplete Data Set or Parameter Mismatches
Data-driven scripts using Excel or CSV files can silently fail when headers are misaligned or cells contain unexpected formats.
4. Improper Session Handling
Scripts not resetting cookies, cache, or session state between test cases cause login failures or UI inconsistencies in batch mode.
5. CI/CD Output Not Parsed Properly
Default Sahi Pro logs may not conform to expected result file formats (e.g., JUnit XML), making it hard for CI tools to register test outcomes without customization.
Diagnostics and Monitoring
1. Use Sahi Debug Logs
Enable logs/debug.log
and playback.log
to capture detailed test execution output, accessor failures, and JavaScript exceptions.
2. Inspect Sahi Controller in Manual Mode
Use the controller to interactively test accessors, inspect DOM structure, and refine element selection. Useful for debugging locator failures.
3. Validate Proxy Settings
Confirm browser proxy settings point to Sahi Pro proxy (typically localhost:9999
). Use about:config
or policy editors for Firefox/Chrome in enterprise environments.
4. Monitor Resource Usage During Batch Execution
Use OS-level tools (e.g., Task Manager, top) to monitor memory and CPU usage. Ensure test machines meet Sahi Pro’s concurrency and thread limits.
5. Capture CI Output and Exit Codes
Wrap test scripts in shell wrappers that parse Sahi’s result files or stdout, converting them into formats Jenkins or other tools can consume.
Step-by-Step Fix Strategy
1. Use Robust Accessors with Attributes
Prefer _byId()
, _byClassName()
, or custom attribute accessors over text or index-based locators. Avoid relying solely on visible text for dynamic components.
2. Launch Browsers via Sahi Pro Tools
Always start test browsers using Sahi's launchers to ensure proxy and script injection are active. Manually configuring proxy settings may miss startup scripts.
3. Normalize Test Data Formats
Clean CSV/Excel inputs, validate header consistency, and use Sahi APIs for cell access validation. Add runtime checks for data integrity.
4. Reset State Between Iterations
Use _clearCookies()
, _setValue()
, and reload pages to ensure a clean slate before each test or scenario loop.
5. Integrate with CI Using Custom Report Parsers
Convert logs/summary.txt
or testReports.xml
into JUnit-compatible XML. Use plugins or custom scripts to propagate exit codes and summary stats.
Best Practices
- Modularize scripts using includes and shared functions to improve maintainability
- Use explicit waits like
_wait()
or_waitFor()
over static delays - Group batch scripts into logical suites to parallelize or sequence intelligently
- Maintain version-controlled copies of scripts and data files
- Regularly update Sahi Pro to support new browser versions and patch known bugs
Conclusion
Sahi Pro remains a versatile tool for enterprise test automation, particularly for teams dealing with legacy systems or mixed technology stacks. By refining element identification, standardizing data sources, and improving CI feedback loops, teams can enhance reliability and performance of Sahi Pro scripts while preparing for broader test strategy modernization.
FAQs
1. Why is my Sahi script failing to find an element it used to identify?
Likely due to DOM changes. Re-record or refine the accessor using _byId
or custom attributes instead of dynamic text labels.
2. How can I fix SSL errors in HTTPS applications?
Install Sahi’s root certificate and ensure your browser is configured to trust it. Check for HSTS or pinned certificate policies that block interception.
3. Why does Sahi Pro run slowly during batch testing?
Check for memory leaks, excessive logging, or unclosed sessions. Split batches or run on separate machines to balance load.
4. Can I integrate Sahi Pro with Jenkins?
Yes, use shell or PowerShell wrappers to execute Sahi scripts, then parse output logs into JUnit format for Jenkins parsing.
5. Is Sahi Pro suitable for SPA or React-based apps?
Yes, but accessors must be carefully tuned due to dynamic rendering. Use attribute-based selectors and validate readiness before interactions.